JVMTM Tool InterfaceVersion 1.0 |
- Introduction
- Functions
- Events
- Data Types
- Constant Index
- Change History
What is the JVM Tool Interface?
The JVM TM Tool Interface (JVM TI) is a programming interface used by development and monitoring tools. It provides both a way to inspect the state and to control the execution of applications running in the Java TM virtual machine (VM). JVM TI is intended to provide a VM interface for the full breadth of tools that need access to VM state, including but not limited to: profiling, debugging, monitoring, thread analysis, and coverage analysis tools. JVM TI may not be available in all implementations of the Java TM virtual machine. JVM TI is a two-way interface. A client of JVM TI, hereafter called an agent , can be notified of interesting occurrences through events . JVM TI can query and control the application through many functions , either in response to events or independent of them. Agents run in the same process with and communicate directly with the virtual machine executing the application being examined. This communication is through a native interface (JVM TI). The native in-process interface allows maximal control with minimal intrusion on the part of a tool. Typically, agents are relatively compact. They can be controlled by a separate process which implements the bulk of a tool's function without interfering with the target application's normal execution.Architecture
Tools can be written directly to JVM TI or indirectly through higher level interfaces. The Java Platform Debugger Architecture includes JVM TI, but also contains higher-level, out-of-process debugger interfaces. The higher-level interfaces are more appropriate than JVM TI for many tools. For more information on the Java Platform Debugger Architecture, see the Java Platform Debugger Architecture website .Writing Agents
Agents can be written in any native language that supports C language calling conventions and C or C++ definitions. The function, event, data type, and constant definitions needed for using JVM TI are defined in the include filejvmti.h
. To use these definitions add the J2SE
TM
include directory to your include path and add
to your source code.#include <jvmti.h>
Agent Command Line Options
The term "command-line option" is used below to mean options supplied in theJavaVMInitArgs
argument to the
JNI_CreateJavaVM
function of the JNI Invocation API.
One of the two following command-line options is used on VM startup to properly load and run agents. These arguments identify the library containing the agent as well as an options string to be passed in at startup.
-
The name following
-agentlib:
is the name of the library to load. Lookup of the library, both its full name and location, proceeds in a platform-specific manner. Typically, the <agent-lib-name> is expanded to an operating system specific file name. The <options> will be passed to the agent on start-up. For example, if the option-agentlib:foo=opt1,opt2
is specified, the VM will attempt to load the shared libraryfoo.dll
from the systemPATH
under Windows TM orlibfoo.so
from theLD_LIBRARY_PATH
under the Solaris TM operating environment. -
The path following
-agentpath:
is the absolute path from which to load the library. No library name expansion will occur. The <options> will be passed to the agent on start-up. For example, if the option-agentpath:c:\myLibs\foo.dll=opt1,opt2
is specified, the VM will attempt to load the shared libraryc:\myLibs\foo.dll
.
-agentlib:
<agent-lib-name>
=
<options>
-agentpath:
<path-to-agent>
=
<options>
-agentlib:
or
-agentpath:
will be searched for JNI native method implementations to facilitate the use of Java programming language code in tools, as is needed for
bytecode instrumentation
.
The agent libraries will be searched after all other libraries have been searched (agents wishing to override or intercept the native method implementations of non-agent methods can use the
NativeMethodBind event
).
These switches do the above and nothing more - they do not change the state of the VM or JVM
TI. No command line options are needed to enable JVM
TI or aspects of JVM
TI, this is handled programmatically by the use of
capabilities
.
Agent Start-Up
The library must export a start-up function with the following prototype:This function will be called by the VM when the library is loaded. The VM should load the library early enough in VM initialization that:JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
- system properties may be set before they have been used in the start-up of the VM
- the full set of capabilities is still available (note that capabilities that configure the VM may only be available at this time--see the Capability function section)
- no bytecodes have executed
- no classes have been loaded
- no objects have been created
Agent_OnLoad
function with
<options>
as the second argument - that is, using the command-line option examples,
"opt1,opt2"
will be passed to the
char *options
argument of
Agent_OnLoad
. The
options
argument is encoded as a
modified UTF-8
string. If
=<options>
is not specified, a zero length string is passed to
options
. The lifespan of the
options
string is the
Agent_OnLoad
call. If needed beyond this time the string or parts of the string must be copied. The period between when
Agent_OnLoad
is called and when it returns is called the
OnLoad phase
. Since the VM is not initialized during the OnLoad
phase
, the set of allowed operations inside
Agent_OnLoad
is restricted (see the function descriptions for the functionality available at this time). The agent can safely process the options and set event callbacks with
SetEventCallbacks
. Once the VM initialization event is received (that is, the
VMInit
callback is invoked), the agent can complete its initialization.
Rationale: Early startup is required so that agents can set the desired capabilities, many of which must be set before the VM is initialized. In JVMDI, the -Xdebug command-line option provides very coarse-grain control of capabilities. JVMPI implementations use various tricks to provide a single "JVMPI on" switch. No reasonable command-line option could provide the fine-grain of control required to balance needed capabilities vs performance impact. Early startup is also needed so that agents can control the execution environment - modifying the file system and system properties to install their functionality.
The return value fromAgent_OnLoad
is used to indicate an error. Any value other than zero indicates an error and causes termination of the VM.
Agent Shutdown
The library may optionally export a shutdown function with the following prototype:This function will be called by the VM when the library is about to be unloaded. The library will be unloaded and this function will be called if some platform specific mechanism causes the unload (an unload mechanism is not specified in this document) or the library is (in effect) unloaded by the termination of the VM whether through normal termination or VM failure, including start-up failure. Uncontrolled shutdown is, of couse, an exception to this rule. Note the distinction between this function and the VM Death event : for the VM Death event to be sent, the VM must have run at least to the point of initialization and a valid JVM TI environment must exist which has set a callback for VMDeath and enabled the event None of these are required forJNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm)
Agent_OnUnload
and this function is also called if the library is unloaded for other reasons. In the case that a VM Death event is sent, it will be sent before this function is called (assuming this function is called due to VM termination). This function can be used to clean-up resources allocated during
Agent_OnLoad
.
JAVA_TOOL_OPTIONS
Since the command-line cannot always be accessed or modified, for example in embedded VMs or simply VMs launched deep within scripts. AJAVA_TOOL_OPTIONS
variable is provided so that agents may be launched in these cases.
Platforms which support environment variables or other named strings, may support the
JAVA_TOOL_OPTIONS
variable. This variable will be broken into options at white-space boundaries. White-space characters include space, tab, carriage-return, new-line, vertical-tab, and form-feed. Sequences of white-space characters are considered equivalent to a single white-space character. No white-space is included in the options unless quoted. Quoting is as follows:
- All characters enclosed between a pair of single quote marks (''), except a single quote, are quoted.
- Double quote characters have no special meaning inside a pair of single quote marks.
- All characters enclosed between a pair of double quote marks (""), except a double quote, are quoted.
- Single quote characters have no special meaning inside a pair of double quote marks.
- A quoted part can start or end anywhere in the variable.
- White-space characters have no special meaning when quoted -- they are included in the option like any other character and do not mark white-space boundaries.
- The pair of quote marks is not included in the option.
JNI_CreateJavaVM
(in the JNI Invocation API) will prepend these options to the options supplied in its
JavaVMInitArgs
argument. Platforms may disable this feature in cases where security is a concern; for example, the Reference Implementation disables this feature on Unix systems when the effective user or group ID differs from the real ID. This feature is intended to support the initialization of tools -- specifically including the launching of native or Java programming language agents. Multiple tools may wish to use this feature, so the variable should not be overwritten, instead, options should be appended to the variable. Note that since the variable is processed at the time of the JNI Invocation API create VM call, options processed by a launcher (e.g., VM selection options) will not be handled.
Environments
The JVM TI specification supports the use of multiple simultaneous JVM TI agents. Each agent has its own JVM TI environment. That is, the JVM TI state is separate for each agent - changes to one environment do not affect the others. The state of a JVM TI environment includes:- the event callbacks
- the set of events which are enabled
- the capabilities
- the memory allocation/deallocation hooks
GetEnv
from
Agent_OnLoad
.
Bytecode Instrumentation
This interface does not include some events that one might expect in an interface with profiling support. Some examples include object allocation events and full speed method enter and exit events. The interface instead provides support for bytecode instrumentation , the ability to alter the Java virtual machine bytecode instructions which comprise the target program. Typically, these alterations are to add "events" to the code of a method - for example, to add, at the beginning of a method, a call toMyProfiler.methodEntered()
. Since the changes are purely additive, they do not modify application state or behavior. Because the inserted agent code is standard bytecodes, the VM can run at full speed, optimizing not only the target program but also the instrumentation. If the instrumentation does not involve switching from bytecode execution, no expensive state transitions are needed. The result is high performance events. This approach also provides complete control to the agent, instrumentation can be restricted to "interesting" portions of the code (e.g., the end user's code) and can be conditional. Instrumentation can run entirely in Java programming language code or can call into the native agent. Instrumentation can simply maintain counters or can statistically sample events.
Instrumentation can be inserted in one of three ways:
- Static Instrumentation: The class file is instrumented before it is loaded into the VM - for example, by creating a duplicate directory of
*.class
files which have been modified to add the instrumentation. This method is extremely awkward and, in general, an agent cannot know the origin of the class files which will be loaded. - Load-Time Instrumentation: When a class file is loaded by the VM, the raw bytes of the class file are sent for instrumentation to the agent. The
ClassFileLoadHook
event provides this functionality. This mechanism provides efficient and complete access to one-time instrumentation. - Dynamic Instrumentation: A class which is already loaded (and possibly even running) is modified. This optional feature is provided by the
RedefineClasses
function. Classes can be modified multiple times and can be returned to their original state. The mechanism allows instrumentation which changes during the course of execution.
ClassFileLoadHook
event and the
RedefineClasses
function) is intended to provide a mechanism for instrumentation (described above) and, during development, for fix-and-continue debugging.
Care must be taken to avoid perturbing dependencies, especially when instrumenting core classes. For example, an approach to getting notification of every object allocation is to instrument the constructor on
Object
. Assuming that the constructor is initially empty, the constructor could be changed to:
However, if this change was made using thepublic Object() { MyProfiler.allocationTracker(this); }
ClassFileLoadHook
event then this might impact a typical VM as follows: the first created object will call the constructor causing a class load of
MyProfiler
; which will then cause object creation, and since
MyProfiler
isn't loaded yet, infinite recursion; resulting in a stack overflow. A refinement of this would be to delay invoking the tracking method until a safe time. For example,
trackAllocations
could be set in the handler for the
VMInit
event.
static boolean trackAllocations = false; public Object() { if (trackAllocations) { MyProfiler.allocationTracker(this); } }
Modified UTF-8 String Encoding
JVM TI uses modified UTF-8 to encode character strings. This is the same encoding used by JNI. Modified UTF-8 differs from standard UTF-8 in the representation of supplementary characters and of the null character. See the Modified UTF-8 Strings section of the JNI specification for details.Specification Context
Since this interface provides access to the state of applications running in the Java virtual machine; terminology refers to the Java platform and not the native platform (unless stated otherwise). For example:- "thread" means Java programming language thread.
- "stack frame" means Java virtual machine stack frame.
- "class" means Java programming language class.
- "heap" means Java virtual machine heap.
- "monitor" means Java programming language object monitor.
Functions
Accessing Functions
Native code accesses JVM TI features by calling JVM TI functions. Access to JVM TI functions is by use of an interface pointer in the same manner as Java Native Interface (JNI) functions are accessed. The JVM TI interface pointer is called the environment pointer . An environment pointer is a pointer to an environment and has the typejvmtiEnv*
. An environment has information about its JVM
TI connection. The first value in the environment is a pointer to the function table. The function table is an array of pointers to JVM
TI functions. Every function pointer is at a predefined offset inside the array.
When used from the C language: double indirection is used to access the functions; the environment pointer provides context and is the first parameter of each function call; for example:
When used from the C++ language: functions are accessed as member functions ofjvmtiEnv *jvmti; ... jvmtiError err = (*jvmti)->GetLoadedClasses(jvmti, &class_count, &classes);
jvmtiEnv
; the environment pointer is not passed to the function call; for example:
Unless otherwise stated, all examples and declarations in this specification use the C language. A JVM TI environment can be obtained through the JNI Invocation APIjvmtiEnv *jvmti; ... jvmtiError err = jvmti->GetLoadedClasses(&class_count, &classes);
GetEnv
function:
Each call tojvmtiEnv *jvmti; ... (*jvm)->GetEnv(jvm, &jvmti, JVMTI_VERSION_1_0);
GetEnv
creates a new JVM
TI connection and thus a new JVM
TI environment. The
version
argument of
GetEnv
must be a JVM
TI version. The returned environment may have a different version than the requested version but the returned environment must be compatible.
GetEnv
will return
JNI_EVERSION
if a compatible version is not available, if JVM
TI is not supposed or JVM
TI is not supported in the current VM configuration. Other interfaces may be added for creating JVM
TI environments in specific contexts. Each environment has its own state (for example,
desired events
,
event handling functions
, and
capabilities
). An environment is released with
DisposeEnvironment
. Thus, unlike JNI which has one environment per thread, JVM
TI environments work across threads and are created dynamically.
Function Return Values
JVM TI functions always return an error code via thejvmtiError
function return value. Some functions can return additional values through pointers provided by the calling function. In some cases, JVM
TI functions allocate memory that your program must explicitly deallocate. This is indicated in the individual JVM
TI function descriptions. Empty lists, arrays, sequences, etc are returned as
NULL
.
In the event that the JVM
TI function encounters an error (any return value other than
JVMTI_ERROR_NONE
) the values of memory referenced by argument pointers is undefined, but no memory will have been allocated and no global references will have been allocated. If the error occurs because of invalid input, no action will have occurred.
Managing JNI Object References
JVM TI functions identify objects with JNI references (jobject
and
jclass
) and their derivatives (
jthread
and
jthreadGroup
). References passed to JVM
TI functions can be either global or local, but they must be strong references. All references returned by JVM
TI functions are local references--these local references are created during the JVM
TI call. Local references are a resource that must be managed (see the
JNI Documentation
). When threads return from native code all local references are freed. Note that some threads, including typical agent threads, will never return from native code. A thread is ensured the ability to create sixteen local references without the need for any explicit management. For threads executing a limited number of JVM
TI calls before returning from native code (for example, threads processing events), it may be determined that no explicit management is needed. However, long running agent threads will need explicit local reference management--usually with the JNI functions
PushLocalFrame
and
PopLocalFrame
. Conversely, to preserve references beyond the return from native code, they must be converted to global references.
Prerequisite State for Calling Functions
Unless the function explicitly states that the agent must bring a thread or the VM to a particular state (for example, suspended), the JVM TI implementation is responsible for bringing the VM to a safe and consistent state for performing the function.Function Index
- Memory Management
- Thread
- Thread Group
- Stack Frame
- Heap
- Local Variable
- Breakpoint
- Watched Field
- Class
- Object
- Field
- Method
- Raw Monitor
- JNI Function Interception
- Event Management
- Extension Mechanism
- Capability
- Timers
- System Properties
- General
Memory Management
Memory Management functions:Allocate
Allocate an area of memory through the JVM TI allocator. The allocated memory should be freed withjvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) Deallocate . This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Deallocate
DeallocatejvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) mem using the JVM TI allocator. This function should be used to deallocate any memory allocated and returned by a JVM TI function (including memory allocated with Allocate ). All allocated memory must be deallocated or the memory cannot be reclaimed. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Thread
Thread functions:- Get Thread State
- Get All Threads
- Suspend Thread
- Suspend Thread List
- Resume Thread
- Resume Thread List
- Stop Thread
- Interrupt Thread
- Get Thread Info
- Get Owned Monitor Info
- Get Current Contended Monitor
- Run Agent Thread
- Set Thread Local Storage
- Get Thread Local Storage
jvmtiThreadInfo
- Thread information structure
Get Thread State
Get the state of a thread. The state of the thread is represented by the answers to the hierarchical set of questions below:jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr)
The following definitions are used to convert JVM TI thread state to java.lang.Thread.State style states.
Rules There can be no more than one answer to a question, although there can be no answer (because the answer is unknown, does not apply, or none of the answers is correct). An answer is set only when the enclosing answers match. That is, no more than one of
JVMTI_THREAD_STATE_ALIVE is set). And if any of these are set, the enclosing answer JVMTI_THREAD_STATE_ALIVE is set. No more than one of
JVMTI_THREAD_STATE_WAITING is set). And if either is set, the enclosing answers JVMTI_THREAD_STATE_ALIVE and JVMTI_THREAD_STATE_WAITING are set. No more than one of
JVMTI_THREAD_STATE_ALIVE and JVMTI_THREAD_STATE_WAITING are set. Also, if JVMTI_THREAD_STATE_SLEEPING is set, then JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT is set. If a state A is implemented using the mechanism of state B then it is state A which is returned by this function. For example, if Thread.sleep(long) is implemented using Object.wait(long) then it is still JVMTI_THREAD_STATE_SLEEPING which is returned. More than one of
JVMTI_THREAD_STATE_ALIVE is set. And finally, JVMTI_THREAD_STATE_TERMINATED cannot be set unless JVMTI_THREAD_STATE_ALIVE is not set. The thread state representation is designed for extension in future versions of the specification; thread state values should be used accordingly, that is they should not be used as ordinals. Most queries can be made by testing a single bit, if use in a switch statement is desired, the state bits should be masked with the interesting bits. All bits not defined above are reserved for future use. A VM, compliant to the current specification, must set reserved bits to zero. An agent should ignore reserved bits -- they should not be assumed to be zero and thus should not be included in comparisons. Examples Note that the values below exclude reserved and vendor bits. The state of a thread blocked at a synchronized -statement would be:
The state of a thread which hasn't started yet would be:JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER The state of a thread at a0 Object.wait(3000) would be:
The state of a thread suspended while runnable would be:JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_WAITING + JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT + JVMTI_THREAD_STATE_MONITOR_WAITING Testing the State In most cases, the thread state can be determined by testing the one bit corresponding to that question. For example, the code to test if a thread is sleeping:JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_RUNNABLE + JVMTI_THREAD_STATE_SUSPENDED For waiting (that is, injint state; jvmtiError err; err = (*jvmti)->GetThreadState(jvmti, thread, &state); if (err == JVMTI_ERROR_NONE) { if (state & JVMTI_THREAD_STATE_SLEEPING) { ... Object.wait , parked, or sleeping) it would be:
For some states, more than one bit will need to be tested as is the case when testing if a thread has not yet been started:if (state & JVMTI_THREAD_STATE_WAITING) { ... To distinguish timed from untimedif ((state & (JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_TERMINATED)) == 0) { ... Object.wait :
Relationship toif (state & JVMTI_THREAD_STATE_IN_OBJECT_WAIT) { if (state & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) { printf("in Object.wait(long timeout)\n"); } else { printf("in Object.wait()\n"); } } java.lang.Thread.State The thread state represented by java.lang.Thread.State returned from java.lang.Thread.getState() is a subset of the information returned from this function. The corresponding java.lang.Thread.State can be determined by using the provided conversion masks. For example, this returns the name of the java.lang.Thread.State thread state:
This function may only be called during the live phase.err = (*jvmti)->GetThreadState(jvmti, thread, &state); abortOnError(err); switch (state & JVMTI_JAVA_LANG_THREAD_STATE_MASK) { case JVMTI_JAVA_LANG_THREAD_STATE_NEW: return "NEW"; case JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED: return "TERMINATED"; case JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE: return "RUNNABLE"; case JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED: return "BLOCKED"; case JVMTI_JAVA_LANG_THREAD_STATE_WAITING: return "WAITING"; case JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING: return "TIMED_WAITING"; }
|
Get All Threads
Get all live threads. The threads are Java programming language threads; that is, threads that are attached to the VM. A thread is live ifjvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) java.lang.Thread.isAlive() would return true , that is, the thread has been started and has not yet died. The universe of threads is determined by the context of the JVM TI environment, which typically is all threads attached to the VM. Note that this includes JVM TI agent threads (see RunAgentThread ). This function may only be called during the live phase.
|
Suspend Thread
Suspend the specified thread. If the calling thread is specified, this function will not return until some other thread callsjvmtiError SuspendThread(jvmtiEnv* env, jthread thread) ResumeThread . If the thread is currently suspended, this function does nothing and returns an error. This function may only be called during the live phase.
|
Suspend Thread List
Suspend thejvmtiError SuspendThreadList(jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results) request_count threads specified in the request_list array. Threads may be resumed with ResumeThreadList or ResumeThread . If the calling thread is specified in the request_list array, this function will not return until some other thread resumes it. Errors encountered in the suspension of a thread are returned in the results array, not in the return value of this function. Threads that are currently suspended are not suspended. This function may only be called during the live phase.
|
Resume Thread
Resume a suspended thread. Any threads currently suspended through a JVM TI suspend function (eg.jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) SuspendThread ) or java.lang.Thread.suspend() will resume execution; all other threads are unaffected. This function may only be called during the live phase.
|
Resume Thread List
Resume thejvmtiError ResumeThreadList(jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results) request_count threads specified in the request_list array. Any thread suspended through a JVM TI suspend function (eg. SuspendThreadList ) orjava.lang.Thread.suspend() will resume execution. This function may only be called during the live phase.
|
Stop Thread
Send the specified asynchronous exception to the specified thread (similar tojvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) java.lang.Thread.stop ). Normally, this function is used to kill the specified thread with an instance of the exception ThreadDeath . This function may only be called during the live phase.
|
Interrupt Thread
Interrupt the specified thread (similar tojvmtiError InterruptThread(jvmtiEnv* env, jthread thread) java.lang.Thread.interrupt ). This function may only be called during the live phase.
|
Get Thread Info
Get thread information. The fields of thetypedef struct { char* name; jint priority; jboolean is_daemon; jthreadGroup thread_group; jobject context_class_loader; } jvmtiThreadInfo;jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) jvmtiThreadInfo structure are filled in with details of the specified thread. This function may only be called during the live phase.
|
Get Owned Monitor Info
Get information about the monitors owned by the specified thread. This function may only be called during the live phase.jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env, jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr)
|
Get Current Contended Monitor
Get the object, if any, whose monitor the specified thread is waiting to enter or waiting to regain throughjvmtiError GetCurrentContendedMonitor(jvmtiEnv* env, jthread thread, jobject* monitor_ptr) java.lang.Object.wait . This function may only be called during the live phase.
|
Agent Start Function
Agent supplied callback function. This function is the entry point for an agent thread started withtypedef void (JNICALL *jvmtiStartFunction) (jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg); RunAgentThread .
|
Run Agent Thread
Starts the execution of an agent thread. with the specified native function. The parameterjvmtiError RunAgentThread(jvmtiEnv* env, jthread thread, jvmtiStartFunction proc, const void* arg, jint priority) arg is forwarded on to the start function(specified with proc ) as its single argument. This function allows the creation of agent threads for handling communication with another process or for handling events without the need to load a special subclass ofjava.lang.Thread or implementer of java.lang.Runnable . Instead, the created thread can run entirely in native code. However, the created thread does require a newly created instance of java.lang.Thread (referenced by the argument thread ) to which it will be associated. The thread object can be created with JNI calls. Ideally, all calls to Java programming language code should be done during the callback for the VMInit event to avoid any interaction with the target application. The following thread priorities are useful:
The new thread is started as a daemon thread with the specified priority . If enabled, a ThreadStart event will be sent. Since the thread has been started, the thread will be live when this function returns, unless the thread has died immediately. The thread group of the thread is ignored -- specifically, the thread is not added to the thread group and the thread is not seen on queries of the thread group at either the Java programming language or JVM TI levels. The thread is not visible to Java programming language queries but is included in JVM TI queries (for example, GetAllThreads and GetAllStackTraces ). Upon execution of proc , the new thread will be attached to the VM--see the JNI documentation on Attaching to the VM. This function may only be called during the live phase.
|
Set Thread Local Storage
The VM stores a pointer value associated with each environment-thread pair. This pointer value is called thread-local storage. This value isjvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) NULL unless set with this function. Agents can allocate memory in which they store thread specific information. By setting thread-local storage it can then be accessed with GetThreadLocalStorage . This function is called by the agent to set the value of the JVM TI thread-local storage. JVM TI supplies to the agent a pointer-size thread-local storage that can be used to record per-thread information. This function may only be called during the start or the live phase.
|
Get Thread Local Storage
Called by the agent to get the value of the JVM TI thread-local storage. This function may only be called during the start or the live phase.jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr)
|
Thread Group
Thread Group functions: Thread Group types:jvmtiThreadGroupInfo
- Thread group information structure
Get Top Thread Groups
Return all top-level (parentless) thread groups in the VM. This function may only be called during the live phase.jvmtiError GetTopThreadGroups(jvmtiEnv* env, jint* group_count_ptr, jthreadGroup** groups_ptr)
|
Get Thread Group Info
Get information about the thread group. The fields of thetypedef struct { jthreadGroup parent; char* name; jint max_priority; jboolean is_daemon; } jvmtiThreadGroupInfo;jvmtiError GetThreadGroupInfo(jvmtiEnv* env, jthreadGroup group, jvmtiThreadGroupInfo* info_ptr) jvmtiThreadGroupInfo structure are filled in with details of the specified thread group. This function may only be called during the live phase.
|
Get Thread Group Children
Get the live threads and active subgroups in this thread group. This function may only be called during the live phase.jvmtiError GetThreadGroupChildren(jvmtiEnv* env, jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr)
|
Stack Frame
Stack Frame functions:- Get Stack Trace
- Get All Stack Traces
- Get Thread List Stack Traces
- Get Frame Count
- Pop Frame
- Get Frame Location
- Notify Frame Pop
jvmtiFrameInfo
- Stack frame information structurejvmtiStackInfo
- Stack information structure
typedef struct { jmethodID method; jlocation location; } jvmtiFrameInfo;Information about a set of frames is returned in this structure:
typedef struct { jthread thread; jint state; jvmtiFrameInfo* frame_buffer; jint frame_count; } jvmtiStackInfo;
jvmtiFrameInfo - Stack frame information structure | ||
Field | Type | Description |
method | jmethodID | The method executing in this frame. |
location | jlocation | The index of the instruction executing in this frame. -1 if the frame is executing a native method. |
jvmtiStackInfo - Stack information structure | ||
Field | Type | Description |
thread | jthread | On return, the thread traced. |
state | jint | On return, the thread state. See GetThreadState . |
frame_buffer | jvmtiFrameInfo* | On return, this agent allocated buffer is filled with stack frame information. |
frame_count | jint | On return, the number of records filled into frame_buffer . This will be min(max_frame_count , stackDepth). |
Get Stack Trace
Get information about the stack of a thread. IfjvmtiError GetStackTrace(jvmtiEnv* env, jthread thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) max_frame_count is less than the depth of the stack, the max_frame_count deepest frames are returned, otherwise the entire stack is returned. Deepest frames are at the beginning of the returned buffer. The following example causes up to five of the deepest frames to be returned and (if there are any frames) the currently executing method name to be printed.
ThejvmtiFrameInfo frames[5]; jint count; jvmtiError err; err = (*jvmti)->GetStackTrace(jvmti, aThread, 0, 5, &frames, &count); if (err == JVMTI_ERROR_NONE && count >= 1) { char *methodName; err = (*jvmti)->GetMethodName(jvmti, frames[0].method, &methodName, NULL); if (err == JVMTI_ERROR_NONE) { printf("Executing method: %s", methodName); } } thread need not be suspended to call this function. The GetLineNumberTable function can be used to map locations to line numbers. Note that this mapping can be done lazily. If platform dependent method invocations are used to launch a thread, they may be included in the stack trace - that is, there may be frames deeper than main() and run() . This function may only be called during the live phase.
|
Get All Stack Traces
Get information about the stacks of all live threads (including agent threads). IfjvmtiError GetAllStackTraces(jvmtiEnv* env, jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) max_frame_count is less than the depth of a stack, themax_frame_count deepest frames are returned for that thread, otherwise the entire stack is returned. Deepest frames are at the beginning of the returned buffer. All stacks are collected simultaneously, that is, no changes will occur to the thread state or stacks between the sampling one thread and the next. The threads need not be suspended.
This function may only be called during the live phase.jvmtiStackInfo *stack_info; jint thread_count; int ti; jvmtiError err; err = (*jvmti)->GetAllStackTraces(jvmti, MAX_FRAMES, &stack_info, &thread_count); if (err != JVMTI_ERROR_NONE) { ... } for (ti = 0; ti < thread_count; ++ti) { jvmtiStackInfo *infop = &stack_info[ti]; jthread thread = infop->thread; jint state = infop->state; jvmtiFrameInfo *frames = infop->frame_buffer; int fi; myThreadAndStatePrinter(thread, state); for (fi = 0; fi < infop->frame_count; fi++) { myFramePrinter(frames[fi].method, frames[fi].location); } } /* this one Deallocate call frees all data allocated by GetAllStackTraces */ err = (*jvmti)->Deallocate(jvmti, stack_info);
|
Get Thread List Stack Traces
Get information about the stacks of the supplied threads. IfjvmtiError GetThreadListStackTraces(jvmtiEnv* env, jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) max_frame_count is less than the depth of a stack, the max_frame_count deepest frames are returned for that thread, otherwise the entire stack is returned. Deepest frames are at the beginning of the returned buffer. All stacks are collected simultaneously, that is, no changes will occur to the thread state or stacks between the sampling one thread and the next. The threads need not be suspended. If a thread terminates before the stack information is collected, a zero length stack (jvmtiStackInfo.frame_count will be zero) will be returned and the thread jvmtiStackInfo.state can be checked. See the example for the similar function GetAllStackTraces . This function may only be called during the live phase.
|
Get Frame Count
Get the number of frames currently in the specified thread's call stack. If this function is called for a thread actively executing bytecodes (for example, not the current thread and not suspended), the information returned is transient. This function may only be called during the live phase.jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr)
|
Pop Frame
Pop the topmost stack frame ofjvmtiError PopFrame(jvmtiEnv* env, jthread thread) thread 's stack. Popping a frame takes you to the preceding frame. When the thread is resumed, the execution state of the thread is reset to the state immediately before the called method was invoked. That is (using The Java Virtual Machine Specificationterminology):
PopFrame and resuming the thread the state of the stack is undefined. To pop frames beyond the first, these three steps must be repeated:
|
Get Frame Location
For a Java programming language frame, return the location of the instruction currently executing. This function may only be called during the live phase.jvmtiError GetFrameLocation(jvmtiEnv* env, jthread thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr)
|
Notify Frame Pop
When the frame that is currently atjvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) depth is popped from the stack, generate a FramePop event. See the FramePop event for details. Only frames corresponding to non-native Java programming language methods can receive notification. The specified thread must either be the current thread or the thread must be suspended. This function may only be called during the live phase.
|
Heap
Heap functions:- Get Tag
- Set Tag
- Force Garbage Collection
- Iterate Over Objects Reachable From Object
- Iterate Over Reachable Objects
- Iterate Over Heap
- Iterate Over Instances Of Class
- Get Objects With Tags
- Heap Object Callback
- Heap Root Object Callback
- Stack Reference Object Callback
- Object Reference Callback
SetTag
function or by callback functions such as
jvmtiHeapObjectCallback
Tags are local to the environment; that is, the tags of one environment are not visible in another.
Tags are
jlong
values which can be used simply to mark an object or to store a pointer to more detailed information. Objects which have not been tagged have an tag of zero. Setting a tag to zero makes the object untagged.
Heap Object Filter Enumeration ( jvmtiHeapObjectFilter
)Constant Value Description JVMTI_HEAP_OBJECT_TAGGED
1 Tagged objects only. JVMTI_HEAP_OBJECT_UNTAGGED
2 Untagged objects only. JVMTI_HEAP_OBJECT_EITHER
3 Either tagged or untagged objects.
Heap Root Kind Enumeration ( jvmtiHeapRootKind
)Constant Value Description JVMTI_HEAP_ROOT_JNI_GLOBAL
1 JNI global reference. JVMTI_HEAP_ROOT_SYSTEM_CLASS
2 System class. JVMTI_HEAP_ROOT_MONITOR
3 Monitor. JVMTI_HEAP_ROOT_STACK_LOCAL
4 Stack local. JVMTI_HEAP_ROOT_JNI_LOCAL
5 JNI local reference. JVMTI_HEAP_ROOT_THREAD
6 Thread. JVMTI_HEAP_ROOT_OTHER
7 Other.
Object Reference Enumeration ( jvmtiObjectReferenceKind
)Constant Value Description JVMTI_REFERENCE_CLASS
1 Reference from an object to its class. JVMTI_REFERENCE_FIELD
2 Reference from an object to the value of one of its instance fields. For references of this kind the referrer_index
parameter to thejvmtiObjectReferenceCallback is the index of the the instance field. The index is based on the order of all the object's fields. This includes all fields of the directly declared static and instance fields in the class, and includes all fields (both public and private) fields declared in superclasses and superinterfaces. The index is thus calculated by summing the index of field in the directly declared class (seeGetClassFields
), with the total number of fields (both public and private) declared in all superclasses and superinterfaces. The index starts at zero.JVMTI_REFERENCE_ARRAY_ELEMENT
3 Reference from an array to one of its elements. For references of this kind the referrer_index
parameter to thejvmtiObjectReferenceCallback is the array index.JVMTI_REFERENCE_CLASS_LOADER
4 Reference from a class to its class loader. JVMTI_REFERENCE_SIGNERS
5 Reference from a class to its signers array. JVMTI_REFERENCE_PROTECTION_DOMAIN
6 Reference from a class to its protection domain. JVMTI_REFERENCE_INTERFACE
7 Reference from a class to one of its interfaces. JVMTI_REFERENCE_STATIC_FIELD
8 Reference from a class to the value of one of its static fields. For references of this kind the referrer_index
parameter to thejvmtiObjectReferenceCallback is the index of the static field. The index is based on the order of the directly declared static and instance fields in the class (not inherited fields), starting at zero. SeeGetClassFields
.JVMTI_REFERENCE_CONSTANT_POOL
9 Reference from a class to a resolved entry in the constant pool. For references of this kind the referrer_index
parameter to thejvmtiObjectReferenceCallback is the index into constant pool table of the class, starting at 1. See The Constant Pool in the Java Virtual Machine Specification.
Iteration Control Enumeration ( jvmtiIterationControl
)Constant Value Description JVMTI_ITERATION_CONTINUE
1 Continue the iteration. If this is a reference iteration, follow the references of this object. JVMTI_ITERATION_IGNORE
2 Continue the iteration. If this is a reference iteration, ignore the references of this object. JVMTI_ITERATION_ABORT
0 Abort the iteration.
Rationale: The heap dumping functionality (below) uses a callback for each object. While it would seem that a buffered approach would provide better throughput, tests do not show this to be the case--possibly due to locality of memory reference or array access overhead.
Get Tag
Retrieve the tag associated with an object. The tag is a long value typically used to store a unique identifier or pointer to object information. The tag is set withjvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) SetTag . Objects for which no tags have been set return a tag value of zero. This function may only be called during the start or the live phase.
|
Set Tag
Set the tag associated with an object. The tag is a long value typically used to store a unique identifier or pointer to object information. The tag is visible withjvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) GetTag . This function may only be called during the start or the live phase.
|
Force Garbage Collection
Force the VM to perform a garbage collection. The garbage collection is as complete as possible. This function does not cause finalizers to be run. This function does not return until the garbage collection is finished. Although garbage collection is as complete as possible there is no guarantee that alljvmtiError ForceGarbageCollection(jvmtiEnv* env) ObjectFree events will have been sent by the time that this function returns. In particular, an object may be prevented from being freed because it is awaiting finalization. This function may only be called during the live phase.
|
Heap Object Callback
Agent supplied callback function. Describes (but does not pass in) an object in the heap. Return value should betypedef jvmtiIterationControl (JNICALL *jvmtiHeapObjectCallback) (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data); JVMTI_ITERATION_CONTINUE to continue iteration, orJVMTI_ITERATION_ABORT to stop iteration. This callback must not use JNI functions. This callback must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). An implementation may invoke this callback on an internal thread or the thread which called the iteration function.
|
Heap Root Object Callback
Agent supplied callback function. Describes (but does not pass in) an object that is a root for the purposes of garbage collection. Return value should betypedef jvmtiIterationControl (JNICALL *jvmtiHeapRootCallback) (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, void* user_data); JVMTI_ITERATION_CONTINUE to continue iteration,JVMTI_ITERATION_IGNORE to continue iteration without pursuing references from referree object or JVMTI_ITERATION_ABORT to stop iteration. This callback must not use JNI functions. This callback must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). An implementation may invoke this callback on an internal thread or the thread which called the iteration function.
|
Stack Reference Object Callback
Agent supplied callback function. Describes (but does not pass in) an object on the stack that is a root for the purposes of garbage collection. Return value should betypedef jvmtiIterationControl (JNICALL *jvmtiStackReferenceCallback) (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, jlong thread_tag, jint depth, jmethodID method, jint slot, void* user_data); JVMTI_ITERATION_CONTINUE to continue iteration,JVMTI_ITERATION_IGNORE to continue iteration without pursuing references from referree object or JVMTI_ITERATION_ABORT to stop iteration. This callback must not use JNI functions. This callback must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). An implementation may invoke this callback on an internal thread or the thread which called the iteration function.
|
Object Reference Callback
Agent supplied callback function. Describes a reference from an object (the referrer) to another object (the referree). Return value should betypedef jvmtiIterationControl (JNICALL *jvmtiObjectReferenceCallback) (jvmtiObjectReferenceKind reference_kind, jlong class_tag, jlong size, jlong* tag_ptr, jlong referrer_tag, jint referrer_index, void* user_data); JVMTI_ITERATION_CONTINUE to continue iteration,JVMTI_ITERATION_IGNORE to continue iteration without pursuing references from referree object or JVMTI_ITERATION_ABORT to stop iteration. This callback must not use JNI functions. This callback must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). An implementation may invoke this callback on an internal thread or the thread which called the iteration function.
|
Iterate Over Objects Reachable From Object
This function iterates over all objects that are directly and indirectly reachable from the specified object. For each object A (known as the referrer) with a reference to object B the specified callback function is called to describe the object reference. The callback is called exactly once for each reference from a referrer; this is true even if there are reference cycles or multiple paths to the referrer. There may be more than one reference between a referrer and a referree, These may be distinguished by thejvmtiError IterateOverObjectsReachableFromObject(jvmtiEnv* env, jobject object, jvmtiObjectReferenceCallback object_reference_callback, void* user_data) jvmtiObjectReferenceCallback.reference_kind andjvmtiObjectReferenceCallback.referrer_index . The callback for an object will always occur after the callback for its referrer. During the execution of this function the state of the heap does not change: no objects are allocated, no objects are garbage collected, and the state of objects (including held values) does not change. As a result, threads executing Java programming language code, threads attempting to resume the execution of Java programming language code, and threads attempting to execute JNI functions are typically stalled. This function may only be called during the live phase.
|
Iterate Over Reachable Objects
This function iterates over the root objects and all objects that are directly and indirectly reachable from the root objects. The root objects comprise the set of system classes, JNI globals, references from thread stacks, and other objects used as roots for the purposes of garbage collection. For each root thejvmtiError IterateOverReachableObjects(jvmtiEnv* env, jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, void* user_data) heap_root_callback or stack_ref_callback callback is called. An object can be a root object for more than one reason and in that case the appropriate callback is called for each reason. For each object reference the object_ref_callback callback function is called to describe the object reference. The callback is called exactly once for each reference from a referrer; this is true even if there are reference cycles or multiple paths to the referrer. There may be more than one reference between a referrer and a referree, These may be distinguished by the jvmtiObjectReferenceCallback.reference_kind andjvmtiObjectReferenceCallback.referrer_index . The callback for an object will always occur after the callback for its referrer. Roots are always reported to the profiler before any object references are reported. In other words, the object_ref_callback callback will not be called until the appropriate callback has been called for all roots. If theobject_ref_callback callback is specified as NULL then this function returns after reporting the root objects to the profiler. During the execution of this function the state of the heap does not change: no objects are allocated, no objects are garbage collected, and the state of objects (including held values) does not change. As a result, threads executing Java programming language code, threads attempting to resume the execution of Java programming language code, and threads attempting to execute JNI functions are typically stalled. This function may only be called during the live phase.
|
Iterate Over Heap
Iterate over all objects in the heap. This includes both reachable and unreachable objects. ThejvmtiError IterateOverHeap(jvmtiEnv* env, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void* user_data) object_filter parameter indicates the objects for which the callback function is called. If this parameter is JVMTI_HEAP_OBJECT_TAGGED then the callback will only be called for every object that is tagged. If the parameter is JVMTI_HEAP_OBJECT_UNTAGGED then the callback will only be for objects that are not tagged. If the parameter is JVMTI_HEAP_OBJECT_EITHER then the callback will be called for every object in the heap, irrespective of whether it is tagged or not. During the execution of this function the state of the heap does not change: no objects are allocated, no objects are garbage collected, and the state of objects (including held values) does not change. As a result, threads executing Java programming language code, threads attempting to resume the execution of Java programming language code, and threads attempting to execute JNI functions are typically stalled. This function may only be called during the live phase.
|
Iterate Over Instances Of Class
Iterate over all objects in the heap that are instances of the specified class. This includes both reachable and unreachable objects. ThejvmtiError IterateOverInstancesOfClass(jvmtiEnv* env, jclass klass, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void* user_data) object_filter parameter indicates the objects for which the callback function is called. If this parameter is JVMTI_HEAP_OBJECT_TAGGED then the callback will only be called for every object that is tagged. If the parameter is JVMTI_HEAP_OBJECT_UNTAGGED then the callback will only be called for objects that are not tagged. If the parameter is JVMTI_HEAP_OBJECT_EITHER then the callback will be called for every object in the heap, irrespective of whether it is tagged or not. During the execution of this function the state of the heap does not change: no objects are allocated, no objects are garbage collected, and the state of objects (including held values) does not change. As a result, threads executing Java programming language code, threads attempting to resume the execution of Java programming language code, and threads attempting to execute JNI functions are typically stalled. This function may only be called during the live phase.
|
Get Objects With Tags
Return objects in the heap with the specified tags. The format is parallel arrays of objects and tags. This function may only be called during the live phase.jvmtiError GetObjectsWithTags(jvmtiEnv* env, jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr)
|
Local Variable
Local Variable functions:- Get Local Variable - Object
- Get Local Variable - Int
- Get Local Variable - Long
- Get Local Variable - Float
- Get Local Variable - Double
- Set Local Variable - Object
- Set Local Variable - Int
- Set Local Variable - Long
- Set Local Variable - Float
- Set Local Variable - Double
GetLocalVariableTable
.
Get Local Variable - Object
This function may only be called during the live phase.jvmtiError GetLocalObject(jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject* value_ptr)
|
Get Local Variable - Int
jvmtiError GetLocalInt(jvmtiEnv* env, jthread thread, jint depth, jint slot, jint* value_ptr) GetLocalInt can be used to retrieve int , char , byte , and boolean values. This function may only be called during the live phase.
|
Get Local Variable - Long
This function may only be called during the live phase.jvmtiError GetLocalLong(jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong* value_ptr)
|
Get Local Variable - Float
This function may only be called during the live phase.jvmtiError GetLocalFloat(jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat* value_ptr)
|
Get Local Variable - Double
This function may only be called during the live phase.jvmtiError GetLocalDouble(jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble* value_ptr)
|
Set Local Variable - Object
This function may only be called during the live phase.jvmtiError SetLocalObject(jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject value)
|
Set Local Variable - Int
jvmtiError SetLocalInt(jvmtiEnv* env, jthread thread, jint depth, jint slot, jint value) SetLocalInt can be used to set int , char , byte , and boolean values. This function may only be called during the live phase.
|
Set Local Variable - Long
This function may only be called during the live phase.jvmtiError SetLocalLong(jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong value)
|
Set Local Variable - Float
This function may only be called during the live phase.jvmtiError SetLocalFloat(jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat value)
|
Set Local Variable - Double
This function may only be called during the live phase.jvmtiError SetLocalDouble(jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble value)
|
Breakpoint
Breakpoint functions:Set Breakpoint
Set a breakpoint at the instruction indicated byjvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) method and location . An instruction can only have one breakpoint. Whenever the designated instruction is about to be executed, a Breakpoint event is generated. This function may only be called during the live phase.
|
Clear Breakpoint
Clear the breakpoint at the bytecode indicated byjvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) method and location . This function may only be called during the live phase.
|
Watched Field
Watched Field functions:- Set Field Access Watch
- Clear Field Access Watch
- Set Field Modification Watch
- Clear Field Modification Watch
Set Field Access Watch
Generate ajvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) FieldAccess event when the field specified by klass and field is about to be accessed. An event will be generated for each access of the field until it is canceled with ClearFieldAccessWatch . Field accesses from Java programming language code or from JNI code are watched, fields modified by other means are not watched. Note that JVM TI users should be aware that their own field accesses will trigger the watch. A field can only have one field access watch set. Modification of a field is not considered an access--use SetFieldModificationWatch to monitor modifications. This function may only be called during the live phase.
|
Clear Field Access Watch
Cancel a field access watch previously set byjvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) SetFieldAccessWatch , on the field specified by klass and field . This function may only be called during the live phase.
|
Set Field Modification Watch
Generate ajvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) FieldModification event when the field specified by klass and field is about to be modified. An event will be generated for each modification of the field until it is canceled with ClearFieldModificationWatch . Field modifications from Java programming language code or from JNI code are watched, fields modified by other means are not watched. Note that JVM TI users should be aware that their own field modifications will trigger the watch. A field can only have one field modification watch set. This function may only be called during the live phase.
|
Clear Field Modification Watch
Cancel a field modification watch previously set byjvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) SetFieldModificationWatch , on the field specified by klass and field . This function may only be called during the live phase.
|
Class
Class functions:- Get Loaded Classes
- Get Classloader Classes
- Get Class Signature
- Get Class Status
- Get Source File Name
- Get Class Modifiers
- Get Class Methods
- Get Class Fields
- Get Implemented Interfaces
- Is Interface
- Is Array Class
- Get Class Loader
- Get Source Debug Extension
- Redefine Classes
jvmtiClassDefinition
- Class redefinition description
Get Loaded Classes
Return an array of all classes loaded in the virtual machine. The number of classes in the array is returned viajvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) class_count_ptr , and the array itself via classes_ptr . Array classes of all types (including arrays of primitive types) are included in the returned list. Primitive classes (for example,java.lang.Integer.TYPE ) are not included in this list. This function may only be called during the live phase.
|
Get Classloader Classes
Returns an array of those classes for which this class loader has been recorded as an initiating loader. Each class in the returned array was created by this class loader, either by defining it directly or by delegation to another class loader. See Creation and Loading in the Java Virtual Machine Specification. For JDK version 1.1 implementations that don't recognize the distinction between initiating and defining class loaders, this function should return all classes loaded in the virtual machine. The number of classes in the array is returned viajvmtiError GetClassLoaderClasses(jvmtiEnv* env, jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) class_count_ptr , and the array itself via classes_ptr . This function may only be called during the live phase.
|
Get Class Signature
For the class indicated byjvmtiError GetClassSignature(jvmtiEnv* env, jclass klass, char** signature_ptr, char** generic_ptr) klass , return the JNI type signature and the generic signature of the class. For example, java.util.List is "Ljava/util/List;" and int[] is "[I" The returned name for primitive classes is the type signature character of the corresponding primitive type. For example,java.lang.Integer.TYPE is "I" . This function may only be called during the start or the live phase.
|
Get Class Status
Get the status of the class. Zero or more of the following bits can be set.jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) This function may only be called during the start or the live phase.
|
Get Source File Name
For the class indicated byjvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) klass , return the source file name viasource_name_ptr . The returned string is a file name only and never contains a directory name. For primitive classes (for example, java.lang.Integer.TYPE ) and for arrays this function returns JVMTI_ERROR_ABSENT_INFORMATION . This function may only be called during the start or the live phase.
|
Get Class Modifiers
For the class indicated byjvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) klass , return the access flags via modifiers_ptr . Access flags are defined in the Java Virtual Machine Specification. If the class is an array class, then its public, private, and protected modifiers are the same as those of its component type. For arrays of primitives, this component type is represented by one of the primitive classes (for example, java.lang.Integer.TYPE ). If the class is a primitive class, its public modifier is always true, and its protected and private modifiers are always false. If the class is an array class or a primitive class then its final modifier is always true and its interface modifier is always false. The values of its other modifiers are not determined by this specification. This function may only be called during the start or the live phase.
|
Get Class Methods
For the class indicated byjvmtiError GetClassMethods(jvmtiEnv* env, jclass klass, jint* method_count_ptr, jmethodID** methods_ptr) klass , return a count of methods viamethod_count_ptr and a list of method IDs via methods_ptr . The method list contains constructors and static initializers as well as true methods. Only directly declared methods are returned (not inherited methods). An empty method list is returned for array classes and primitive classes (for example, java.lang.Integer.TYPE ). This function may only be called during the start or the live phase.
|
Get Class Fields
For the class indicated byjvmtiError GetClassFields(jvmtiEnv* env, jclass klass, jint* field_count_ptr, jfieldID** fields_ptr) klass , return a count of fields via field_count_ptr and a list of field IDs via fields_ptr . Only directly declared fields are returned (not inherited fields). Fields are returned in the order they occur in the class file. An empty field list is returned for array classes and primitive classes (for example, java.lang.Integer.TYPE ). Use JNI to determine the length of an array. This function may only be called during the start or the live phase.
|
Get Implemented Interfaces
Return the direct super-interfaces of this class. For a class, this function returns the interfaces declared in itsjvmtiError GetImplementedInterfaces(jvmtiEnv* env, jclass klass, jint* interface_count_ptr, jclass** interfaces_ptr) implements clause. For an interface, this function returns the interfaces declared in its extends clause. An empty interface list is returned for array classes and primitive classes (for example, java.lang.Integer.TYPE ). This function may only be called during the start or the live phase.
|
Is Interface
Determines whether a class object reference represents an interface. ThejvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) jboolean result is JNI_TRUE if the "class" is actually an interface, JNI_FALSE otherwise. This function may only be called during the start or the live phase.
|
Is Array Class
Determines whether a class object reference represents an array. ThejvmtiError IsArrayClass(jvmtiEnv* env, jclass klass, jboolean* is_array_class_ptr) jboolean result is JNI_TRUE if the class is an array, JNI_FALSE otherwise. This function may only be called during the start or the live phase.
|
Get Class Loader
For the class indicated byjvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) klass , return via classloader_ptr a reference to the class loader for the class. This function may only be called during the start or the live phase.
|
Get Source Debug Extension
For the class indicated byjvmtiError GetSourceDebugExtension(jvmtiEnv* env, jclass klass, char** source_debug_extension_ptr) klass , return the debug extension viasource_debug_extension_ptr . The returned string contains exactly the debug extension information present in the class file of klass . This function may only be called during the start or the live phase.
|
Redefine Classes
All classes given are redefined according to the definitions supplied. See the description of bytecode instrumentation for usage information. An original version of method is considered equivalent to the new version if:typedef struct { jclass klass; jint class_byte_count; const unsigned char* class_bytes; } jvmtiClassDefinition;jvmtiError RedefineClasses(jvmtiEnv* env, jint class_count, const jvmtiClassDefinition* class_definitions)
IsMethodObsolete . The new method version will be used on new invokes. If a method has active stack frames, those active frames continue to run the bytecodes of the original method version. If resetting of stack frames is desired, use PopFrame to pop frames with obsolete method versions. This function does not cause any initialization except that which would occur under the customary JVM semantics. In other words, redefining a class does not cause its initializers to be run. The values of static fields will remain as they were prior to the call. Threads need not be suspended. All breakpoints in the class are cleared. All attributes are updated. Instances of the redefined class are not affected -- fields retain their previous values. Tags on the instances are also unaffected. In response to this call, the JVM TI event Class File Load Hook will be sent (if enabled), but no other JVM TI events will be sent. The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, change modifiers, or change inheritance. These restrictions may be lifted in future versions. See the error return description below for information on error codes returned if an unsupported redefinition is attempted. This function may only be called during the live phase.
|
Object
Object functions: Object types:jvmtiMonitorUsage
- Object monitor usage information
Get Object Size
For the object indicated byjvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) object , return via size_ptr the size of the object. This size is an implementation-specific approximation of the amount of storage consumed by this object. It may include some or all of the object's overhead, and thus is useful for comparison within an implementation but not between implementations. The estimate may change during a single invocation of the JVM. This function may only be called during the start or the live phase.
|
Get Object Hash Code
For the object indicated byjvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) object , return via hash_code_ptr a hash code. This hash code could be used to maintain a hash table of object references, however, on some implementations this can cause significant performance impacts--in most cases tags will be a more efficient means of associating information with objects. This function guarantees the same hash code value for a particular object throughout its life This function may only be called during the start or the live phase.
|
Get Object Monitor Usage
Get information about the object's monitor. The fields of thetypedef struct { jthread owner; jint entry_count; jint waiter_count; jthread* waiters; jint notify_waiter_count; jthread* notify_waiters; } jvmtiMonitorUsage;jvmtiError GetObjectMonitorUsage(jvmtiEnv* env, jobject object, jvmtiMonitorUsage* info_ptr) jvmtiMonitorUsage structure are filled in with information about usage of the monitor. This function may only be called during the live phase.
|
Field
Field functions:Get Field Name (and Signature)
For the field indicated byjvmtiError GetFieldName(jvmtiEnv* env, jclass klass, jfieldID field, char** name_ptr, char** signature_ptr, char** generic_ptr) klass and field , return the field name via name_ptr and field signature via signature_ptr . The field signatures are defined in the JNI Specification and in the The Java Virtual Machine Specification where they are referred to as Field Descriptors. This function may only be called during the start or the live phase.
|
Get Field Declaring Class
For the field indicated byjvmtiError GetFieldDeclaringClass(jvmtiEnv* env, jclass klass, jfieldID field, jclass* declaring_class_ptr) klass and field return the class that defined it via declaring_class_ptr . The declaring class will either be klass , a superclass, or an implemented interface. This function may only be called during the start or the live phase.
|
Get Field Modifiers
For the field indicated byjvmtiError GetFieldModifiers(jvmtiEnv* env, jclass klass, jfieldID field, jint* modifiers_ptr) klass and field return the access flags viamodifiers_ptr . Access flags are defined in the Java Virtual Machine Specification . This function may only be called during the start or the live phase.
|
Is Field Synthetic
For the field indicated byjvmtiError IsFieldSynthetic(jvmtiEnv* env, jclass klass, jfieldID field, jboolean* is_synthetic_ptr) klass and field , return a value indicating whether the field is synthetic via is_synthetic_ptr . Synthetic fields are generated by the compiler but not present in the original source code. This function may only be called during the start or the live phase.
|
Method
Method functions:- Get Method Name (and Signature)
- Get Method Declaring Class
- Get Method Modifiers
- Get Max Locals
- Get Arguments Size
- Get Line Number Table
- Get Method Location
- Get Local Variable Table
- Get Bytecodes
- Is Method Native
- Is Method Synthetic
- Is Method Obsolete
jvmtiLineNumberEntry
- Line number table entryjvmtiLocalVariableEntry
- Local variable table entry
Get Method Name (and Signature)
For the method indicated byjvmtiError GetMethodName(jvmtiEnv* env, jmethodID method, char** name_ptr, char** signature_ptr, char** generic_ptr) method , return the method name via name_ptr and method signature via signature_ptr . The method signatures are defined in the JNI Specification and in the The Java Virtual Machine Specification where they are referred to as Method Descriptors. Note this is different than method signatures as defined in the Java Language Specification. This function may only be called during the start or the live phase.
|
Get Method Declaring Class
For the method indicated byjvmtiError GetMethodDeclaringClass(jvmtiEnv* env, jmethodID method, jclass* declaring_class_ptr) method , return the class that defined it viadeclaring_class_ptr . This function may only be called during the start or the live phase.
|
Get Method Modifiers
For the method indicated byjvmtiError GetMethodModifiers(jvmtiEnv* env, jmethodID method, jint* modifiers_ptr) method , return the access flags via modifiers_ptr . Access flags are defined in the Java Virtual Machine Specification . This function may only be called during the start or the live phase.
|
Get Max Locals
For the method indicated byjvmtiError GetMaxLocals(jvmtiEnv* env, jmethodID method, jint* max_ptr) method , return the number of local variable slots used by the method, including the local variables used to pass parameters to the method on its invocation. See max_locals in the Code Attribute section of the The JavaTM Virtual Machine Specification. This function may only be called during the start or the live phase.
|
Get Arguments Size
For the method indicated byjvmtiError GetArgumentsSize(jvmtiEnv* env, jmethodID method, jint* size_ptr) method , return via max_ptr the number of local variable slots used by the method's arguments. Note that two-word arguments use two slots. This function may only be called during the start or the live phase.
|
Get Line Number Table
For the method indicated bytypedef struct { jlocation start_location; jint line_number; } jvmtiLineNumberEntry;jvmtiError GetLineNumberTable(jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr) method , return a table of source line number entries. The size of the table is returned via entry_count_ptr and the table itself is returned via table_ptr . This function may only be called during the start or the live phase.
|
Get Method Location
For the method indicated byjvmtiError GetMethodLocation(jvmtiEnv* env, jmethodID method, jlocation* start_location_ptr, jlocation* end_location_ptr) method , return the beginning and ending addresses through start_location_ptr and end_location_ptr . In a conventional byte code indexing scheme, start_location_ptr will always point to zero andend_location_ptr will always point to the byte code count minus one. This function may only be called during the start or the live phase.
|
Get Local Variable Table
Return local variable information. This function may only be called during the live phase.typedef struct { jlocation start_location; jint length; char* name; char* signature; char* generic_signature; jint slot; } jvmtiLocalVariableEntry;jvmtiError GetLocalVariableTable(jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr)
|
Get Bytecodes
For the method indicated byjvmtiError GetBytecodes(jvmtiEnv* env, jmethodID method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) method , return the byte codes that implement the method. The number of bytecodes is returned via bytecode_count_ptr . The byte codes themselves are returned via bytecodes_ptr . This function may only be called during the start or the live phase.
|
Is Method Native
For the method indicated byjvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) method , return a value indicating whether the method is native via is_native_ptr This function may only be called during the start or the live phase.
|
Is Method Synthetic
For the method indicated byjvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) method , return a value indicating whether the method is synthetic via is_synthetic_ptr . Synthetic methods are generated by the compiler but not present in the original source code. This function may only be called during the start or the live phase.
|
Is Method Obsolete
Determine if a method ID refers to an obsolete method version. SeejvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) RedefineClasses for details. This function may only be called during the start or the live phase.
|
Raw Monitor
Raw Monitor functions:- Create Raw Monitor
- Destroy Raw Monitor
- Raw Monitor Enter
- Raw Monitor Exit
- Raw Monitor Wait
- Raw Monitor Notify
- Raw Monitor Notify All
Create Raw Monitor
Create a raw monitor. This function may only be called during the OnLoad or the live phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Destroy Raw Monitor
Destroy the raw monitor. If the monitor being destroyed has been entered by this thread, it will be exited before it is destroyed. If the monitor being destroyed has been entered by another thread, an error will be returned and the monitor will not be destroyed. This function may only be called during the OnLoad or the live phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Raw Monitor Enter
Gain exclusive ownership of a raw monitor. The same thread may enter a monitor more then once. The thread must exit the monitor the same number of times as it is entered. If a monitor is entered duringjvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) OnLoad (before attached threads exist) and has not exited when attached threads come into existence, the enter is considered to have occurred on the main thread. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Raw Monitor Exit
Release exclusive ownership of a raw monitor. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Raw Monitor Wait
Wait for notification of the raw monitor. Causes the current thread to wait until either another thread callsjvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) RawMonitorNotify or RawMonitorNotifyAll for the specified raw monitor, or the specified timeout has elapsed. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Raw Monitor Notify
Notify a single thread waiting on the raw monitor. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Raw Monitor Notify All
Notify all threads waiting on the raw monitor. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
JNI Function Interception
JNI Function Interception functions: Provides the ability to intercept and resend Java Native Interface (JNI) function calls by manipulating the JNI function table. See JNI Functions in the Java Native Interface Specification . The following example illustrates intercepting theNewGlobalRef
JNI call in order to count reference creation.
Sometime afterJNIEnv original_jni_Functions; JNIEnv redirected_jni_Functions; int my_global_ref_count = 0; jobject MyNewGlobalRef(JNIEnv *jni_env, jobject lobj) { ++my_global_ref_count; return originalJNIFunctions->NewGlobalRef(env, lobj); } void myInit() { jvmtiError err; err = (*jvmti_env)->GetJNIFunctionTable(jvmti_env, &original_jni_Functions); if (err != JVMTI_ERROR_NONE) { die(); } err = (*jvmti_env)->GetJNIFunctionTable(jvmti_env, &redirected_jni_Functions); if (err != JVMTI_ERROR_NONE) { die(); } redirectedJNIFunctions->NewGlobalRef = MyNewGlobalRef; err = (*jvmti_env)->SetJNIFunctionTable(jvmti_env, redirected_jni_Functions); if (err != JVMTI_ERROR_NONE) { die(); } }
myInit
is called the user's JNI code is executed which makes the call to create a new global reference. Instead of going to the normal JNI implementation the call goes to
myNewGlobalRef
. Note that a copy of the original function table is kept so that the normal JNI function can be called after the data is collected. Note also that any JNI functions which are not overwritten will behave normally.
Set JNI Function Table
Set the JNI function table in all current and future JNI environments. As a result, all future JNI calls are directed to the specified functions. UsejvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) GetJNIFunctionTable to get the function table to pass. The table is copied--changes to the local copy of the table have no effect. This function affects only the function table, all other aspects of the environment are unaffected. See the examples above. This function may only be called during the start or the live phase.
|
Get JNI Function Table
Get the JNI function table. The JNI function table is copied into allocated memory. IfjvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) SetJNIFunctionTable has been called, the modified (not the original) function table is returned. Only the function table is copied, no other aspects of the environment are copied. See the examples above. This function may only be called during the start or the live phase.
|
Event Management
Event Management functions:Set Event Callbacks
Set the functions to be called for each event. The callbacks are specified by supplying a replacement function table. The function table is copied--changes to the local copy of the table have no effect. This is an atomic action, all callbacks are set at once. No events are sent before this function is called. When an entry isjvmtiError SetEventCallbacks(jvmtiEnv* env, const jvmtiEventCallbacks* callbacks, jint size_of_callbacks) NULL or when the event is beyondsize_of_callbacks no event is sent. Details on events are described later in this document. An event must be enabled and have a callback in order to be sent--the order in which this function and SetEventNotificationMode are called does not affect the result. This function may only be called during the OnLoad or the live phase.
|
Set Event Notification Mode
Control the generation of events.typedef enum { JVMTI_ENABLE = 1, JVMTI_DISABLE = 0 } jvmtiEventMode;jvmtiError SetEventNotificationMode(jvmtiEnv* env, jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...) If thread is NULL , the event is enabled or disabled globally; otherwise, it is enabled or disabled for a particular thread. An event is generated for a particular thread if it is enabled either at the thread or global levels. See below for information on specific events. The following events cannot be controlled at the thread level through this function.
|
Generate Events
Generate events to represent the current state of the VM. For example, ifjvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type) event_type is JVMTI_EVENT_COMPILED_METHOD_LOAD , a CompiledMethodLoad event will be sent for each currently compiled method. Methods that were loaded and now have been unloaded are not sent. The history of what events have previous been sent does not effect what events are sent--all currently compiled methods will be sent each time this method is called. This function is useful when events may have been missed due to the agent attaching after program execution begins, this function generates the missed events. Attempts to execute Java programming language code or JNI functions may be paused until this function returns - so neither should be called from the thread sending the event. This function returns only after the missed events have been sent, processed and have returned. The event may be sent on a different thread than the thread on which the event occurred. The callback for the event must be set with SetEventCallbacks and the event must be enabled with SetEventNotificationMode or the events will not occur. If the VM no longer has the information to generate some or all of the requested events, the events are simply not sent - no error is returned. Only the following events are supported:
This function may only be called during the live phase.
|
Extension Mechanism
Extension Mechanism functions: Extension Mechanism function types: Extension Mechanism types:jvmtiParamInfo
- Extension Function/Event Parameter InfojvmtiExtensionFunctionInfo
- Extension Function InfojvmtiExtensionEventInfo
- Extension Event Info
Extension Function/Event Parameter Types ( jvmtiParamTypes
)Constant Value Description JVMTI_TYPE_JBYTE
101 Java programming language primitive type - byte
. JNI typejbyte
.JVMTI_TYPE_JCHAR
102 Java programming language primitive type - char
. JNI typejchar
.JVMTI_TYPE_JSHORT
103 Java programming language primitive type - short
. JNI typejshort
.JVMTI_TYPE_JINT
104 Java programming language primitive type - int
. JNI typejint
.JVMTI_TYPE_JLONG
105 Java programming language primitive type - long
. JNI typejlong
.JVMTI_TYPE_JFLOAT
106 Java programming language primitive type - float
. JNI typejfloat
.JVMTI_TYPE_JDOUBLE
107 Java programming language primitive type - double
. JNI typejdouble
.JVMTI_TYPE_JBOOLEAN
108 Java programming language primitive type - boolean
. JNI typejboolean
.JVMTI_TYPE_JOBJECT
109 Java programming language object type - java.lang.Object
. JNI typejobject
. Returned values are JNI local references and must be managed.JVMTI_TYPE_JTHREAD
110 Java programming language object type - java.lang.Thread
. JVM TI typejthread
. Returned values are JNI local references and must be managed.JVMTI_TYPE_JCLASS
111 Java programming language object type - java.lang.Class
. JNI typejclass
. Returned values are JNI local references and must be managed.JVMTI_TYPE_JVALUE
112 Union of all Java programming language primitive and object types - JNI type jvalue
. Returned values which represent object types are JNI local references and must be managed.JVMTI_TYPE_JFIELDID
113 Java programming language field identifier - JNI type jfieldID
.JVMTI_TYPE_JMETHODID
114 Java programming language method identifier - JNI type jmethodID
.JVMTI_TYPE_CCHAR
115 C programming language type - char
.JVMTI_TYPE_CVOID
116 C programming language type - void
.JVMTI_TYPE_JNIENV
117 JNI environment - JNIEnv
. Should be used with the correctjvmtiParamKind
to make it a pointer type.
Extension Function/Event Parameter Kinds ( jvmtiParamKind
)Constant Value Description JVMTI_KIND_IN
91 Ingoing argument - foo
.JVMTI_KIND_IN_PTR
92 Ingoing pointer argument - const foo*
.JVMTI_KIND_IN_BUF
93 Ingoing array argument - const foo*
.JVMTI_KIND_ALLOC_BUF
94 Outgoing allocated array argument - foo**
. Free withDeallocate
.JVMTI_KIND_ALLOC_ALLOC_BUF
95 Outgoing allocated array of allocated arrays argument - foo***
. Free withDeallocate
.JVMTI_KIND_OUT
96 Outgoing argument - foo*
.JVMTI_KIND_OUT_BUF
97 Outgoing array argument (pre-allocated by agent) - foo*
. Do notDeallocate
.
typedef struct { char* name; jvmtiParamKind kind; jvmtiParamTypes base_type; jboolean null_ok; } jvmtiParamInfo;
jvmtiParamInfo - Extension Function/Event Parameter Info | ||
Field | Type | Description |
name | char* | The parameter name, encoded as a modified UTF-8 string |
kind | jvmtiParamKind | The kind of the parameter - type modifiers |
base_type | jvmtiParamTypes | The base type of the parameter - modified by kind |
null_ok | jboolean | Is a NULL argument permitted? Applies only to pointer and object types. |
Extension Function
This is the implementation-specific extension function.typedef jvmtiError (JNICALL *jvmtiExtensionFunction) (jvmtiEnv* jvmti_env, ...);
|
Get Extension Functions
Returns the set of extension functions. This function may only be called during the OnLoad or the live phase.typedef struct { jvmtiExtensionFunction func; char* id; char* short_description; jint param_count; jvmtiParamInfo* params; jint error_count; jvmtiError* errors; } jvmtiExtensionFunctionInfo;jvmtiError GetExtensionFunctions(jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions)
|
Get Extension Events
Returns the set of extension events. This function may only be called during the OnLoad or the live phase.typedef struct { jint extension_event_index; char* id; char* short_description; jint param_count; jvmtiParamInfo* params; } jvmtiExtensionEventInfo;jvmtiError GetExtensionEvents(jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions)
|
Extension Event
This is the implementation-specific event. The event handler is set withtypedef void (JNICALL *jvmtiExtensionEvent) (jvmtiEnv* jvmti_env, ...); SetExtensionEventCallback . Event handlers for extension events must be declared varargs to match this definition. Failure to do so could result in calling convention mismatch and undefined behavior on some platforms. For example, if the jvmtiParamInfo returned by GetExtensionEvents indicates that there is a jint parameter, the event handler should be declared:
Note the terminal "void JNICALL myHandler(jvmtiEnv* jvmti_env, jint myInt, ...) ... " which indicates varargs.
|
Set Extension Event Callback
Sets the callback function for an extension event and enables the event. Or, if the callback isjvmtiError SetExtensionEventCallback(jvmtiEnv* env, jint extension_event_index, jvmtiExtensionEvent callback) NULL , disables the event. Note that unlike standard events, setting the callback and enabling the event are a single operation. This function may only be called during the OnLoad or the live phase.
|
Capability
Capability functions: Capability types:jvmtiCapabilities
- Capabilities of an Environment
- may never be added
- may be added in either the
OnLoad
or live phase in any environment - may be added only during the
OnLoad
phase - may be possessed by only one environment at a time
- may be possessed by only one environment at a time, and only during the
OnLoad
phase - and so on ...
- One VM might perform all execution by compiling bytecodes into native code and be unable to generate single step instructions. In this implementation the capability can not be added.
- Another VM may be able to switch execution to a single stepping interpreter at any time. In this implementation, having the capability has no overhead and could be added at any time.
- Yet another VM might be able to choose a bytecode compiling or single stepping capable interpreted execution engine at start up, but be unable to switch between them. In this implementation the capability would need to be added during the
OnLoad
phase (before bytecode execution begins) and would have a large impact on execution speed even if single stepping was never used. - Still another VM might be able to add an "is single stepping on" check into compiled bytecodes or a generated interpreter. Again in this implementation the capability would need to be added during the
OnLoad
phase but the overhead (a test and branch on each instruction) would be considerably less.
OnLoad
phase. For most virtual machines certain capabilities require special set up for the virtual machine and this set up must happen during the
OnLoad
phase, before the virtual machine begins execution. Once a capability is added, it can only be removed if explicitly relinquished by the environment.
The agent can,
determine what capabilities this VM can potentially provide
,
add the capabilities to be used
,
release capabilities which are no longer needed
, and
examine the currently available capabilities
.
Capability Examples
For example, a freshly started agent (in theOnLoad
function) wants to enable all possible capabilities. Note that, in general, this is not advisable as the agent may suffer a performance penalty for functionality it is not using. The code might look like this in C:
For example, if an agent wants to check if it can get the bytecodes of a method (that is, it wants to check if it previously added this capability and has not relinquished it), the code might look like this in C:jvmtiCapabilities capa; jvmtiError err; err = (*jvmti)->GetPotentialCapabilities(jvmti, &capa); if (err == JVMTI_ERROR_NONE) { err = (*jvmti)->AddCapabilities(jvmti, &capa);
jvmtiCapabilities capa; jvmtiError err; err = (*jvmti)->GetCapabilities(jvmti, &capa); if (err == JVMTI_ERROR_NONE) { if (capa.can_get_bytecodes) { ... } }
The Capabilities Structure
These functions use the capabilities structure (jvmtiCapabilities
) which contains boolean flags corresponding to each capability:
typedef struct { unsigned int can_tag_objects : 1; unsigned int can_generate_field_modification_events : 1; unsigned int can_generate_field_access_events : 1; unsigned int can_get_bytecodes : 1; unsigned int can_get_synthetic_attribute : 1; unsigned int can_get_owned_monitor_info : 1; unsigned int can_get_current_contended_monitor : 1; unsigned int can_get_monitor_info : 1; unsigned int can_pop_frame : 1; unsigned int can_redefine_classes : 1; unsigned int can_signal_thread : 1; unsigned int can_get_source_file_name : 1; unsigned int can_get_line_numbers : 1; unsigned int can_get_source_debug_extension : 1; unsigned int can_access_local_variables : 1; unsigned int can_maintain_original_method_order : 1; unsigned int can_generate_single_step_events : 1; unsigned int can_generate_exception_events : 1; unsigned int can_generate_frame_pop_events : 1; unsigned int can_generate_breakpoint_events : 1; unsigned int can_suspend : 1; unsigned int can_redefine_any_class : 1; unsigned int can_get_current_thread_cpu_time : 1; unsigned int can_get_thread_cpu_time : 1; unsigned int can_generate_method_entry_events : 1; unsigned int can_generate_method_exit_events : 1; unsigned int can_generate_all_class_hook_events : 1; unsigned int can_generate_compiled_method_load_events : 1; unsigned int can_generate_monitor_events : 1; unsigned int can_generate_vm_object_alloc_events : 1; unsigned int can_generate_native_method_bind_events : 1; unsigned int can_generate_garbage_collection_events : 1; unsigned int can_generate_object_free_events : 1; unsigned int : 15; unsigned int : 16; unsigned int : 16; unsigned int : 16; unsigned int : 16; unsigned int : 16; } jvmtiCapabilities;
jvmtiCapabilities - Capabilities of an Environment | ||
All types are unsigned int : 1 | ||
Field | Description | |
can_tag_objects | Can set and get tags, as described in the Heap category. | |
can_generate_field_modification_events | Can set watchpoints on field modification -SetFieldModificationWatch | |
can_generate_field_access_events | Can set watchpoints on field access -SetFieldAccessWatch | |
can_get_bytecodes | Can get bytecodes of a method GetBytecodes | |
can_get_synthetic_attribute | Can test if a field or method is synthetic -IsFieldSynthetic and IsMethodSynthetic | |
can_get_owned_monitor_info | Can get information about ownership of monitors -GetOwnedMonitorInfo | |
can_get_current_contended_monitor | Can GetCurrentContendedMonitor | |
can_get_monitor_info | Can GetObjectMonitorUsage | |
can_pop_frame | Can pop frames off the stack - PopFrame | |
can_redefine_classes | Can redefine classes with RedefineClasses . Bytecodes of the original and redefined methods can be different. The constant pool and attributes can also be different. | |
can_signal_thread | Can send stop or interrupt to threads | |
can_get_source_file_name | Can get the source file name of a class | |
can_get_line_numbers | Can get the line number table of a method | |
can_get_source_debug_extension | Can get the source debug extension of a class | |
can_access_local_variables | Can set and get local variables | |
can_maintain_original_method_order | Can return methods in the order they occur in the class file | |
can_generate_single_step_events | Can get single step events | |
can_generate_exception_events | Can get exception thrown and exception catchevents | |
can_generate_frame_pop_events | Can set and thus get FramePop events | |
can_generate_breakpoint_events | Can set and thus get Breakpoint events | |
can_suspend | Can suspend and resume threads | |
can_redefine_any_class | RedefineClasses can be called on any class (can_redefine_classes must also be set) | |
can_get_current_thread_cpu_time | Can get current thread CPU time | |
can_get_thread_cpu_time | Can get thread CPU time | |
can_generate | Can generate method entry events on entering a method | |
can_generate | Can generate method exit events on leaving a method | |
can_generate | Can generate ClassFileLoadHook events for every loaded class. | |
can_generate | Can generate events when a method is compiled or unloaded | |
can_generate | Can generate events on monitor activity | |
can_generate | Can generate events on VM allocation of an object | |
can_generate | Can generate events when a native method is bound to its implementation | |
can_generate | Can generate events when garbage collection begins or ends | |
can_generate | Can generate events when the garbage collector frees an object |
Get Potential Capabilities
Returns viajvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) capabilities_ptr the JVM TI features that can potentially be possessed by this environment at this time. The returned capabilities differ from the complete set of capabilities implemented by the VM in two cases: another environment possesses capabilities that can only be possessed by one environment, or the current phase is live, and certain capabilities can only be added during the OnLoad phase. The AddCapabilities function may be used to set any or all or these capabilities. Currently possessed capabilities are included. Typically this function is used in the OnLoad function. Some virtual machines may allow a limited set of capabilities to be added in the live phase. In this case, the set of potentially available capabilities will likely differ from the OnLoad phase set. See the Capability Examples. This function may only be called during the OnLoad or the live phase.
|
Add Capabilities
Set new capabilities by adding the capabilities pointed to byjvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) capabilities_ptr . All previous capabilities are retained. Typically this function is used in the OnLoad function. Some virtual machines may allow a limited set of capabilities to be added in the live phase. See the Capability Examples. This function may only be called during the OnLoad or the live phase.
|
Relinquish Capabilities
Relinquish the capabilities pointed to byjvmtiError RelinquishCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) capabilities_ptr . Some implementations may allow only one environment to have a capability (see the capability introduction). This function releases capabilities so that they may be used by other agents. All other capabilities are retained. The capability will no longer be present in GetCapabilities . Attempting to relinquish a capability that the agent does not possess is not an error. This function may only be called during the OnLoad or the live phase.
|
Get Capabilities
Returns viajvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) capabilities_ptr the optional JVM TI features which this environment currently possesses. An environment does not possess a capability unless it has been successfully added with AddCapabilities . An environment only loses possession of a capability if it has been relinquished with RelinquishCapabilities . Thus, this function returns the net result of the AddCapabilities and RelinquishCapabilities calls which have been made. See the Capability Examples. This function may be called during any phase.
|
Timers
Timers functions:- Get Current Thread CPU Timer Information
- Get Current Thread CPU Time
- Get Thread CPU Timer Information
- Get Thread CPU Time
- Get Timer Information
- Get Time
- Get Available Processors
jvmtiTimerInfo
- Timer Info
typedef struct { jlong max_value; jboolean may_skip_forward; jboolean may_skip_backward; jvmtiTimerKind kind; jlong reserved1; jlong reserved2; } jvmtiTimerInfo;Where the timer kind is --
Timer Kinds ( jvmtiTimerKind
)Constant Value Description JVMTI_TIMER_USER_CPU
30 CPU time that a thread is in user mode. JVMTI_TIMER_TOTAL_CPU
31 CPU time that a thread is in user or system mode. JVMTI_TIMER_ELAPSED
32 Elapsed time.
jvmtiTimerInfo - Timer Info | ||
Field | Type | Description |
max_value | jlong | The maximum value the timer can reach. After this value is reached the timer wraps back to zero. This is an unsigned value. If tested or printed as a jlong (signed value) it may appear to be a negative number. |
may_skip_forward | jboolean | If true, the timer can be externally adjusted and as a result skip forward. If false, the timer value will never increase faster than real time. |
may_skip_backward | jboolean | If true, the timer can be externally adjusted and as a result skip backward. If false, the timer value will be monotonically increasing. |
kind | jvmtiTimerKind | The kind of timer. On a platform that does not distinguish between user and system time,JVMTI_TIMER_TOTAL_CPU is returned. |
reserved1 | jlong | Reserved for future use. |
reserved2 | jlong | Reserved for future use. |
Get Current Thread CPU Timer Information
Get information about thejvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) GetCurrentThreadCpuTime timer. The fields of thejvmtiTimerInfo structure are filled in with details about the timer. This information is specific to the platform and the implementation ofGetCurrentThreadCpuTime and thus does not vary by thread nor does it vary during a particular invocation of the VM. Note that the implementations of GetCurrentThreadCpuTime and GetThreadCpuTime may differ, and thus the values returned by GetCurrentThreadCpuTimerInfo andGetThreadCpuTimerInfo may differ -- see GetCurrentThreadCpuTime for more information. This function may only be called during the start or the live phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Current Thread CPU Time
Return the CPU time utilized by the current thread. Note that thejvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr) GetThreadCpuTime function provides CPU time for any thread, including the current thread. GetCurrentThreadCpuTime exists to support platforms which cannot supply CPU time for threads other than the current thread or which have more accurate information for the current thread (seeGetCurrentThreadCpuTimerInfo vs GetThreadCpuTimerInfo ). On many platforms this call will be equivalent to:
This function may only be called during the start or the live phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for theGetThreadCpuTime(env, NULL, nanos_ptr) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Thread CPU Timer Information
Get information about thejvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) GetThreadCpuTime timer. The fields of thejvmtiTimerInfo structure are filled in with details about the timer. This information is specific to the platform and the implementation ofGetThreadCpuTime and thus does not vary by thread nor does it vary during a particular invocation of the VM. Note that the implementations of GetCurrentThreadCpuTime and GetThreadCpuTime may differ, and thus the values returned by GetCurrentThreadCpuTimerInfo andGetThreadCpuTimerInfo may differ -- see GetCurrentThreadCpuTime for more information. This function may only be called during the live phase.
|
Get Thread CPU Time
Return the CPU time utilized by the specified thread. Get information about this timer withjvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread, jlong* nanos_ptr) GetThreadCpuTimerInfo . This function may only be called during the live phase.
|
Get Timer Information
Get information about thejvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) GetTime timer. The fields of the jvmtiTimerInfo structure are filled in with details about the timer. This information will not change during a particular invocation of the VM. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Time
Return the current value of the system timer, in nanoseconds. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This function provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Get information about this timer withjvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) GetTimerInfo . This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Available Processors
Returns the number of processors available to the Java virtual machine. This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property. This function may be called during any phase.jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr)
|
System Properties
System Properties functions:Add To Bootstrap Class Loader Search
After the bootstrap class loader unsuccessfully searches for a class, the specified platform-dependent search pathjvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) segment will be searched as well. This function can be used to cause instrumentation classes to be defined by the bootstrap class loader. Only one segment (typically a directory or JAR file) may be specified in the segment . This function may be called multiple times to add multiple segments, the segments will be searched in the order that this function was called. This function may only be called during the OnLoad phase.
|
Get System Properties
The list of VM system property keys which may be used withjvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) GetSystemProperty is returned. It is strongly recommended that virtual machines provide the following property keys:
java.lang.System.getProperties . JNI method invocation may be used to accessjava.lang.System.getProperties . The set of properties may grow during execution. This function may only be called during the OnLoad or the live phase.
|
Get System Property
Return a VM system property value given the property key. The functionjvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) GetSystemProperties returns the set of property keys which may be used. The properties which can be retrieved may grow during execution. Since this is a VM view of system properties, the values of properties may differ from that returned by java.lang.System.getProperty(String) . A typical VM might copy the values of the VM system properties into the Properties held by java.lang.System during the initialization of that class. Thereafter any changes to the VM system properties (with SetSystemProperty ) or thejava.lang.System system properties (with java.lang.System.setProperty(String,String) ) would cause the values to diverge. JNI method invocation may be used to access java.lang.System.getProperty(String) . This function may only be called during the OnLoad or the live phase.
|
Set System Property
Set a VM system property value. The functionjvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) GetSystemProperties returns the set of property keys, some of these may be settable. See GetSystemProperty . This function may only be called during the OnLoad phase.
|
General
General functions:- Get Phase
- Dispose Environment
- Set Environment Local Storage
- Get Environment Local Storage
- Get Version Number
- Get Error Name
- Set Verbose Flag
- Get JLocation Format
Get Phase
Return the current phase of VM execution. The phases proceed in sequence:typedef enum { JVMTI_PHASE_ONLOAD = 1, JVMTI_PHASE_PRIMORDIAL = 2, JVMTI_PHASE_START = 6, JVMTI_PHASE_LIVE = 4, JVMTI_PHASE_DEAD = 8 } jvmtiPhase;jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) In the case of start-up failure the VM will proceed directly to the dead phase skipping intermediate phases and neither a VMInit nor VMDeath event will be sent. Most JVM TI functions operate only in the live phase. The following functions operate in either the OnLoad or live phases:
OnLoad phase:
The following functions operate in the start or live phases:
|
Dispose Environment
Shutdown a JVM TI connection created with JNIjvmtiError DisposeEnvironment(jvmtiEnv* env) GetEnv (see Environments). Dispose of any resources held by the environment. Suspended threads are not resumed, this must be done explicitly by the agent. Allocated memory is not released, this must be done explicitly by the agent. This environment may not be used after this call. This call returns to the caller. This function may be called during any phase.
|
Set Environment Local Storage
The VM stores a pointer value associated with each environment. This pointer value is called environment-local storage. This value isjvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) NULL unless set with this function. Agents can allocate memory in which they store environment specific information. By setting environment-local storage it can then be accessed with GetEnvironmentLocalStorage . Called by the agent to set the value of the JVM TI environment-local storage. JVM TI supplies to the agent a pointer-size environment-local storage that can be used to record per-environment information. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for the GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Environment Local Storage
Called by the agent to get the value of the JVM TI environment-local storage. This function may be called during any phase. This function may be called from the callbacks to the Heap iteration functions, or from the event handles for thejvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) GarbageCollectionStart ,GarbageCollectionFinish , and ObjectFree events.
|
Get Version Number
Return the JVM TI version viajvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) version_ptr . The return value is the version identifier. The version identifier includes major, minor and micro version as well as the interface type.
This function may be called during any phase.
|
Get Error Name
Return the symbolic name for an error code. For examplejvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) GetErrorName(env, JVMTI_ERROR_NONE, &err_name) would return in err_name the string "JVMTI_ERROR_NONE" . This function may be called during any phase.
|
Set Verbose Flag
typedef enum { JVMTI_VERBOSE_OTHER = 0, JVMTI_VERBOSE_GC = 1, JVMTI_VERBOSE_CLASS = 2, JVMTI_VERBOSE_JNI = 4 } jvmtiVerboseFlag;jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) Control verbose output. This is the output which typically is sent to stderr . This function may be called during any phase.
|
Get JLocation Format
Although the greatest functionality is achieved with location information referencing the virtual machine bytecode index, the definition oftypedef enum { JVMTI_JLOCATION_JVMBCI = 1, JVMTI_JLOCATION_MACHINEPC = 2, JVMTI_JLOCATION_OTHER = 0 } jvmtiJlocationFormat;jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) jlocation has intentionally been left unconstrained to allow VM implementations that do not have this information. This function describes the representation of jlocation used in this VM. If the returned format is JVMTI_JLOCATION_JVMBCI , jlocation s can be used as in indices into the array returned by GetBytecodes .
This function may be called during any phase.
|
Errors
Every JVM TI function returns ajvmtiError
error code.
It is the responsibility of the agent to call JVM
TI functions with valid parameters and in the proper context (calling thread is attached, phase is correct, etc.). Detecting some error conditions may be difficult, inefficient, or impossible for an implementation. The errors listed in
Function Specific Required Errors
must be detected by the implementation. All other errors represent the recommended response to the error condition.
Universal Errors
The following errors may be returned by any function- No error has occurred. This is the error code that is returned on successful completion of the function.
-
Pointer is unexpectedly
NULL
. - The function attempted to allocate memory and no more memory was available for allocation.
- The desired functionality has not been enabled in this virtual machine.
-
The thread being used to call this function is not attached to the virtual machine. Calls must be made from attached threads. See
AttachCurrentThread
in the JNI invocation API. - The JVM TI environment provided is no longer connected or is not an environment.
- The desired functionality is not available in the current phase. Always returned if the virtual machine has completed running.
- An unexpected internal error has occurred.
JVMTI_ERROR_NONE (0)
JVMTI_ERROR_NULL_POINTER (100)
JVMTI_ERROR_OUT_OF_MEMORY (110)
JVMTI_ERROR_ACCESS_DENIED (111)
JVMTI_ERROR_UNATTACHED_THREAD (115)
JVMTI_ERROR_INVALID_ENVIRONMENT (116)
JVMTI_ERROR_WRONG_PHASE (112)
JVMTI_ERROR_INTERNAL (113)
Function Specific Required Errors
The following errors are returned by some JVM TI functions and must be returned by the implementation when the condition occurs.- Invalid priority.
- Thread was not suspended.
- Thread already suspended.
- This operation requires the thread to be alive--that is, it must be started and not yet have died.
- The class has been loaded but not yet prepared.
- There are no Java programming language or JNI stack frames at the specified depth.
- Information about the frame is not available (e.g. for native frames).
- Item already set.
- Desired element (e.g. field or breakpoint) not found
- This thread doesn't own the raw monitor.
- The call has been interrupted before completion.
- The class cannot be modified.
- The functionality is not available in this virtual machine.
- The requested information is not available.
- The specified event type ID is not recognized.
- The requested information is not available for native method.
JVMTI_ERROR_INVALID_PRIORITY (12)
JVMTI_ERROR_THREAD_NOT_SUSPENDED (13)
JVMTI_ERROR_THREAD_SUSPENDED (14)
JVMTI_ERROR_THREAD_NOT_ALIVE (15)
JVMTI_ERROR_CLASS_NOT_PREPARED (22)
JVMTI_ERROR_NO_MORE_FRAMES (31)
JVMTI_ERROR_OPAQUE_FRAME (32)
JVMTI_ERROR_DUPLICATE (40)
JVMTI_ERROR_NOT_FOUND (41)
JVMTI_ERROR_NOT_MONITOR_OWNER (51)
JVMTI_ERROR_INTERRUPT (52)
JVMTI_ERROR_UNMODIFIABLE_CLASS (79)
JVMTI_ERROR_NOT_AVAILABLE (98)
JVMTI_ERROR_ABSENT_INFORMATION (101)
JVMTI_ERROR_INVALID_EVENT_TYPE (102)
JVMTI_ERROR_NATIVE_METHOD (104)
Function Specific Agent Errors
The following errors are returned by some JVM TI functions. They are returned in the event of invalid parameters passed by the agent or usage in an invalid context. An implementation is not required to detect these errors.- The passed thread is not a valid thread.
- Invalid field.
- Invalid method.
- Invalid location.
- Invalid object.
- Invalid class.
- The variable is not an appropriate type for the function used.
- Invalid slot.
- The capability being used is false in this environment.
- Thread group invalid.
- Invalid raw monitor.
- Illegal argument.
- The state of the thread has been modified, and is now inconsistent.
- A new class file has a version number not supported by this VM.
-
A new class file is malformed (the VM would return a
ClassFormatError
). -
The new class file definitions would lead to a circular definition (the VM would return a
ClassCircularityError
). - A new class file would require adding a method.
- A new class version changes a field.
- The class bytes fail verification.
- A direct superclass is different for the new class version, or the set of directly implemented interfaces is different.
- A new class version does not declare a method declared in the old class version.
- The class name defined in the new class file is different from the name in the old class object.
- A new class version has different modifiers.
- A method in the new class version has different modifiers than its counterpart in the old class version.
JVMTI_ERROR_INVALID_THREAD (10)
JVMTI_ERROR_INVALID_FIELDID (25)
JVMTI_ERROR_INVALID_METHODID (23)
JVMTI_ERROR_INVALID_LOCATION (24)
JVMTI_ERROR_INVALID_OBJECT (20)
JVMTI_ERROR_INVALID_CLASS (21)
JVMTI_ERROR_TYPE_MISMATCH (34)
JVMTI_ERROR_INVALID_SLOT (35)
JVMTI_ERROR_MUST_POSSESS_CAPABILITY (99)
JVMTI_ERROR_INVALID_THREAD_GROUP (11)
JVMTI_ERROR_INVALID_MONITOR (50)
JVMTI_ERROR_ILLEGAL_ARGUMENT (103)
JVMTI_ERROR_INVALID_TYPESTATE (65)
JVMTI_ERROR_UNSUPPORTED_VERSION (68)
JVMTI_ERROR_INVALID_CLASS_FORMAT (60)
JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION (61)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED (63)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED (64)
JVMTI_ERROR_FAILS_VERIFICATION (62)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED (66)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED (67)
JVMTI_ERROR_NAMES_DONT_MATCH (69)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED (70)
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED (71)
Data Types
JVM TI extends the data types defined by JNI.JVM Tool Interface Base Types | |
Type | Description |
jvmtiEnv | The JVM TI environment pointer. See the Function Section. jvmtiEnv points to the function table pointer. |
jthread | Subtype of jobject that holds a thread. |
typedef jobject jthread; | |
jthreadGroup | Subtype of jobject that holds a thread group. |
typedef jobject jthreadGroup; | |
jlocation | A 64 bit value, representing a monotonically increasing executable position within a method. -1 indicates a native method. See GetJLocationFormat for the format on a given VM. |
typedef jlong jlocation; | |
jrawMonitorID | A raw monitor. |
struct _jrawMonitorID; typedef struct _jrawMonitorID *jrawMonitorID; | |
jvmtiError | Holds an error return code. See the Error section for possible values.
typedef enum { JVMTI_ERROR_NONE = 0, JVMTI_ERROR_INVALID_THREAD = 10, ... } jvmtiError; |
jvmtiEvent | An identifier for an event type. See the Event section for possible values. It is guaranteed that future versions of this specification will never assign zero as an event type identifier.
typedef enum { JVMTI_EVENT_SINGLE_STEP = 1, JVMTI_EVENT_BREAKPOINT = 2, ... } jvmtiEvent; |
jvmtiEventCallbacks | The callbacks used for events.
See event callbacks for the complete structure. Where, for example, the VM initialization callback is defined:typedef struct { jvmtiEventVMInit VMInit; jvmtiEventVMDeath VMDeath; ... } jvmtiEventCallbacks; See the individual events for the callback function definition.typedef void (JNICALL *jvmtiEventVMInit) (jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread); |
jniNativeInterface | Typedef for the JNI function table JNINativeInterface defined in theJNI Specification. The JNI reference implementation defines this with an underscore. |
typedef struct JNINativeInterface_ jniNativeInterface; |
Structure Type Definitions | |
Type | Description |
jvmtiAddrLocationMap | Native address to location entry |
jvmtiCapabilities | Capabilities of an Environment |
jvmtiClassDefinition | Class redefinition description |
jvmtiExtensionEventInfo | Extension Event Info |
jvmtiExtensionFunctionInfo | Extension Function Info |
jvmtiFrameInfo | Stack frame information structure |
jvmtiLineNumberEntry | Line number table entry |
jvmtiLocalVariableEntry | Local variable table entry |
jvmtiMonitorUsage | Object monitor usage information |
jvmtiParamInfo | Extension Function/Event Parameter Info |
jvmtiStackInfo | Stack information structure |
jvmtiThreadGroupInfo | Thread group information structure |
jvmtiThreadInfo | Thread information structure |
jvmtiTimerInfo | Timer Info |
Function Type Definitions | |
Type | Description |
jvmtiExtensionEvent | Extension Event |
jvmtiExtensionFunction | Extension Function |
jvmtiHeapObjectCallback | Heap Object Callback |
jvmtiHeapRootCallback | Heap Root Object Callback |
jvmtiObjectReferenceCallback | Object Reference Callback |
jvmtiStackReferenceCallback | Stack Reference Object Callback |
jvmtiStartFunction | Agent Start Function |
Enumeration Definitions | |
Type | Description |
jvmtiEventMode | Event Enable/Disable |
jvmtiHeapObjectFilter | Heap Object Filter Enumeration |
jvmtiHeapRootKind | Heap Root Kind Enumeration |
jvmtiIterationControl | Iteration Control Enumeration |
jvmtiJlocationFormat | JLocation Format Enumeration |
jvmtiObjectReferenceKind | Object Reference Enumeration |
jvmtiParamKind | Extension Function/Event Parameter Kinds |
jvmtiParamTypes | Extension Function/Event Parameter Types |
jvmtiPhase | Phases of execution |
jvmtiTimerKind | Timer Kinds |
jvmtiVerboseFlag | Verbose Flag Enumeration |
Function Table Layout | ||
Position | Function | Declaration |
1 | reserved | void *reserved1; |
2 | Set Event Notification Mode | jvmtiError (JNICALL *SetEventNotificationMode) (jvmtiEnv* env, jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...); |
3 | reserved | void *reserved3; |
4 | Get All Threads | jvmtiError (JNICALL *GetAllThreads) (jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr); |
5 | Suspend Thread | jvmtiError (JNICALL *SuspendThread) (jvmtiEnv* env, jthread thread); |
6 | Resume Thread | jvmtiError (JNICALL *ResumeThread) (jvmtiEnv* env, jthread thread); |
7 | Stop Thread | jvmtiError (JNICALL *StopThread) (jvmtiEnv* env, jthread thread, jobject exception); |
8 | Interrupt Thread | jvmtiError (JNICALL *InterruptThread) (jvmtiEnv* env, jthread thread); |
9 | Get Thread Info | jvmtiError (JNICALL *GetThreadInfo) (jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr); |
10 | Get Owned Monitor Info | jvmtiError (JNICALL *GetOwnedMonitorInfo) (jvmtiEnv* env, jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr); |
11 | Get Current Contended Monitor | jvmtiError (JNICALL *GetCurrentContendedMonitor) (jvmtiEnv* env, jthread thread, jobject* monitor_ptr); |
12 | Run Agent Thread | jvmtiError (JNICALL *RunAgentThread) (jvmtiEnv* env, jthread thread, jvmtiStartFunction proc, const void* arg, jint priority); |
13 | Get Top Thread Groups | jvmtiError (JNICALL *GetTopThreadGroups) (jvmtiEnv* env, jint* group_count_ptr, jthreadGroup** groups_ptr); |
14 | Get Thread Group Info | jvmtiError (JNICALL *GetThreadGroupInfo) (jvmtiEnv* env, jthreadGroup group, jvmtiThreadGroupInfo* info_ptr); |
15 | Get Thread Group Children | jvmtiError (JNICALL *GetThreadGroupChildren) (jvmtiEnv* env, jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr); |
16 | Get Frame Count | jvmtiError (JNICALL *GetFrameCount) (jvmtiEnv* env, jthread thread, jint* count_ptr); |
17 | Get Thread State | jvmtiError (JNICALL *GetThreadState) (jvmtiEnv* env, jthread thread, jint* thread_state_ptr); |
18 | reserved | void *reserved18; |
19 | Get Frame Location | jvmtiError (JNICALL *GetFrameLocation) (jvmtiEnv* env, jthread thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr); |
20 | Notify Frame Pop | jvmtiError (JNICALL *NotifyFramePop) (jvmtiEnv* env, jthread thread, jint depth); |
21 | Get Local Variable - Object | jvmtiError (JNICALL *GetLocalObject) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject* value_ptr); |
22 | Get Local Variable - Int | jvmtiError (JNICALL *GetLocalInt) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jint* value_ptr); |
23 | Get Local Variable - Long | jvmtiError (JNICALL *GetLocalLong) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong* value_ptr); |
24 | Get Local Variable - Float | jvmtiError (JNICALL *GetLocalFloat) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat* value_ptr); |
25 | Get Local Variable - Double | jvmtiError (JNICALL *GetLocalDouble) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble* value_ptr); |
26 | Set Local Variable - Object | jvmtiError (JNICALL *SetLocalObject) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject value); |
27 | Set Local Variable - Int | jvmtiError (JNICALL *SetLocalInt) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jint value); |
28 | Set Local Variable - Long | jvmtiError (JNICALL *SetLocalLong) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong value); |
29 | Set Local Variable - Float | jvmtiError (JNICALL *SetLocalFloat) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat value); |
30 | Set Local Variable - Double | jvmtiError (JNICALL *SetLocalDouble) (jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble value); |
31 | Create Raw Monitor | jvmtiError (JNICALL *CreateRawMonitor) (jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr); |
32 | Destroy Raw Monitor | jvmtiError (JNICALL *DestroyRawMonitor) (jvmtiEnv* env, jrawMonitorID monitor); |
33 | Raw Monitor Enter | jvmtiError (JNICALL *RawMonitorEnter) (jvmtiEnv* env, jrawMonitorID monitor); |
34 | Raw Monitor Exit | jvmtiError (JNICALL *RawMonitorExit) (jvmtiEnv* env, jrawMonitorID monitor); |
35 | Raw Monitor Wait | jvmtiError (JNICALL *RawMonitorWait) (jvmtiEnv* env, jrawMonitorID monitor, jlong millis); |
36 | Raw Monitor Notify | jvmtiError (JNICALL *RawMonitorNotify) (jvmtiEnv* env, jrawMonitorID monitor); |
37 | Raw Monitor Notify All | jvmtiError (JNICALL *RawMonitorNotifyAll) (jvmtiEnv* env, jrawMonitorID monitor); |
38 | Set Breakpoint | jvmtiError (JNICALL *SetBreakpoint) (jvmtiEnv* env, jmethodID method, jlocation location); |
39 | Clear Breakpoint | jvmtiError (JNICALL *ClearBreakpoint) (jvmtiEnv* env, jmethodID method, jlocation location); |
40 | reserved | void *reserved40; |
41 | Set Field Access Watch | jvmtiError (JNICALL *SetFieldAccessWatch) (jvmtiEnv* env, jclass klass, jfieldID field); |
42 | Clear Field Access Watch | jvmtiError (JNICALL *ClearFieldAccessWatch) (jvmtiEnv* env, jclass klass, jfieldID field); |
43 | Set Field Modification Watch | jvmtiError (JNICALL *SetFieldModificationWatch) (jvmtiEnv* env, jclass klass, jfieldID field); |
44 | Clear Field Modification Watch | jvmtiError (JNICALL *ClearFieldModificationWatch) (jvmtiEnv* env, jclass klass, jfieldID field); |
45 | reserved | void *reserved45; |
46 | Allocate | jvmtiError (JNICALL *Allocate) (jvmtiEnv* env, jlong size, unsigned char** mem_ptr); |
47 | Deallocate | jvmtiError (JNICALL *Deallocate) (jvmtiEnv* env, unsigned char* mem); |
48 | Get Class Signature | jvmtiError (JNICALL *GetClassSignature) (jvmtiEnv* env, jclass klass, char** signature_ptr, char** generic_ptr); |
49 | Get Class Status | jvmtiError (JNICALL *GetClassStatus) (jvmtiEnv* env, jclass klass, jint* status_ptr); |
50 | Get Source File Name | jvmtiError (JNICALL *GetSourceFileName) (jvmtiEnv* env, jclass klass, char** source_name_ptr); |
51 | Get Class Modifiers | jvmtiError (JNICALL *GetClassModifiers) (jvmtiEnv* env, jclass klass, jint* modifiers_ptr); |
52 | Get Class Methods | jvmtiError (JNICALL *GetClassMethods) (jvmtiEnv* env, jclass klass, jint* method_count_ptr, jmethodID** methods_ptr); |
53 | Get Class Fields | jvmtiError (JNICALL *GetClassFields) (jvmtiEnv* env, jclass klass, jint* field_count_ptr, jfieldID** fields_ptr); |
54 | Get Implemented Interfaces | jvmtiError (JNICALL *GetImplementedInterfaces) (jvmtiEnv* env, jclass klass, jint* interface_count_ptr, jclass** interfaces_ptr); |
55 | Is Interface | jvmtiError (JNICALL *IsInterface) (jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr); |
56 | Is Array Class | jvmtiError (JNICALL *IsArrayClass) (jvmtiEnv* env, jclass klass, jboolean* is_array_class_ptr); |
57 | Get Class Loader | jvmtiError (JNICALL *GetClassLoader) (jvmtiEnv* env, jclass klass, jobject* classloader_ptr); |
58 | Get Object Hash Code | jvmtiError (JNICALL *GetObjectHashCode) (jvmtiEnv* env, jobject object, jint* hash_code_ptr); |
59 | Get Object Monitor Usage | jvmtiError (JNICALL *GetObjectMonitorUsage) (jvmtiEnv* env, jobject object, jvmtiMonitorUsage* info_ptr); |
60 | Get Field Name (and Signature) | jvmtiError (JNICALL *GetFieldName) (jvmtiEnv* env, jclass klass, jfieldID field, char** name_ptr, char** signature_ptr, char** generic_ptr); |
61 | Get Field Declaring Class | jvmtiError (JNICALL *GetFieldDeclaringClass) (jvmtiEnv* env, jclass klass, jfieldID field, jclass* declaring_class_ptr); |
62 | Get Field Modifiers | jvmtiError (JNICALL *GetFieldModifiers) (jvmtiEnv* env, jclass klass, jfieldID field, jint* modifiers_ptr); |
63 | Is Field Synthetic | jvmtiError (JNICALL *IsFieldSynthetic) (jvmtiEnv* env, jclass klass, jfieldID field, jboolean* is_synthetic_ptr); |
64 | Get Method Name (and Signature) | jvmtiError (JNICALL *GetMethodName) (jvmtiEnv* env, jmethodID method, char** name_ptr, char** signature_ptr, char** generic_ptr); |
65 | Get Method Declaring Class | jvmtiError (JNICALL *GetMethodDeclaringClass) (jvmtiEnv* env, jmethodID method, jclass* declaring_class_ptr); |
66 | Get Method Modifiers | jvmtiError (JNICALL *GetMethodModifiers) (jvmtiEnv* env, jmethodID method, jint* modifiers_ptr); |
67 | reserved | void *reserved67; |
68 | Get Max Locals | jvmtiError (JNICALL *GetMaxLocals) (jvmtiEnv* env, jmethodID method, jint* max_ptr); |
69 | Get Arguments Size | jvmtiError (JNICALL *GetArgumentsSize) (jvmtiEnv* env, jmethodID method, jint* size_ptr); |
70 | Get Line Number Table | jvmtiError (JNICALL *GetLineNumberTable) (jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr); |
71 | Get Method Location | jvmtiError (JNICALL *GetMethodLocation) (jvmtiEnv* env, jmethodID method, jlocation* start_location_ptr, jlocation* end_location_ptr); |
72 | Get Local Variable Table | jvmtiError (JNICALL *GetLocalVariableTable) (jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr); |
73 | reserved | void *reserved73; |
74 | reserved | void *reserved74; |
75 | Get Bytecodes | jvmtiError (JNICALL *GetBytecodes) (jvmtiEnv* env, jmethodID method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr); |
76 | Is Method Native | jvmtiError (JNICALL *IsMethodNative) (jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr); |
77 | Is Method Synthetic | jvmtiError (JNICALL *IsMethodSynthetic) (jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr); |
78 | Get Loaded Classes | jvmtiError (JNICALL *GetLoadedClasses) (jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr); |
79 | Get Classloader Classes | jvmtiError (JNICALL *GetClassLoaderClasses) (jvmtiEnv* env, jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr); |
80 | Pop Frame | jvmtiError (JNICALL *PopFrame) (jvmtiEnv* env, jthread thread); |
81 | reserved | void *reserved81; |
82 | reserved | void *reserved82; |
83 | reserved | void *reserved83; |
84 | reserved | void *reserved84; |
85 | reserved | void *reserved85; |
86 | reserved | void *reserved86; |
87 | Redefine Classes | jvmtiError (JNICALL *RedefineClasses) (jvmtiEnv* env, jint class_count, const jvmtiClassDefinition* class_definitions); |
88 | Get Version Number | jvmtiError (JNICALL *GetVersionNumber) (jvmtiEnv* env, jint* version_ptr); |
89 | Get Capabilities | jvmtiError (JNICALL *GetCapabilities) (jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr); |
90 | Get Source Debug Extension | jvmtiError (JNICALL *GetSourceDebugExtension) (jvmtiEnv* env, jclass klass, char** source_debug_extension_ptr); |
91 | Is Method Obsolete | jvmtiError (JNICALL *IsMethodObsolete) (jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr); |
92 | Suspend Thread List | jvmtiError (JNICALL *SuspendThreadList) (jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results); |
93 | Resume Thread List | jvmtiError (JNICALL *ResumeThreadList) (jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results); |
94 | reserved | void *reserved94; |
95 | reserved | void *reserved95; |
96 | reserved | void *reserved96; |
97 | reserved | void *reserved97; |
98 | reserved | void *reserved98; |
99 | reserved | void *reserved99; |
100 | Get All Stack Traces | jvmtiError (JNICALL *GetAllStackTraces) (jvmtiEnv* env, jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr); |
101 | Get Thread List Stack Traces | jvmtiError (JNICALL *GetThreadListStackTraces) (jvmtiEnv* env, jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr); |
102 | Get Thread Local Storage | jvmtiError (JNICALL *GetThreadLocalStorage) (jvmtiEnv* env, jthread thread, void** data_ptr); |
103 | Set Thread Local Storage | jvmtiError (JNICALL *SetThreadLocalStorage) (jvmtiEnv* env, jthread thread, const void* data); |
104 | Get Stack Trace | jvmtiError (JNICALL *GetStackTrace) (jvmtiEnv* env, jthread thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr); |
105 | reserved | void *reserved105; |
106 | Get Tag | jvmtiError (JNICALL *GetTag) (jvmtiEnv* env, jobject object, jlong* tag_ptr); |
107 | Set Tag | jvmtiError (JNICALL *SetTag) (jvmtiEnv* env, jobject object, jlong tag); |
108 | Force Garbage Collection | jvmtiError (JNICALL *ForceGarbageCollection) (jvmtiEnv* env); |
109 | Iterate Over Objects Reachable From Object | jvmtiError (JNICALL *IterateOverObjectsReachableFromObject) (jvmtiEnv* env, jobject object, jvmtiObjectReferenceCallback object_reference_callback, void* user_data); |
110 | Iterate Over Reachable Objects | jvmtiError (JNICALL *IterateOverReachableObjects) (jvmtiEnv* env, jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, void* user_data); |
111 | Iterate Over Heap | jvmtiError (JNICALL *IterateOverHeap) (jvmtiEnv* env, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void* user_data); |
112 | Iterate Over Instances Of Class | jvmtiError (JNICALL *IterateOverInstancesOfClass) (jvmtiEnv* env, jclass klass, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, void* user_data); |
113 | reserved | void *reserved113; |
114 | Get Objects With Tags | jvmtiError (JNICALL *GetObjectsWithTags) (jvmtiEnv* env, jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr); |
115 | reserved | void *reserved115; |
116 | reserved | void *reserved116; |
117 | reserved | void *reserved117; |
118 | reserved | void *reserved118; |
119 | reserved | void *reserved119; |
120 | Set JNI Function Table | jvmtiError (JNICALL *SetJNIFunctionTable) (jvmtiEnv* env, const jniNativeInterface* function_table); |
121 | Get JNI Function Table | jvmtiError (JNICALL *GetJNIFunctionTable) (jvmtiEnv* env, jniNativeInterface** function_table); |
122 | Set Event Callbacks | jvmtiError (JNICALL *SetEventCallbacks) (jvmtiEnv* env, const jvmtiEventCallbacks* callbacks, jint size_of_callbacks); |
123 | Generate Events | jvmtiError (JNICALL *GenerateEvents) (jvmtiEnv* env, jvmtiEvent event_type); |
124 | Get Extension Functions | jvmtiError (JNICALL *GetExtensionFunctions) (jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions); |
125 | Get Extension Events | jvmtiError (JNICALL *GetExtensionEvents) (jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions); |
126 | Set Extension Event Callback | jvmtiError (JNICALL *SetExtensionEventCallback) (jvmtiEnv* env, jint extension_event_index, jvmtiExtensionEvent callback); |
127 | Dispose Environment | jvmtiError (JNICALL *DisposeEnvironment) (jvmtiEnv* env); |
128 | Get Error Name | jvmtiError (JNICALL *GetErrorName) (jvmtiEnv* env, jvmtiError error, char** name_ptr); |
129 | Get JLocation Format | jvmtiError (JNICALL *GetJLocationFormat) (jvmtiEnv* env, jvmtiJlocationFormat* format_ptr); |
130 | Get System Properties | jvmtiError (JNICALL *GetSystemProperties) (jvmtiEnv* env, jint* count_ptr, char*** property_ptr); |
131 | Get System Property | jvmtiError (JNICALL *GetSystemProperty) (jvmtiEnv* env, const char* property, char** value_ptr); |
132 | Set System Property | jvmtiError (JNICALL *SetSystemProperty) (jvmtiEnv* env, const char* property, const char* value); |
133 | Get Phase | jvmtiError (JNICALL *GetPhase) (jvmtiEnv* env, jvmtiPhase* phase_ptr); |
134 | Get Current Thread CPU Timer Information | jvmtiError (JNICALL *GetCurrentThreadCpuTimerInfo) (jvmtiEnv* env, jvmtiTimerInfo* info_ptr); |
135 | Get Current Thread CPU Time | jvmtiError (JNICALL *GetCurrentThreadCpuTime) (jvmtiEnv* env, jlong* nanos_ptr); |
136 | Get Thread CPU Timer Information | jvmtiError (JNICALL *GetThreadCpuTimerInfo) (jvmtiEnv* env, jvmtiTimerInfo* info_ptr); |
137 | Get Thread CPU Time | jvmtiError (JNICALL *GetThreadCpuTime) (jvmtiEnv* env, jthread thread, jlong* nanos_ptr); |
138 | Get Timer Information | jvmtiError (JNICALL *GetTimerInfo) (jvmtiEnv* env, jvmtiTimerInfo* info_ptr); |
139 | Get Time | jvmtiError (JNICALL *GetTime) (jvmtiEnv* env, jlong* nanos_ptr); |
140 | Get Potential Capabilities | jvmtiError (JNICALL *GetPotentialCapabilities) (jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr); |
141 | reserved | void *reserved141; |
142 | Add Capabilities | jvmtiError (JNICALL *AddCapabilities) (jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr); |
143 | Relinquish Capabilities | jvmtiError (JNICALL *RelinquishCapabilities) (jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr); |
144 | Get Available Processors | jvmtiError (JNICALL *GetAvailableProcessors) (jvmtiEnv* env, jint* processor_count_ptr); |
145 | reserved | void *reserved145; |
146 | reserved | void *reserved146; |
147 | Get Environment Local Storage | jvmtiError (JNICALL *GetEnvironmentLocalStorage) (jvmtiEnv* env, void** data_ptr); |
148 | Set Environment Local Storage | jvmtiError (JNICALL *SetEnvironmentLocalStorage) (jvmtiEnv* env, const void* data); |
149 | Add To Bootstrap Class Loader Search | jvmtiError (JNICALL *AddToBootstrapClassLoaderSearch) (jvmtiEnv* env, const char* segment); |
150 | Set Verbose Flag | jvmtiError (JNICALL *SetVerboseFlag) (jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value); |
151 | reserved | void *reserved151; |
152 | reserved | void *reserved152; |
153 | reserved | void *reserved153; |
154 | Get Object Size | jvmtiError (JNICALL *GetObjectSize) (jvmtiEnv* env, jobject object, jlong* size_ptr); |
Events
Handling Events
Agents can be informed of many events that occur in application programs. To handle events, designate a set of callback functions withSetEventCallbacks
. For each event the corresponding callback function will be called. Arguments to the callback function provides additional information about the event. The callback function is usually called from within application threads and the JVM
TI implementation does not queue events in any way. This means that event callback functions must be written carefully. Here are some general guidelines. See the individual event descriptions for further suggestions.
- Any exception thrown during the execution of an event callback can overwrite any current pending exception in the current application thread. Care must be taken to preserve a pending exception when an event callback makes a JNI call that might generate an exception.
- Event callback functions must be re-entrant. The JVM TI implementation does not queue events. If an agent needs to process events one at a time, it can use a raw monitor inside the event callback functions to serialize event processing.
- Event callback functions that execute JNI's FindClass function to load classes need to note that FindClass locates the class loader associated with the current native method. For the purposes of class loading, an event callback that includes a JNI environment as a parameter to the callback, can be viewed as a native method of the current class executed by the event thread.
SetEventNotificationMode
. All events are initially disabled. Thus, in order to receive any event:
- If the event requires a capability, that capability must be added with
AddCapabilities
. - A callback for the event must be set with
SetEventCallbacks
. - The event must be enabled with
SetEventNotificationMode
.
SuspendThread
.
If an event is enabled in multiple environments, the event will be sent to each agent in the order that the environments were created.
Multiple Co-located Events
In many situations it is possible for multiple events to occur at the same location in one thread. When this happens, all the events are reported through the event callbacks in the order specified in this section. If the current location is at the entry point of a method, theMethodEntry
event is reported before any other event at the current location in the same thread.
If an exception catch has been detected at the current location, either because it is the beginning of a catch clause or a native method that cleared a pending exception has returned, the
exceptionCatch
event is reported before any other event at the current location in the same thread.
If a
singleStep
event or
breakpoint
event is triggered at the current location, the event is defined to occur immediately before the code at the current location is executed. These events are reported before any events which are triggered by the execution of code at the current location in the same thread (specifically:
exception
,
fieldAccess
, and
fieldModification
). If both a step and breakpoint event are triggered for the same thread and location, the step event is reported before the breakpoint event.
If the current location is the exit point of a method (that is, the last location before returning to the caller), the
MethodExit
event and the
FramePop
event (if requested) are reported after all other events at the current location in the same thread. There is no specified ordering of these two events with respect to each other.
Co-located events can be triggered during the processing of some other event by the agent at the same location in the same thread. If such an event, of type
y
, is triggered during the processing of an event of type
x
, and if
x
precedes
y
in the ordering specified above, the co-located event
y
is reported for the current thread and location. If
x
does not precede
y
,
y
is not reported for the current thread and location. For example, if a breakpoint is set at the current location during the processing of
SingleStep
, that breakpoint will be reported before the thread moves off the current location.
The following events are never considered to be co-located with other events.
Event Callbacks
The event callback structure below is used to specify the handler function for events. It is set with theSetEventCallbacks
function.
typedef struct { jvmtiEventVMInit VMInit; jvmtiEventVMDeath VMDeath; jvmtiEventThreadStart ThreadStart; jvmtiEventThreadEnd ThreadEnd; jvmtiEventClassFileLoadHook ClassFileLoadHook; jvmtiEventClassLoad ClassLoad; jvmtiEventClassPrepare ClassPrepare; jvmtiEventVMStart VMStart; jvmtiEventException Exception; jvmtiEventExceptionCatch ExceptionCatch; jvmtiEventSingleStep SingleStep; jvmtiEventFramePop FramePop; jvmtiEventBreakpoint Breakpoint; jvmtiEventFieldAccess FieldAccess; jvmtiEventFieldModification FieldModification; jvmtiEventMethodEntry MethodEntry; jvmtiEventMethodExit MethodExit; jvmtiEventNativeMethodBind NativeMethodBind; jvmtiEventCompiledMethodLoad CompiledMethodLoad; jvmtiEventCompiledMethodUnload CompiledMethodUnload; jvmtiEventDynamicCodeGenerated DynamicCodeGenerated; jvmtiEventDataDumpRequest DataDumpRequest; jvmtiEventReserved reserved72; jvmtiEventMonitorWait MonitorWait; jvmtiEventMonitorWaited MonitorWaited; jvmtiEventMonitorContendedEnter MonitorContendedEnter; jvmtiEventMonitorContendedEntered MonitorContendedEntered; jvmtiEventReserved reserved77; jvmtiEventReserved reserved78; jvmtiEventReserved reserved79; jvmtiEventReserved reserved80; jvmtiEventGarbageCollectionStart GarbageCollectionStart; jvmtiEventGarbageCollectionFinish GarbageCollectionFinish; jvmtiEventObjectFree ObjectFree; jvmtiEventVMObjectAlloc VMObjectAlloc; } jvmtiEventCallbacks;
Event Index
- Breakpoint
- Class File Load Hook
- Class Load
- Class Prepare
- Compiled Method Load
- Compiled Method Unload
- Data Dump Request
- Dynamic Code Generated
- Exception
- Exception Catch
- Field Access
- Field Modification
- Frame Pop
- Garbage Collection Finish
- Garbage Collection Start
- Method Entry
- Method Exit
- Monitor Contended Enter
- Monitor Contended Entered
- Monitor Wait
- Monitor Waited
- Native Method Bind
- Object Free
- Single Step
- Thread End
- Thread Start
- VM Death Event
- VM Initialization Event
- VM Object Allocation
- VM Start Event
Single Step
Single step events allow the agent to trace thread execution at the finest granularity allowed by the VM. A single step event is generated whenever a thread reaches a new location. Typically, single step events represent the completion of one VM instruction as defined the Java Virtual Machine Specification . However, some implementations may define locations differently. In any case thevoid JNICALL SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location)
method
and
location
parameters uniquely identify the current location and allow the mapping to source file and line number when that information is available.
No single step events are generated from within native methods.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_SINGLE_STEP = 60
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_single_step_events | Can get single step events |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread about to execution a new instruction |
method | jmethodID | Method about to execute a new instruction |
location | jlocation | Location of the new instruction |
Breakpoint
Breakpoint events are generated whenever a thread reaches a location designated as a breakpoint withvoid JNICALL Breakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location)
SetBreakpoint
. The
method
and
location
parameters uniquely identify the current location and allow the mapping to source file and line number when that information is available.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_BREAKPOINT = 62
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_breakpoint_events | Can set and thus get Breakpoint events |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. |
thread | jthread | Thread that hit the breakpoint |
method | jmethodID | Method that hit the breakpoint |
location | jlocation | location of the breakpoint |
Field Access
Field access events are generated whenever a thread accesses a field that was designated as a watchpoint withvoid JNICALL FieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location, jclass field_klass, jobject object, jfieldID field)
SetFieldAccessWatch
. The
method
and
location
parameters uniquely identify the current location and allow the mapping to source file and line number when that information is available.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_FIELD_ACCESS = 63
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_FIELD_ACCESS, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_field_access_events | Can set watchpoints on field access - SetFieldAccessWatch |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread accessing the field |
method | jmethodID | Method where the access is occurring |
location | jlocation | Location where the access is occurring |
field_klass | jclass | Class of the field being accessed |
object | jobject | Object with the field being accessed if the field is an instance field; NULL otherwise |
field | jfieldID | Field being accessed |
Field Modification
Field modification events are generated whenever a thread modifies a field that was designated as a watchpoint withvoid JNICALL FieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location, jclass field_klass, jobject object, jfieldID field, char signature_type, jvalue new_value)
SetFieldModificationWatch
. The
method
and
location
parameters uniquely identify the current location and allow the mapping to source file and line number when that information is available.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_FIELD_MODIFICATION = 64
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_FIELD_MODIFICATION, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_field_modification_events | Can set watchpoints on field modification -SetFieldModificationWatch |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread modifying the field |
method | jmethodID | Method where the modification is occurring |
location | jlocation | Location where the modification is occurring |
field_klass | jclass | Class of the field being modified |
object | jobject | Object with the field being modified if the field is an instance field; NULL otherwise |
field | jfieldID | Field being modified |
signature_type | char | Signature type of the new value |
new_value | jvalue | The new value |
Frame Pop
Frame pop events are generated upon exit from a single method in a single frame as specified in a call tovoid JNICALL FramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jboolean was_popped_by_exception)
NotifyFramePop
. This is true whether termination is caused by executing its return instruction or by throwing an exception to its caller (see
was_popped_by_exception
). However, frame pops caused by the
PopFrame
function are not reported.
The location reported by
GetFrameLocation
identifies the executable location in the returning method, immediately prior to the return.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_FRAME_POP = 61
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_FRAME_POP, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_frame_pop_events | Can set and thus get FramePop events |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread that is popping the frame |
method | jmethodID | Method being popped |
was_popped_by_exception | jboolean | True if frame was popped by a thrown exception. False if method exited through its return instruction. |
Method Entry
Method entry events are generated upon entry of Java programming language methods (including native methods). The location reported byvoid JNICALL MethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method)
GetFrameLocation
identifies the initial executable location in the method.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_METHOD_ENTRY = 65
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_method_entry_events | Can generate method entry events on entering a method |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread entering the method |
method | jmethodID | Method being entered |
Method Exit
Method exit events are generated upon exit from Java programming language methods (including native methods). This is true whether termination is caused by executing its return instruction or by throwing an exception to its caller (seevoid JNICALL MethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jboolean was_popped_by_exception, jvalue return_value)
was_popped_by_exception
).
The
method
field uniquely identifies the method being entered or exited. The
frame
field provides access to the stack frame for the method.
The location reported by
GetFrameLocation
identifies the executable location in the returning method immediately prior to the return.
Enabling method entry or exit events will significantly degrade performance on many platforms and is thus not advised for performance critical usage (such as profiling).
Bytecode instrumentation
should be used in these cases.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_METHOD_EXIT = 66
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_EXIT, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_method_exit_events | Can generate method exit events on leaving a method |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread exiting the method |
method | jmethodID | Method being exited |
was_popped_by_exception | jboolean | True if frame was popped by a thrown exception. False if method exited through its return instruction. |
return_value | jvalue | The return value of the method being exited. Undefined and should not be used if was_popped_by_exception is true. |
Native Method Bind
A Native Method Bind event is sent when a VM binds a Java programming language native method to the address of a function that implements the native method. This will occur when the native method is called for the first time and also occurs when the JNI functionvoid JNICALL NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, void* address, void** new_address_ptr)
RegisterNatives
is called. This event allows the bind to be redirected to an agent-specified proxy function. This event is not sent when the native method is unbound. Typically, this proxy function will need to be specific to a particular method or, to handle the general case, automatically generated assembly code, since after instrumentation code is executed the function at the original binding address will usually be invoked. The original binding can be restored or the redirection changed by use of the JNI function
RegisterNatives
. Some events may be sent during the primordial phase, JNI and most of JVM
TI cannot be used at this time but the method and address can be save for use later.
This event is sent during the primordial, start or live
phase
.
Event ID:
JVMTI_EVENT_NATIVE_METHOD_BIND = 67
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_native_method_bind_events | Can generate events when a native method is bound to its implementation |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread Will beNULL if sent during the primordial phase. |
thread | jthread | Thread requesting the bind |
method | jmethodID | Native method being bound |
address | void* | The address the VM is about to bind to--that is, the address of the implementation of the native method |
new_address_ptr | void** | if the referenced address is changed (that is, if*new_address_ptr is set), the binding will instead be made to the supplied address. |
Exception
Exception events are generated whenever an exception is first detected in a Java programming language method. The exception may have been thrown by a Java programming language or native method, but in the case of native methods, the event is not generated until the exception is first seen by a Java programming language method. If an exception is set and cleared in a native method (and thus is never visible to Java programming language code), no exception event is generated. Thevoid JNICALL Exception(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location, jobject exception, jmethodID catch_method, jlocation catch_location)
method
and
location
parameters uniquely identify the current location (where the exception was detected) and allow the mapping to source file and line number when that information is available. The
exception
field identifies the thrown exception object. The
catch_method
and
catch_location
identify the location of the catch clause, if any, that handles the thrown exception. If there is no such catch clause, each field is set to 0. There is no guarantee that the thread will ever reach this catch clause. If there are native methods on the call stack between the throw location and the catch clause, the exception may be reset by one of those native methods. Similarly, exceptions that are reported as uncaught (
catch_klass
et al. set to 0) may in fact be caught by native code. Agents can check for these occurrences by monitoring
ExceptionCatch
events. Note that finally clauses are implemented as catch and re-throw. Therefore they will be reported in the catch location.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_EXCEPTION = 58
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_exception_events | Can get exception thrown and exception catch events |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread generating the exception |
method | jmethodID | Method generating the exception |
location | jlocation | Location where exception occurred |
exception | jobject | The exception being thrown |
catch_method | jmethodID | Method that will catch the exception, or NULL if no known catch |
catch_location | jlocation | location which will catch the exception or zero if no known catch |
Exception Catch
Exception catch events are generated whenever a thrown exception is caught. If the exception is caught in a Java programming language method, the event is generated when the catch clause is reached. If the exception is caught in a native method, the event is generated as soon as control is returned to a Java programming language method. Exception catch events are generated for any exception for which a throw was detected in a Java programming language method. Note that finally clauses are implemented as catch and re-throw. Therefore they will generate exception catch events. Thevoid JNICALL ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, jlocation location, jobject exception)
method
and
location
parameters uniquely identify the current location and allow the mapping to source file and line number when that information is available. For exceptions caught in a Java programming language method, the
exception
object identifies the exception object. Exceptions caught in native methods are not necessarily available by the time the exception catch is reported, so the
exception
field is set to
NULL
.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_EXCEPTION_CATCH = 59
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION_CATCH, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_exception_events | Can get exception thrown and exception catch events |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread catching the exception |
method | jmethodID | Method catching the exception |
location | jlocation | Location where exception is being caught |
exception | jobject | Exception being caught |
Thread Start
Thread start events are generated by a new thread before its initial method executes. A thread may be listed in the array returned byvoid JNICALL ThreadStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread)
GetAllThreads
before its thread start event is generated. It is possible for other events to be generated on a thread before its thread start event.
The event is sent on the newly started
thread
.
This event is sent during the start or live
phase
.
Event ID:
JVMTI_EVENT_THREAD_START = 52
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. |
thread | jthread | Thread starting |
Thread End
Thread end events are generated by a terminating thread after its initial method has finished execution. A thread may be listed in the array returned byvoid JNICALL ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread)
GetAllThreads
after its thread end event is generated. No events are generated on a thread after its thread end event.
The event is sent on the dying
thread
.
This event is sent during the start or live
phase
.
Event ID:
JVMTI_EVENT_THREAD_END = 53
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. |
thread | jthread | Thread ending |
Class Load
A class load event is generated when a class is first loaded. The order of class load events generated by a particular thread are guaranteed to match the order of class loading within that thread. Array class creation does not generate a class load event. The creation of a primitive class (for example, java.lang.Integer.TYPE) does not generate a class load event. This event is sent at an early stage in loading the class. As a result the class should be used carefully. Note, for example, that methods and fields are not yet loaded, so queries for methods, fields, subclasses, and so on will not give correct results. See "Loading of Classes and Interfaces" in the Java Language Specification . For most purposes thevoid JNICALL ClassLoad(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass)
ClassPrepare
event will be more useful.
This event is sent during the start or live
phase
.
Event ID:
JVMTI_EVENT_CLASS_LOAD = 55
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread loading the class |
klass | jclass | Class being loaded |
Class Prepare
A class prepare event is generated when class preparation is complete. At this point, class fields, methods, and implemented interfaces are available, and no code from the class has been executed. Since array classes never have fields or methods, class prepare events are not generated for them. Class prepare events are not generated for primitive classes (for example,void JNICALL ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jclass klass)
java.lang.Integer.TYPE
).
This event is sent during the start or live
phase
.
Event ID:
JVMTI_EVENT_CLASS_PREPARE = 56
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread generating the class prepare |
klass | jclass | Class being prepared |
Class File Load Hook
Sent when the VM obtains a class file data, but before it constructs the in-memory representation for that class. Also sent whenvoid JNICALL ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jclass class_being_redefined, jobject loader, const char* name, jobject protection_domain, jint class_data_len, const unsigned char* class_data, jint* new_class_data_len, unsigned char** new_class_data)
RedefineClasses
is called in any JVM
TI environment. The agent can instrument the existing class file data sent by the VM to include profiling/debugging hooks. See the description of
bytecode instrumentation
for usage information.
This event may be sent before the VM is initialized. During this time no VM resources should be created. Some classes might not be compatible with the function (eg. ROMized classes) and this event will not be generated for these classes.
The agent must allocate the space for the modified class file data buffer using the memory allocation function
Allocate
because the VM is responsible for freeing the new class file data buffer using
Deallocate
.
If the agent wishes to modify the class file, it must set
new_class_data
to point to the newly instrumented class file data buffer and set
new_class_data_len
to the length of that buffer before returning from this call. If no modification is desired, the agent simply does not set
new_class_data
. If multiple agents have enabled this event the results are chained. That is, if
new_class_data
has been set, it becomes the
class_data
for the next agent. As with all events, agents are called in the order the environment was created.
This event is sent during the primordial, start or live
phase
.
Event ID:
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK = 54
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)
Capabilities | |
Required Functionality | |
Optional Features | |
Capability | Effect |
can_generate_all_class_hook_events | Can generate ClassFileLoadHook events for every loaded class. |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. Will be NULL if sent during the primordial phase. |
class_being_redefined | jclass | The class being redefined with RedefineClasses . NULL if sent by class load. |
loader | jobject | The class loader loading the class. NULL if the bootstrap class loader. |
name | const char* | Name of class being loaded as a VM internal qualified name (for example, "java/util/List"), encoded as amodified UTF-8 string. Note: if the class is defined with a NULL name or without a name specified, name will beNULL . |
protection_domain | jobject | The ProtectionDomain of the class. |
class_data_len | jint | Length of current class file data buffer. |
class_data | const unsigned char* | Pointer to the current class file data buffer. |
new_class_data_len | jint* | Pointer to the length of the new class file data buffer. |
new_class_data | unsigned char** | Pointer to the pointer to the instrumented class file data buffer. |
VM Start Event
The VM initialization event signals the start of the VM. At this time JNI is live but the VM is not yet fully initialized. Once this event is generated, the agent is free to call any JNI function. This event signals the beginning of the start phase, JVM TI functions permitted in the start phase may be called. In the case of VM start-up failure, this event will not be sent. This event is sent during the start or live phase . Event ID:void JNICALL VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env)
JVMTI_EVENT_VM_START = 57
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. |
VM Initialization Event
The VM initialization event signals the completion of VM initialization. Once this event is generated, the agent is free to call any JNI or JVM TI function. The VM initialization event can be preceded by or can be concurrent with other events, but the preceding events should be handled carefully, if at all, because the VM has not completed its initialization. The thread start event for the main application thread is guaranteed not to occur until after the handler for the VM initialization event returns. In the case of VM start-up failure, this event will not be sent. This event is sent only during the live phase . Event ID:void JNICALL VMInit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread)
JVMTI_EVENT_VM_INIT = 50
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread. |
thread | jthread | The initial thread |
VM Death Event
The VM death event notifies the agent of the termination of the VM. No events will occur after the VMDeath event. In the case of VM start-up failure, this event will not be sent. Note that Agent_OnUnload will still be called in these cases. This event is sent only during the live phase . Event ID:void JNICALL VMDeath(jvmtiEnv *jvmti_env, JNIEnv* jni_env)
JVMTI_EVENT_VM_DEATH = 51
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
Compiled Method Load
Sent when a method is compiled and loaded into memory by the VM. If it is unloaded, thetypedef struct { const void* start_address; jlocation location; } jvmtiAddrLocationMap;void JNICALL CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, const void* compile_info)
CompiledMethodUnload
event is sent. If it is moved, the
CompiledMethodUnload
event is sent, followed by a new
CompiledMethodLoad
event. Note that a single method may have multiple compiled forms, and that this event will be sent for each form. Note also that several methods may be inlined into a single address range, and that this event will be sent for each method.
These events can be sent after their initial occurrence with
GenerateEvents
.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_COMPILED_METHOD_LOAD = 68
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL)
jvmtiAddrLocationMap - Native address to location entry | ||
Field | Type | Description |
start_address | const void* | Starting native address of code corresponding to a location |
location | jlocation | Corresponding location. See GetJLocationFormat for the meaning of location. |
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_compiled_method_load_events | Can generate events when a method is compiled or unloaded |
Parameters | ||
Name | Type | Description |
method | jmethodID | Method being compiled and loaded |
code_size | jint | Size of compiled code |
code_addr | const void* | Address where compiled method code is loaded |
map_length | jint | Number of jvmtiAddrLocationMap entries in the address map. Zero if mapping information cannot be supplied. |
map | constjvmtiAddrLocationMap* | Map from native addresses to location. The native address range of each entry is from start_address tostart_address-1 of the next entry. NULL if mapping information cannot be supplied. |
compile_info | const void* | VM-specific compilation information. The referenced compile information is managed by the VM and must not depend on the agent for collection. A VM implementation defines the content and lifetime of the information. |
Compiled Method Unload
Sent when a compiled method is unloaded from memory. This event might not be sent on the thread which performed the unload. This event may be sent sometime after the unload occurs, but will be sent before the memory is reused by a newly generated compiled method. This event may be sent after the class is unloaded. This event is sent only during the live phase . Event ID:void JNICALL CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, const void* code_addr)
JVMTI_EVENT_COMPILED_METHOD_UNLOAD = 69
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_compiled_method_load_events | Can generate events when a method is compiled or unloaded |
Parameters | ||
Name | Type | Description |
method | jmethodID | Compiled method being unloaded. For identification of the compiled method only -- the class may be unloaded and therefore the method should not be used as an argument to further JNI or JVM TI functions. |
code_addr | const void* | Address where compiled method code was loaded. For identification of the compiled method only -- the space may have been reclaimed. |
Dynamic Code Generated
Sent when a component of the virtual machine is generated dynamically. This does not correspond to Java programming language code that is compiled--seevoid JNICALL DynamicCodeGenerated(jvmtiEnv *jvmti_env, const char* name, const void* address, jint length)
CompiledMethodLoad
. This is for native code--for example, an interpreter that is generated differently depending on command-line options.
Note that this event has no controlling capability. If a VM cannot generate these events, it simply does not send any.
These events can be sent after their initial occurrence with
GenerateEvents
.
This event is sent during the primordial, start or live
phase
.
Event ID:
JVMTI_EVENT_DYNAMIC_CODE_GENERATED = 70
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
name | const char* | Name of the code, encoded as a modified UTF-8 string. Intended for display to an end-user. The name might not be unique. |
address | const void* | Native address of the code |
length | jint | Length in bytes of the code |
Data Dump Request
Sent by the VM to request the agent to dump its data. This is just a hint and the agent need not react to this event. This is useful for processing command-line signals from users. For example, in the Java 2 SDK a CTRL-Break on Win32 and a CTRL-\ on Solaris causes the VM to send this event to the agent. This event is sent only during the live phase . Event ID:void JNICALL DataDumpRequest(jvmtiEnv *jvmti_env)
JVMTI_EVENT_DATA_DUMP_REQUEST = 71
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, NULL)
Capabilities | |
Required Functionality |
Parameters | ||
Name | Type | Description |
Monitor Contended Enter
Sent when a thread is attempting to enter a Java programming language monitor already acquired by another thread. This event is sent only during the live phase . Event ID:void JNICALL MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object)
JVMTI_EVENT_MONITOR_CONTENDED_ENTER = 75
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_monitor_events | Can generate events on monitor activity |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | JNI local reference to the thread attempting to enter the monitor |
object | jobject | JNI local reference to the monitor |
Monitor Contended Entered
Sent when a thread enters a Java programming language monitor after waiting for it to be released by another thread. This event is sent only during the live phase . Event ID:void JNICALL MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object)
JVMTI_EVENT_MONITOR_CONTENDED_ENTERED = 76
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_monitor_events | Can generate events on monitor activity |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | JNI local reference to the thread entering the monitor |
object | jobject | JNI local reference to the monitor |
Monitor Wait
Sent when a thread is about to wait on an object. That is, a thread is enteringvoid JNICALL MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object, jlong timeout)
Object.wait()
.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_MONITOR_WAIT = 73
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_monitor_events | Can generate events on monitor activity |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | JNI local reference to the thread about to wait |
object | jobject | JNI local reference to the monitor |
timeout | jlong | The number of milliseconds the thread will wait |
Monitor Waited
Sent when a thread finishes waiting on an object. That is, a thread is leavingvoid JNICALL MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object, jboolean timed_out)
Object.wait()
.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_MONITOR_WAITED = 74
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_monitor_events | Can generate events on monitor activity |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | JNI local reference to the thread that was finished waiting |
object | jobject | JNI local reference to the monitor. |
timed_out | jboolean | True if the monitor timed out |
VM Object Allocation
Sent when a method causes the virtual machine to allocate an Object visible to Java programming language code and the allocation is not detectable by other intrumentation mechanisms. Generally object allocation should be detected by instrumenting the bytecodes of allocating methods. Object allocation generated in native code by JNI function calls should be detected using JNI function interception . Some methods might not have associated bytecodes and are not native methods, they instead are executed directly by the VM. These methods should send this event. Virtual machines which are incapable of bytecode instrumentation for some or all of their methods can send this event. Typical examples where this event might be sent:void JNICALL VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jobject object, jclass object_klass, jlong size)
- Reflection -- for example,
java.lang.Class.newInstance()
- Methods not represented by bytecodes -- for example, VM intrinsics and J2ME preloaded classes
- Allocation due to bytecodes -- for example, the
new
andnewarray
VM instructions - Allocation due to JNI function calls -- for example,
AllocObject
- Allocations during VM initialization
- VM internal objects
JVMTI_EVENT_VM_OBJECT_ALLOC = 84
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_vm_object_alloc_events | Can generate events on VM allocation of an object |
Parameters | ||
Name | Type | Description |
jni_env | JNIEnv * | The JNI environment of the event (current) thread |
thread | jthread | Thread allocating the object. |
object | jobject | JNI local reference to the object that was allocated |
object_klass | jclass | JNI local reference to the class of the object |
size | jlong | Size of the object (in bytes). See GetObjectSize . |
Object Free
An Object Free event is sent when the garbage collector frees an object. Events are only sent for tagged objects--see heap functions . The event handler must not use JNI functions and must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). This event is sent only during the live phase . Event ID:void JNICALL ObjectFree(jvmtiEnv *jvmti_env, jlong tag)
JVMTI_EVENT_OBJECT_FREE = 83
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_object_free_events | Can generate events when the garbage collector frees an object |
Parameters | ||
Name | Type | Description |
tag | jlong | The freed object's tag |
Garbage Collection Start
A Garbage Collection Start event is sent when a full cycle garbage collection begins. Only stop-the-world collections are reported--that is, collections during which all threads cease to modify the state of the Java virtual machine. This means that some collectors will never generate these events. This event is sent while the VM is still stopped, thus the event handler must not use JNI functions and must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). This event is always sent as a matched pair withvoid JNICALL GarbageCollectionStart(jvmtiEnv *jvmti_env)
GarbageCollectionFinish
(assuming both events are enabled) and no garbage collection events will occur between them.
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_GARBAGE_COLLECTION_START = 81
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_garbage_collection_events | Can generate events when garbage collection begins or ends |
Parameters | ||
Name | Type | Description |
Garbage Collection Finish
A Garbage Collection Finish event is sent when a full garbage collection cycle ends. This event is sent while the VM is still stopped, thus the event handler must not use JNI functions and must not use JVM TI functions except those which specifically allow such use (see the raw monitor, memory management, and environment local storage functions). Some agents may need to do post garbage collection operations that require the use of the disallowed JVM TI or JNI functions. For these cases an agent thread can be created which waits on a raw monitor, and the handler for the Garbage Collection Finish event simply notifies the raw monitor This event is always sent as a matched pair withvoid JNICALL GarbageCollectionFinish(jvmtiEnv *jvmti_env)
GarbageCollectionStart
(assuming both events are enabled).
This event is sent only during the live
phase
.
Event ID:
JVMTI_EVENT_GARBAGE_COLLECTION_FINISH = 82
Enabling:
All events are initially disabled. Enable globally withSetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL)
Capabilities | |
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities ) must be true to use this event. | |
Capability | Effect |
can_generate_garbage_collection_events | Can generate events when garbage collection begins or ends |
Parameters | ||
Name | Type | Description |
Constant Index
JVMTI_CLASS_STATUS_ARRAY
JVMTI_CLASS_STATUS_ERROR
JVMTI_CLASS_STATUS_INITIALIZED
JVMTI_CLASS_STATUS_PREPARED
JVMTI_CLASS_STATUS_PRIMITIVE
JVMTI_CLASS_STATUS_VERIFIED
JVMTI_DISABLE
JVMTI_ENABLE
JVMTI_HEAP_OBJECT_EITHER
JVMTI_HEAP_OBJECT_TAGGED
JVMTI_HEAP_OBJECT_UNTAGGED
JVMTI_HEAP_ROOT_JNI_GLOBAL
JVMTI_HEAP_ROOT_JNI_LOCAL
JVMTI_HEAP_ROOT_MONITOR
JVMTI_HEAP_ROOT_OTHER
JVMTI_HEAP_ROOT_STACK_LOCAL
JVMTI_HEAP_ROOT_SYSTEM_CLASS
JVMTI_HEAP_ROOT_THREAD
JVMTI_ITERATION_ABORT
JVMTI_ITERATION_CONTINUE
JVMTI_ITERATION_IGNORE
JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED
JVMTI_JAVA_LANG_THREAD_STATE_MASK
JVMTI_JAVA_LANG_THREAD_STATE_NEW
JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE
JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED
JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING
JVMTI_JAVA_LANG_THREAD_STATE_WAITING
JVMTI_JLOCATION_JVMBCI
JVMTI_JLOCATION_MACHINEPC
JVMTI_JLOCATION_OTHER
JVMTI_KIND_ALLOC_ALLOC_BUF
JVMTI_KIND_ALLOC_BUF
JVMTI_KIND_IN
JVMTI_KIND_IN_BUF
JVMTI_KIND_IN_PTR
JVMTI_KIND_OUT
JVMTI_KIND_OUT_BUF
JVMTI_PHASE_DEAD
JVMTI_PHASE_LIVE
JVMTI_PHASE_ONLOAD
JVMTI_PHASE_PRIMORDIAL
JVMTI_PHASE_START
JVMTI_REFERENCE_ARRAY_ELEMENT
JVMTI_REFERENCE_CLASS
JVMTI_REFERENCE_CLASS_LOADER
JVMTI_REFERENCE_CONSTANT_POOL
JVMTI_REFERENCE_FIELD
JVMTI_REFERENCE_INTERFACE
JVMTI_REFERENCE_PROTECTION_DOMAIN
JVMTI_REFERENCE_SIGNERS
JVMTI_REFERENCE_STATIC_FIELD
JVMTI_THREAD_MAX_PRIORITY
JVMTI_THREAD_MIN_PRIORITY
JVMTI_THREAD_NORM_PRIORITY
JVMTI_THREAD_STATE_ALIVE
JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
JVMTI_THREAD_STATE_IN_NATIVE
JVMTI_THREAD_STATE_IN_OBJECT_WAIT
JVMTI_THREAD_STATE_INTERRUPTED
JVMTI_THREAD_STATE_PARKED
JVMTI_THREAD_STATE_RUNNABLE
JVMTI_THREAD_STATE_SLEEPING
JVMTI_THREAD_STATE_SUSPENDED
JVMTI_THREAD_STATE_TERMINATED
JVMTI_THREAD_STATE_VENDOR_1
JVMTI_THREAD_STATE_VENDOR_2
JVMTI_THREAD_STATE_VENDOR_3
JVMTI_THREAD_STATE_WAITING
JVMTI_THREAD_STATE_WAITING_INDEFINITELY
JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
JVMTI_TIMER_ELAPSED
JVMTI_TIMER_TOTAL_CPU
JVMTI_TIMER_USER_CPU
JVMTI_TYPE_CCHAR
JVMTI_TYPE_CVOID
JVMTI_TYPE_JBOOLEAN
JVMTI_TYPE_JBYTE
JVMTI_TYPE_JCHAR
JVMTI_TYPE_JCLASS
JVMTI_TYPE_JDOUBLE
JVMTI_TYPE_JFIELDID
JVMTI_TYPE_JFLOAT
JVMTI_TYPE_JINT
JVMTI_TYPE_JLONG
JVMTI_TYPE_JMETHODID
JVMTI_TYPE_JNIENV
JVMTI_TYPE_JOBJECT
JVMTI_TYPE_JSHORT
JVMTI_TYPE_JTHREAD
JVMTI_TYPE_JVALUE
JVMTI_VERBOSE_CLASS
JVMTI_VERBOSE_GC
JVMTI_VERBOSE_JNI
JVMTI_VERBOSE_OTHER
JVMTI_VERSION_INTERFACE_JNI
JVMTI_VERSION_INTERFACE_JVMTI
JVMTI_VERSION_MASK_INTERFACE_TYPE
JVMTI_VERSION_MASK_MAJOR
JVMTI_VERSION_MASK_MICRO
JVMTI_VERSION_MASK_MINOR
JVMTI_VERSION_SHIFT_MAJOR
JVMTI_VERSION_SHIFT_MICRO
JVMTI_VERSION_SHIFT_MINOR
from: http://docs.oracle.com/javase/1.5.0/docs/guide/jvmti/jvmti.html