JVMTM Tool Interface

Version 1.0


What is the JVM Tool Interface?

The JVMTM 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 JavaTM 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 JavaTM 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 file jvmti.h. To use these definitions add the J2SETM include directory to your include path and add
#include <jvmti.h>
    
to your source code.

Agent Command Line Options

The term "command-line option" is used below to mean options supplied in the JavaVMInitArgs 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.
-agentlib:<agent-lib-name>=<options>
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 library foo.dll from the system PATH under WindowsTM or libfoo.so from the LD_LIBRARY_PATH under the SolarisTM operating environment.
-agentpath:<path-to-agent>=<options>
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 library c:\myLibs\foo.dll.
The start-up routine Agent_OnLoad in the library will be invoked.

Libraries loaded with -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:
JNIEXPORT jint JNICALL 
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
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:

The VM will call the 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 from Agent_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:
JNIEXPORT void JNICALL 
Agent_OnUnload(JavaVM *vm)
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 for 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. A JAVA_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: 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: Although their JVM TI state is separate, agents inspect and modify the shared state of the VM, they also share the native environment in which they execute. As such, an agent can perturb the results of other agents or cause them to fail. It is the responsibility of the agent writer to specify the level of compatibility with other agents. JVM TI implementations are not capable of preventing destructive interactions between agents. Techniques to reduce the likelihood of these occurrences are beyond the scope of this document.

An agent creates a JVM TI environment by passing a JVM TI version as the interface ID to the JNI Invocation API function GetEnv. See Accessing Functions for more details on the creation and use of JVM TI environments. Typically, JVM TI environments are created by calling 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 to MyProfiler.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:

The class modification functionality provided in this interface (the 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:
      public Object() {
        MyProfiler.allocationTracker(this);
      }
    
However, if this change was made using the 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:

Sun, Sun Microsystems, the Sun logo, Java, and JVM are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.


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 type jvmtiEnv*. 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:
jvmtiEnv *jvmti;
...
jvmtiError err = (*jvmti)->GetLoadedClasses(jvmti, &class_count, &classes);
    

When used from the C++ language: functions are accessed as member functions of jvmtiEnv; the environment pointer is not passed to the function call; for example:
jvmtiEnv *jvmti;
...
jvmtiError err = jvmti->GetLoadedClasses(&class_count, &classes);
    
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 API GetEnv function:
jvmtiEnv *jvmti;
...
(*jvm)->GetEnv(jvm, &jvmti, JVMTI_VERSION_1_0);
    
Each call to 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 the jvmtiError 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

Memory Management functions:


Allocate

jvmtiError
Allocate(jvmtiEnv* env,
            jlong size,
            unsigned char** mem_ptr)
Allocate an area of memory through the JVM TI allocator. The allocated memory should be freed with 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.

Capabilities
Required Functionality

Parameters
Name Type Description
sizejlong The number of bytes to allocate.

Rationale: jlong is used for compatibility with JVMDI.

mem_ptrunsigned char** On return, a pointer to the beginning of the allocated memory. If size is zero, NULL is returned.

Agent passes a pointer to a unsigned char*. On return, the unsigned char* points to a newly allocated array of size size. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_OUT_OF_MEMORY Memory request cannot be honored.
JVMTI_ERROR_ILLEGAL_ARGUMENT size is less than zero.
JVMTI_ERROR_NULL_POINTER mem_ptr is NULL.

Deallocate

jvmtiError
Deallocate(jvmtiEnv* env,
            unsigned char* mem)
Deallocate 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.

Capabilities
Required Functionality

Parameters
Name Type Description
mem unsigned char * A pointer to the beginning of the allocated memory. Please ignore "On return, the elements are set."

Agent passes an array of unsigned char. The incoming values of the elements of the array are ignored. On return, the elements are set. If mem is NULL, the call is ignored.

Errors
This function returns a universal error


Thread

Thread functions: Thread function types: Thread types:


Get Thread State

jvmtiError
GetThreadState(jvmtiEnv* env,
            jthread thread,
            jint* thread_state_ptr)
Get the state of a thread. The state of the thread is represented by the answers to the hierarchical set of questions below:

The answers are represented by the following bit vector.
Thread State Flags
Constant Value Description
JVMTI_THREAD_STATE_ALIVE0x0001 Thread is alive. Zero if thread is new (not started) or terminated.
JVMTI_THREAD_STATE_TERMINATED0x0002 Thread has completed execution.
JVMTI_THREAD_STATE_RUNNABLE0x0004 Thread is runnable.
JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER0x0400 Thread is waiting to enter a synchronization block/method or, after an Object.wait(), waiting to re-enter a synchronization block/method.
JVMTI_THREAD_STATE_WAITING0x0080 Thread is waiting.
JVMTI_THREAD_STATE_WAITING_INDEFINITELY0x0010 Thread is waiting without a timeout. For example, Object.wait().
JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT0x0020 Thread is waiting with a maximum time to wait specified. For example, Object.wait(long).
JVMTI_THREAD_STATE_SLEEPING0x0040 Thread is sleeping -- Thread.sleep(long).
JVMTI_THREAD_STATE_IN_OBJECT_WAIT0x0100 Thread is waiting on an object monitor -- Object.wait.
JVMTI_THREAD_STATE_PARKED0x0200 Thread is parked, for example: LockSupport.park, LockSupport.parkUtil and LockSupport.parkNanos.
JVMTI_THREAD_STATE_SUSPENDED0x100000 Thread suspended. java.lang.Thread.suspend() or a JVM TI suspend function (such as SuspendThread) has been called on the thread. If this bit is set, the other bits refer to the thread state before suspension.
JVMTI_THREAD_STATE_INTERRUPTED0x200000 Thread has been interrupted.
JVMTI_THREAD_STATE_IN_NATIVE0x400000 Thread is in native code--that is, a native method is running which has not called back into the VM or Java programming language code.

This flag is not set when running VM compiled Java programming language code nor is it set when running VM code or VM support code. Native VM interface functions, such as JNI and JVM TI functions, may be implemented as VM code.
JVMTI_THREAD_STATE_VENDOR_10x10000000 Defined by VM vendor.
JVMTI_THREAD_STATE_VENDOR_20x20000000 Defined by VM vendor.
JVMTI_THREAD_STATE_VENDOR_30x40000000 Defined by VM vendor.
The following definitions are used to convert JVM TI thread state to java.lang.Thread.State style states.
java.lang.Thread.State Conversion Masks
Constant Value Description
JVMTI_JAVA_LANG_THREAD_STATE_MASKJVMTI_THREAD_STATE_TERMINATED | JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_INDEFINITELY | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT Mask the state with this before comparison
JVMTI_JAVA_LANG_THREAD_STATE_NEW0 java.lang.Thread.State.NEW
JVMTI_JAVA_LANG_THREAD_STATE_TERMINATEDJVMTI_THREAD_STATE_TERMINATED java.lang.Thread.State.TERMINATED
JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLEJVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE java.lang.Thread.State.RUNNABLE
JVMTI_JAVA_LANG_THREAD_STATE_BLOCKEDJVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER java.lang.Thread.State.BLOCKED
JVMTI_JAVA_LANG_THREAD_STATE_WAITINGJVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_INDEFINITELY java.lang.Thread.State.WAITING
JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITINGJVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT java.lang.Thread.State.TIMED_WAITING
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_RUNNABLE
  • JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
  • JVMTI_THREAD_STATE_WAITING
can be set (a J2SETM compliant implementation will always set one of these if 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_INDEFINITELY
  • JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
can be set (a J2SETM compliant implementation will always set one of these if 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_IN_OBJECT_WAIT
  • JVMTI_THREAD_STATE_PARKED
  • JVMTI_THREAD_STATE_SLEEPING
can be set. And if any of these is set, the enclosing answers 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_SUSPENDED
  • JVMTI_THREAD_STATE_INTERRUPTED
  • JVMTI_THREAD_STATE_IN_NATIVE
can be set, but if any is set, 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:
            JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
        
The state of a thread which hasn't started yet would be:
            0
        
The state of a thread at a Object.wait(3000) would be:
            JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_WAITING + 
                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT + 
                JVMTI_THREAD_STATE_MONITOR_WAITING
        
The state of a thread suspended while runnable would be:
            JVMTI_THREAD_STATE_ALIVE + JVMTI_THREAD_STATE_RUNNABLE + JVMTI_THREAD_STATE_SUSPENDED
        

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:
	jint state;
	jvmtiError err;

	err = (*jvmti)->GetThreadState(jvmti, thread, &state);
	if (err == JVMTI_ERROR_NONE) {
	   if (state & JVMTI_THREAD_STATE_SLEEPING) {  ...
        

For waiting (that is, in Object.wait, parked, or sleeping) it would be:
	   if (state & JVMTI_THREAD_STATE_WAITING) {  ...
        
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_ALIVE | JVMTI_THREAD_STATE_TERMINATED)) == 0)  {  ...
        
To distinguish timed from untimed Object.wait:
	   if (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");
             }
           }
        

Relationship to 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:
	    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";
            }
        

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread The thread to query. If thread is NULL, the current thread is used.
thread_state_ptrjint* On return, points to state flags, as defined by the Thread State Flags.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_NULL_POINTER thread_state_ptr is NULL.

Get All Threads

jvmtiError
GetAllThreads(jvmtiEnv* env,
            jint* threads_count_ptr,
            jthread** threads_ptr)
Get all live threads. The threads are Java programming language threads; that is, threads that are attached to the VM. A thread is live if 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.

Capabilities
Required Functionality

Parameters
Name Type Description
threads_count_ptrjint* On return, points to the number of running threads.

Agent passes a pointer to a jint. On return, the jint has been set.
threads_ptrjthread** On return, points to an array of references, one for each running thread.

Agent passes a pointer to a jthread*. On return, the jthread* points to a newly allocated array of size *threads_count_ptr. The array should be freed with Deallocate. The objects returned by threads_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER threads_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER threads_ptr is NULL.

Suspend Thread

jvmtiError
SuspendThread(jvmtiEnv* env,
            jthread thread)
Suspend the specified thread. If the calling thread is specified, this function will not return until some other thread calls 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_suspend Can suspend and resume threads

Parameters
Name Type Description
threadjthread The thread to suspend. If thread is NULL, the current thread is used.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_suspend. Use AddCapabilities.
JVMTI_ERROR_THREAD_SUSPENDED Thread already suspended.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).

Suspend Thread List

jvmtiError
SuspendThreadList(jvmtiEnv* env,
            jint request_count,
            const jthread* request_list,
            jvmtiError* results)
Suspend the 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_suspend Can suspend and resume threads

Parameters
Name Type Description
request_countjint The number of threads to suspend.
request_listconst jthread* The list of threads to suspend.

Agent passes in an array of request_count elements of jthread.
resultsjvmtiError* An agent supplied array of request_count elements. On return, filled with the error code for the suspend of the corresponding thread. The error code will be JVMTI_ERROR_NONE if the thread was suspended by this call. Possible error codes are those specified for SuspendThread.

Agent passes an array large enough to hold request_count elements of jvmtiError. The incoming values of the elements of the array are ignored. On return, the elements are set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_suspend. Use AddCapabilities.
JVMTI_ERROR_ILLEGAL_ARGUMENT request_count is less than 0.
JVMTI_ERROR_NULL_POINTER request_list is NULL.
JVMTI_ERROR_NULL_POINTER results is NULL.

Resume Thread

jvmtiError
ResumeThread(jvmtiEnv* env,
            jthread thread)
Resume a suspended thread. Any threads currently suspended through a JVM TI suspend function (eg. SuspendThread) or java.lang.Thread.suspend() will resume execution; all other threads are unaffected.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_suspend Can suspend and resume threads

Parameters
Name Type Description
threadjthread The thread to resume.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_suspend. Use AddCapabilities.
JVMTI_ERROR_THREAD_NOT_SUSPENDED Thread was not suspended.
JVMTI_ERROR_INVALID_TYPESTATE The state of the thread has been modified, and is now inconsistent.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).

Resume Thread List

jvmtiError
ResumeThreadList(jvmtiEnv* env,
            jint request_count,
            const jthread* request_list,
            jvmtiError* results)
Resume the request_count threads specified in the request_list array. Any thread suspended through a JVM TI suspend function (eg. SuspendThreadList) or java.lang.Thread.suspend() will resume execution.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_suspend Can suspend and resume threads

Parameters
Name Type Description
request_countjint The number of threads to resume.
request_listconst jthread* The threads to resume.

Agent passes in an array of request_count elements of jthread.
resultsjvmtiError* An agent supplied array of request_count elements. On return, filled with the error code for the resume of the corresponding thread. The error code will be JVMTI_ERROR_NONE if the thread was suspended by this call. Possible error codes are those specified for ResumeThread.

Agent passes an array large enough to hold request_count elements of jvmtiError. The incoming values of the elements of the array are ignored. On return, the elements are set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_suspend. Use AddCapabilities.
JVMTI_ERROR_ILLEGAL_ARGUMENT request_count is less than 0.
JVMTI_ERROR_NULL_POINTER request_list is NULL.
JVMTI_ERROR_NULL_POINTER results is NULL.

Stop Thread

jvmtiError
StopThread(jvmtiEnv* env,
            jthread thread,
            jobject exception)
Send the specified asynchronous exception to the specified thread (similar to 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_signal_thread Can send stop or interrupt to threads

Parameters
Name Type Description
threadjthread The thread to stop.
exceptionjobject The asynchronous exception object.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_signal_thread. Use AddCapabilities.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_INVALID_OBJECT exception is not an object.

Interrupt Thread

jvmtiError
InterruptThread(jvmtiEnv* env,
            jthread thread)
Interrupt the specified thread (similar to java.lang.Thread.interrupt).

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_signal_thread Can send stop or interrupt to threads

Parameters
Name Type Description
threadjthread The thread to interrupt.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_signal_thread. Use AddCapabilities.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).

Get Thread Info

typedef 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)
Get thread information. The fields of the jvmtiThreadInfo structure are filled in with details of the specified thread.

This function may only be called during the live phase.

Capabilities
Required Functionality

jvmtiThreadInfo - Thread information structure
Field Type Description
namechar* The thread name, encoded as a modified UTF-8 string.
priorityjint The thread priority. See the thread priority constants: jvmtiThreadPriority.
is_daemonjboolean Is this a daemon thread?
thread_groupjthreadGroup The thread group to which this thread belongs. NULL if the thread has died.
context_class_loaderjobject The context class loader associated with this thread.

Parameters
Name Type Description
threadjthread The thread to query. If thread is NULL, the current thread is used.
info_ptrjvmtiThreadInfo* On return, filled with information describing the specified thread.

For JDK 1.1 implementations that don't recognize context class loaders, the context_class_loader field will be NULL.

Agent passes a pointer to a jvmtiThreadInfo. On return, the jvmtiThreadInfo has been set. The pointer returned in the field name of jvmtiThreadInfo is a newly allocated array. The array should be freed with Deallocate. The object returned in the field thread_group of jvmtiThreadInfo is a JNI local reference and must be managed. The object returned in the field context_class_loader of jvmtiThreadInfo is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_NULL_POINTER info_ptr is NULL.

Get Owned Monitor Info

jvmtiError
GetOwnedMonitorInfo(jvmtiEnv* env,
            jthread thread,
            jint* owned_monitor_count_ptr,
            jobject** owned_monitors_ptr)
Get information about the monitors owned by the specified thread.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_owned_monitor_info Can get information about ownership of monitors - GetOwnedMonitorInfo

Parameters
Name Type Description
threadjthread The thread to query. If thread is NULL, the current thread is used.
owned_monitor_count_ptrjint* The number of monitors returned.

Agent passes a pointer to a jint. On return, the jint has been set.
owned_monitors_ptrjobject** The array of owned monitors.

Agent passes a pointer to a jobject*. On return, the jobject* points to a newly allocated array of size *owned_monitor_count_ptr. The array should be freed with Deallocate. The objects returned by owned_monitors_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_owned_monitor_info. Use AddCapabilities.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_NULL_POINTER owned_monitor_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER owned_monitors_ptr is NULL.

Get Current Contended Monitor

jvmtiError
GetCurrentContendedMonitor(jvmtiEnv* env,
            jthread thread,
            jobject* monitor_ptr)
Get the object, if any, whose monitor the specified thread is waiting to enter or waiting to regain through java.lang.Object.wait.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_current_contended_monitor Can GetCurrentContendedMonitor

Parameters
Name Type Description
threadjthread The thread to query. If thread is NULL, the current thread is used.
monitor_ptrjobject* On return, filled with the current contended monitor, or NULL if there is none.

Agent passes a pointer to a jobject. On return, the jobject has been set. The object returned by monitor_ptr is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_current_contended_monitor. Use AddCapabilities.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_NULL_POINTER monitor_ptr is NULL.

Agent Start Function

typedef void (JNICALL *jvmtiStartFunction)
    (jvmtiEnv* jvmti_env, 
     JNIEnv* jni_env, 
     void* arg);
Agent supplied callback function. This function is the entry point for an agent thread started with RunAgentThread.

Parameters
Name Type Description
jvmti_env jvmtiEnv * The JVM TI environment.
jni_env JNIEnv * The JNI environment.
arg void * The arg parameter passed to RunAgentThread.

Run Agent Thread

jvmtiError
RunAgentThread(jvmtiEnv* env,
            jthread thread,
            jvmtiStartFunction proc,
            const void* arg,
            jint priority)
Starts the execution of an agent thread. with the specified native function. The parameter 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 of java.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:
Thread Priority Constants
Constant Value Description
JVMTI_THREAD_MIN_PRIORITY1 Minimum possible thread priority
JVMTI_THREAD_NORM_PRIORITY5 Normal thread priority
JVMTI_THREAD_MAX_PRIORITY10 Maximum possible thread priority

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.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread The thread to run.
proc jvmtiStartFunction The start function.

argconst void * The argument to the start function.

Agent passes in an array. If arg is NULL, NULL is passed to the start function.
priorityjint The priority of the started thread. Any thread priority allowed by java.lang.Thread.setPriority can be used including those in jvmtiThreadPriority.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_PRIORITY priority is less than JVMTI_THREAD_MIN_PRIORITY or greater than JVMTI_THREAD_MAX_PRIORITY
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_NULL_POINTER proc is NULL.

Set Thread Local Storage

jvmtiError
SetThreadLocalStorage(jvmtiEnv* env,
            jthread thread,
            const void* data)
The VM stores a pointer value associated with each environment-thread pair. This pointer value is called thread-local storage. This value is 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.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread Store to this thread. If thread is NULL, the current thread is used.
dataconst void * The value to be entered into the thread-local storage.

Agent passes in an array. If data is NULL, value is set to NULL.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).

Get Thread Local Storage

jvmtiError
GetThreadLocalStorage(jvmtiEnv* env,
            jthread thread,
            void** data_ptr)
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.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread Retrieve from this thread. If thread is NULL, the current thread is used.
data_ptrvoid** Pointer through which the value of the thread local storage is returned. If thread-local storage has not been set with SetThreadLocalStorage the returned pointer is NULL.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_NULL_POINTER data_ptr is NULL.


Thread Group

Thread Group functions: Thread Group types:


Get Top Thread Groups

jvmtiError
GetTopThreadGroups(jvmtiEnv* env,
            jint* group_count_ptr,
            jthreadGroup** groups_ptr)
Return all top-level (parentless) thread groups in the VM.

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
group_count_ptrjint* On return, points to the number of top-level thread groups.

Agent passes a pointer to a jint. On return, the jint has been set.
groups_ptrjthreadGroup** On return, refers to a pointer to the top-level thread group array.

Agent passes a pointer to a jthreadGroup*. On return, the jthreadGroup* points to a newly allocated array of size *group_count_ptr. The array should be freed with Deallocate. The objects returned by groups_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER group_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER groups_ptr is NULL.

Get Thread Group Info

typedef struct {
    jthreadGroup parent;
    char* name;
    jint max_priority;
    jboolean is_daemon;
} jvmtiThreadGroupInfo;
jvmtiError
GetThreadGroupInfo(jvmtiEnv* env,
            jthreadGroup group,
            jvmtiThreadGroupInfo* info_ptr)
Get information about the thread group. The fields of the jvmtiThreadGroupInfo structure are filled in with details of the specified thread group.

This function may only be called during the live phase.

Capabilities
Required Functionality

jvmtiThreadGroupInfo - Thread group information structure
Field Type Description
parentjthreadGroup The parent thread group.
namechar* The thread group's name, encoded as a modified UTF-8 string.
max_priorityjint The maximum priority for this thread group.
is_daemonjboolean Is this a daemon thread group?

Parameters
Name Type Description
groupjthreadGroup The thread group to query.
info_ptrjvmtiThreadGroupInfo* On return, filled with information describing the specified thread group.

Agent passes a pointer to a jvmtiThreadGroupInfo. On return, the jvmtiThreadGroupInfo has been set. The object returned in the field parent of jvmtiThreadGroupInfo is a JNI local reference and must be managed. The pointer returned in the field name of jvmtiThreadGroupInfo is a newly allocated array. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD_GROUP group is not a thread group object.
JVMTI_ERROR_NULL_POINTER info_ptr is NULL.

Get Thread Group Children

jvmtiError
GetThreadGroupChildren(jvmtiEnv* env,
            jthreadGroup group,
            jint* thread_count_ptr,
            jthread** threads_ptr,
            jint* group_count_ptr,
            jthreadGroup** groups_ptr)
Get the live threads and active subgroups in this thread group.

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
groupjthreadGroup The group to query.
thread_count_ptrjint* On return, points to the number of live threads in this thread group.

Agent passes a pointer to a jint. On return, the jint has been set.
threads_ptrjthread** On return, points to an array of the live threads in this thread group.

Agent passes a pointer to a jthread*. On return, the jthread* points to a newly allocated array of size *thread_count_ptr. The array should be freed with Deallocate. The objects returned by threads_ptr are JNI local references and must be managed.
group_count_ptrjint* On return, points to the number of active child thread groups

Agent passes a pointer to a jint. On return, the jint has been set.
groups_ptrjthreadGroup** On return, points to an array of the active child thread groups.

Agent passes a pointer to a jthreadGroup*. On return, the jthreadGroup* points to a newly allocated array of size *group_count_ptr. The array should be freed with Deallocate. The objects returned by groups_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD_GROUP group is not a thread group object.
JVMTI_ERROR_NULL_POINTER thread_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER threads_ptr is NULL.
JVMTI_ERROR_NULL_POINTER group_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER groups_ptr is NULL.


Stack Frame

Stack Frame functions: Stack Frame types: These functions provide information about the stack of a thread. Stack frames are referenced by depth. The frame at depth zero is the current frame.

The frames are as described in the Java Virtual Machine Specification, Section 3.6 Frames. That is, they correspond to method invocations (including native methods) but do not correspond to platform native or VM internal frames. Information about a frame is returned in this 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
methodjmethodID The method executing in this frame.
locationjlocation 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
threadjthread On return, the thread traced.
statejint On return, the thread state. See GetThreadState.
frame_buffer jvmtiFrameInfo * On return, this agent allocated buffer is filled with stack frame information.
frame_countjint On return, the number of records filled into frame_buffer. This will be min(max_frame_count, stackDepth).


Get Stack Trace

jvmtiError
GetStackTrace(jvmtiEnv* env,
            jthread thread,
            jint start_depth,
            jint max_frame_count,
            jvmtiFrameInfo* frame_buffer,
            jint* count_ptr)
Get information about the stack of a thread. If 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.
jvmtiFrameInfo 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);
   }
}
        

The 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.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread Fetch the stack trace of this thread. If thread is NULL, the current thread is used.
start_depthjint Begin retrieving frames at this depth. If non-negative, count from the current frame, the first frame retrieved is at depth start_depth. For example, if zero, start from the current frame; if one, start from the caller of the current frame; if two, start from the caller of the caller of the current frame; and so on. If negative, count from below the oldest frame, the first frame retrieved is at depth stackDepth + start_depth, where stackDepth is the count of frames on the stack. For example, if negative one, only the oldest frame is retrieved; if negative two, start from the frame called by the oldest frame.
max_frame_countjint The maximum number of jvmtiFrameInfo records to retrieve.
frame_buffer jvmtiFrameInfo * On return, this agent allocated buffer is filled with stack frame information.

Agent passes an array large enough to hold max_frame_count elements of jvmtiFrameInfo. The incoming values of the elements of the array are ignored. On return, *count_ptr of the elements are set.
count_ptrjint* On return, points to the number of records filled in. For non-negative start_depth, this will be min(max_frame_count, stackDepth - start_depth). For negative start_depth, this will be min(max_frame_count, -start_depth).

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_ILLEGAL_ARGUMENT start_depth is greater than or equal to stackDepth or start_depth is less than -stackDepth.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT max_frame_count is less than 0.
JVMTI_ERROR_NULL_POINTER frame_buffer is NULL.
JVMTI_ERROR_NULL_POINTER count_ptr is NULL.

Get All Stack Traces

jvmtiError
GetAllStackTraces(jvmtiEnv* env,
            jint max_frame_count,
            jvmtiStackInfo** stack_info_ptr,
            jint* thread_count_ptr)
Get information about the stacks of all live threads (including agent threads). If 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.
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); 
        

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
max_frame_countjint The maximum number of jvmtiFrameInfo records to retrieve per thread.
stack_info_ptr jvmtiStackInfo ** On return, this buffer is filled with stack information for each thread. The number of jvmtiStackInfo records is determined by thread_count_ptr.

Note that this buffer is allocated to include the jvmtiFrameInfo buffers pointed to by jvmtiStackInfo.frame_buffer. These buffers must not be separately deallocated.

Agent passes a pointer to a jvmtiStackInfo*. On return, the jvmtiStackInfo* points to a newly allocated array. The array should be freed with Deallocate. The objects returned in the field thread of jvmtiStackInfo are JNI local references and must be managed.
thread_count_ptrjint* The number of threads traced.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_ILLEGAL_ARGUMENT max_frame_count is less than 0.
JVMTI_ERROR_NULL_POINTER stack_info_ptr is NULL.
JVMTI_ERROR_NULL_POINTER thread_count_ptr is NULL.

Get Thread List Stack Traces

jvmtiError
GetThreadListStackTraces(jvmtiEnv* env,
            jint thread_count,
            const jthread* thread_list,
            jint max_frame_count,
            jvmtiStackInfo** stack_info_ptr)
Get information about the stacks of the supplied threads. If 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.

Capabilities
Required Functionality

Parameters
Name Type Description
thread_countjint The number of threads to trace.
thread_listconst jthread* The list of threads to trace.

Agent passes in an array of thread_count elements of jthread.
max_frame_countjint The maximum number of jvmtiFrameInfo records to retrieve per thread.
stack_info_ptr jvmtiStackInfo ** On return, this buffer is filled with stack information for each thread. The number of jvmtiStackInfo records is determined by thread_count.

Note that this buffer is allocated to include the jvmtiFrameInfo buffers pointed to by jvmtiStackInfo.frame_buffer. These buffers must not be separately deallocated.

Agent passes a pointer to a jvmtiStackInfo*. On return, the jvmtiStackInfo* points to a newly allocated array of size *thread_count. The array should be freed with Deallocate. The objects returned in the field thread of jvmtiStackInfo are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_ILLEGAL_ARGUMENT thread_count is less than 0.
JVMTI_ERROR_NULL_POINTER thread_list is NULL.
JVMTI_ERROR_ILLEGAL_ARGUMENT max_frame_count is less than 0.
JVMTI_ERROR_NULL_POINTER stack_info_ptr is NULL.

Get Frame Count

jvmtiError
GetFrameCount(jvmtiEnv* env,
            jthread thread,
            jint* count_ptr)
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.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread The thread to query. If thread is NULL, the current thread is used.
count_ptrjint* On return, points to the number of frames in the call stack.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_NULL_POINTER count_ptr is NULL.

Pop Frame

jvmtiError
PopFrame(jvmtiEnv* env,
            jthread thread)
Pop the topmost stack frame of 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 Specification terminology):
  • the current frame is discarded as the previous frame becomes the current one
  • the operand stack is restored--the argument values are added back and if the invoke was not invokestatic, objectref is added back as well
  • the Java virtual machine PC is restored to the opcode of the invoke instruction
Note however, that any changes to the arguments, which occurred in the called method, remain; when execution continues, the first instruction to execute will be the invoke.

Between calling PopFrame and resuming the thread the state of the stack is undefined. To pop frames beyond the first, these three steps must be repeated:
  • suspend the thread via an event (step, breakpoint, ...)
  • call PopFrame
  • resume the thread

Locks acquired by a popped frame are released when it is popped. This applies to synchronized methods that are popped, and to any synchronized blocks within them, but does not apply to native locks.

Finally blocks are not executed.

Changes to global state are not addressed and thus remain changed.

The specified thread must not be the current thread and must be suspended.

Both the called method and calling method must be non-native Java programming language methods.

No JVM TI events are generated by this function.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_pop_frame Can pop frames off the stack - PopFrame

Parameters
Name Type Description
threadjthread The thread whose top frame is to be popped.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_pop_frame. Use AddCapabilities.
JVMTI_ERROR_OPAQUE_FRAME Attempted to pop a frame corresponding to a native method or a frame that the implementation is unable to pop.
JVMTI_ERROR_THREAD_NOT_SUSPENDED Thread was not suspended or current thread.
JVMTI_ERROR_NO_MORE_FRAMES There are no more Java programming language frames on the call stack. Or, the thread is the current thread.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).

Get Frame Location

jvmtiError
GetFrameLocation(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jmethodID* method_ptr,
            jlocation* location_ptr)

For a Java programming language frame, return the location of the instruction currently executing.

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
threadjthread The thread of the frame to query. If thread is NULL, the current thread is used.
depthjint The depth of the frame to query.
method_ptrjmethodID* On return, points to the method for the current location.

Agent passes a pointer to a jmethodID. On return, the jmethodID has been set.
location_ptrjlocation* On return, points to the index of the currently executing instruction. Is set to -1 if the frame is executing a native method.

Agent passes a pointer to a jlocation. On return, the jlocation has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER method_ptr is NULL.
JVMTI_ERROR_NULL_POINTER location_ptr is NULL.

Notify Frame Pop

jvmtiError
NotifyFramePop(jvmtiEnv* env,
            jthread thread,
            jint depth)
When the frame that is currently at 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_frame_pop_events Can set and thus get FramePop events

Parameters
Name Type Description
threadjthread The thread of the frame for which the frame pop event will be generated. If thread is NULL, the current thread is used.
depthjint The depth of the frame for which the frame pop event will be generated.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_frame_pop_events. Use AddCapabilities.
JVMTI_ERROR_OPAQUE_FRAME The frame at depth is executing a native method.
JVMTI_ERROR_THREAD_NOT_SUSPENDED Thread was not suspended and was not the current thread.
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.


Heap

Heap functions: Heap function types: These functions are used to analyze the heap. Functionality includes the ability to view the objects in the heap and to tag these objects.

A tag is a value associated with an object. Tags are explicitly set by the agent using the 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_TAGGED1 Tagged objects only.
JVMTI_HEAP_OBJECT_UNTAGGED2 Untagged objects only.
JVMTI_HEAP_OBJECT_EITHER3 Either tagged or untagged objects.
Heap Root Kind Enumeration (jvmtiHeapRootKind)
Constant Value Description
JVMTI_HEAP_ROOT_JNI_GLOBAL1 JNI global reference.
JVMTI_HEAP_ROOT_SYSTEM_CLASS2 System class.
JVMTI_HEAP_ROOT_MONITOR3 Monitor.
JVMTI_HEAP_ROOT_STACK_LOCAL4 Stack local.
JVMTI_HEAP_ROOT_JNI_LOCAL5 JNI local reference.
JVMTI_HEAP_ROOT_THREAD6 Thread.
JVMTI_HEAP_ROOT_OTHER7 Other.
Object Reference Enumeration (jvmtiObjectReferenceKind)
Constant Value Description
JVMTI_REFERENCE_CLASS1 Reference from an object to its class.
JVMTI_REFERENCE_FIELD2 Reference from an object to the value of one of its instance fields. For references of this kind the referrer_index parameter to the jvmtiObjectReferenceCallback 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 (see GetClassFields), with the total number of fields (both public and private) declared in all superclasses and superinterfaces. The index starts at zero.
JVMTI_REFERENCE_ARRAY_ELEMENT3 Reference from an array to one of its elements. For references of this kind the referrer_index parameter to the jvmtiObjectReferenceCallback is the array index.
JVMTI_REFERENCE_CLASS_LOADER4 Reference from a class to its class loader.
JVMTI_REFERENCE_SIGNERS5 Reference from a class to its signers array.
JVMTI_REFERENCE_PROTECTION_DOMAIN6 Reference from a class to its protection domain.
JVMTI_REFERENCE_INTERFACE7 Reference from a class to one of its interfaces.
JVMTI_REFERENCE_STATIC_FIELD8 Reference from a class to the value of one of its static fields. For references of this kind the referrer_index parameter to the jvmtiObjectReferenceCallback 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. See GetClassFields.
JVMTI_REFERENCE_CONSTANT_POOL9 Reference from a class to a resolved entry in the constant pool. For references of this kind the referrer_index parameter to the jvmtiObjectReferenceCallback 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_CONTINUE1 Continue the iteration. If this is a reference iteration, follow the references of this object.
JVMTI_ITERATION_IGNORE2 Continue the iteration. If this is a reference iteration, ignore the references of this object.
JVMTI_ITERATION_ABORT0 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

jvmtiError
GetTag(jvmtiEnv* env,
            jobject object,
            jlong* tag_ptr)
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 with 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
objectjobject The object whose tag is to be retrieved.
tag_ptrjlong* On return, the referenced long is set to the value of the tag.

Agent passes a pointer to a jlong. On return, the jlong has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_INVALID_OBJECT object is not an object.
JVMTI_ERROR_NULL_POINTER tag_ptr is NULL.

Set Tag

jvmtiError
SetTag(jvmtiEnv* env,
            jobject object,
            jlong 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 with GetTag.

This function may only be called during the start or the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
objectjobject The object whose tag is to be set.
tagjlong The new value of the tag.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_INVALID_OBJECT object is not an object.

Force Garbage Collection

jvmtiError
ForceGarbageCollection(jvmtiEnv* env)
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 all 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.

Capabilities
Required Functionality

Parameters
Name Type Description

Errors
This function returns a universal error

Heap Object Callback

typedef jvmtiIterationControl (JNICALL *jvmtiHeapObjectCallback)
    (jlong class_tag, 
     jlong size, 
     jlong* tag_ptr, 
     void* user_data);
Agent supplied callback function. Describes (but does not pass in) an object in the heap.

Return value should be JVMTI_ITERATION_CONTINUE to continue iteration, 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.

Parameters
Name Type Description
class_tagjlong The tag of the class of object (zero if the class is not tagged). If the object represents a runtime class, the class_tag is the tag associated with java.lang.Class (zero if java.lang.Class is not tagged).
sizejlong Size of the object (in bytes). See GetObjectSize.
tag_ptrjlong* The object tag value, or zero if the object is not tagged. To set the tag value to be associated with the object the agent sets the jlong pointed to by the parameter.
user_datavoid* The user supplied data that was passed into the iteration function.

Heap Root Object Callback

typedef jvmtiIterationControl (JNICALL *jvmtiHeapRootCallback)
    (jvmtiHeapRootKind root_kind, 
     jlong class_tag, 
     jlong size, 
     jlong* tag_ptr, 
     void* user_data);
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 be 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.

Parameters
Name Type Description
root_kindjvmtiHeapRootKind The kind of heap root.
class_tagjlong The tag of the class of object (zero if the class is not tagged). If the object represents a runtime class, the class_tag is the tag associated with java.lang.Class (zero if java.lang.Class is not tagged).
sizejlong Size of the object (in bytes). See GetObjectSize.
tag_ptrjlong* The object tag value, or zero if the object is not tagged. To set the tag value to be associated with the object the agent sets the jlong pointed to by the parameter.
user_datavoid* The user supplied data that was passed into the iteration function.

Stack Reference Object Callback

typedef 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);
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 be 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.

Parameters
Name Type Description
root_kindjvmtiHeapRootKind The kind of root (either JVMTI_HEAP_ROOT_STACK_LOCAL or JVMTI_HEAP_ROOT_JNI_LOCAL).
class_tagjlong The tag of the class of object (zero if the class is not tagged). If the object represents a runtime class, the class_tag is the tag associated with java.lang.Class (zero if java.lang.Class is not tagged).
sizejlong Size of the object (in bytes). See GetObjectSize.
tag_ptrjlong* The object tag value, or zero if the object is not tagged. To set the tag value to be associated with the object the agent sets the jlong pointed to by the parameter.
thread_tagjlong The tag of the thread corresponding to this stack, zero if not tagged.
depthjint The depth of the frame.
methodjmethodID The method executing in this frame.
slotjint The slot number.
user_datavoid* The user supplied data that was passed into the iteration function.

Object Reference Callback

typedef jvmtiIterationControl (JNICALL *jvmtiObjectReferenceCallback)
    (jvmtiObjectReferenceKind reference_kind, 
     jlong class_tag, 
     jlong size, 
     jlong* tag_ptr, 
     jlong referrer_tag, 
     jint referrer_index, 
     void* user_data);
Agent supplied callback function. Describes a reference from an object (the referrer) to another object (the referree).

Return value should be 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.

Parameters
Name Type Description
reference_kindjvmtiObjectReferenceKind The type of reference.
class_tagjlong The tag of the class of referree object (zero if the class is not tagged). If the referree object represents a runtime class, the class_tag is the tag associated with java.lang.Class (zero if java.lang.Class is not tagged).
sizejlong Size of the referree object (in bytes). See GetObjectSize.
tag_ptrjlong* The referree object tag value, or zero if the object is not tagged. To set the tag value to be associated with the object the agent sets the jlong pointed to by the parameter.
referrer_tagjlong The tag of the referrer object, or zero if the referrer object is not tagged.
referrer_indexjint For references of type JVMTI_REFERENCE_FIELD the index of the field in the referrer object. The index is based on the order of all the object's fields - see JVMTI_REFERENCE_FIELD for further description.

For references of type JVMTI_REFERENCE_STATIC_FIELD the index of the static field. The index is based on the order of the directly declared fields in the class - see JVMTI_REFERENCE_STATIC_FIELD for further description.

For references of type JVMTI_REFERENCE_ARRAY_ELEMENT the array index - see JVMTI_REFERENCE_ARRAY_ELEMENT for further description.

For references of type JVMTI_REFERENCE_CONSTANT_POOL the index into the constant pool of the class - see JVMTI_REFERENCE_CONSTANT_POOL for further description.

For references of other kinds the referrer_index is -1.
user_datavoid* The user supplied data that was passed into the iteration function.

Iterate Over Objects Reachable From Object

jvmtiError
IterateOverObjectsReachableFromObject(jvmtiEnv* env,
            jobject object,
            jvmtiObjectReferenceCallback object_reference_callback,
            void* user_data)
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 the jvmtiObjectReferenceCallback.reference_kind and jvmtiObjectReferenceCallback.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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
objectjobject The object
object_reference_callback jvmtiObjectReferenceCallback The callback to be called to describe each object reference.

user_data void * User supplied data to be passed to the callback.

Agent passes a pointer to a void. On return, the void has been set. If user_data is NULL, NULL is passed as the user supplied data.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_INVALID_OBJECT object is not an object.
JVMTI_ERROR_NULL_POINTER object_reference_callback is NULL.

Iterate Over Reachable Objects

jvmtiError
IterateOverReachableObjects(jvmtiEnv* env,
            jvmtiHeapRootCallback heap_root_callback,
            jvmtiStackReferenceCallback stack_ref_callback,
            jvmtiObjectReferenceCallback object_ref_callback,
            void* user_data)
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 the 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 and jvmtiObjectReferenceCallback.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 the object_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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
heap_root_callback jvmtiHeapRootCallback The callback function to be called for each heap root of type JVMTI_HEAP_ROOT_JNI_GLOBAL, JVMTI_HEAP_ROOT_SYSTEM_CLASS, JVMTI_HEAP_ROOT_MONITOR, JVMTI_HEAP_ROOT_THREAD, or JVMTI_HEAP_ROOT_OTHER.

If heap_root_callback is NULL, do not report heap roots.
stack_ref_callback jvmtiStackReferenceCallback The callback function to be called for each heap root of JVMTI_HEAP_ROOT_STACK_LOCAL or JVMTI_HEAP_ROOT_JNI_LOCAL.

If stack_ref_callback is NULL, do not report stack references.
object_ref_callback jvmtiObjectReferenceCallback The callback function to be called for each object reference.

If object_ref_callback is NULL, do not follow references from the root objects.
user_data void * User supplied data to be passed to the callback.

Agent passes a pointer to a void. On return, the void has been set. If user_data is NULL, NULL is passed as the user supplied data.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.

Iterate Over Heap

jvmtiError
IterateOverHeap(jvmtiEnv* env,
            jvmtiHeapObjectFilter object_filter,
            jvmtiHeapObjectCallback heap_object_callback,
            void* user_data)
Iterate over all objects in the heap. This includes both reachable and unreachable objects.

The 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
object_filterjvmtiHeapObjectFilter Indicates the objects for which the callback function is called.
heap_object_callback jvmtiHeapObjectCallback The iterator function to be called for each object in the heap.

If heap_object_callback is NULL, do not process objects which are not tagged.
user_data void * User supplied data to be passed to the callback.

Agent passes a pointer to a void. On return, the void has been set. If user_data is NULL, NULL is passed as the user supplied data.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_ILLEGAL_ARGUMENT object_filter is not a jvmtiHeapObjectFilter.

Iterate Over Instances Of Class

jvmtiError
IterateOverInstancesOfClass(jvmtiEnv* env,
            jclass klass,
            jvmtiHeapObjectFilter object_filter,
            jvmtiHeapObjectCallback heap_object_callback,
            void* user_data)
Iterate over all objects in the heap that are instances of the specified class. This includes both reachable and unreachable objects.

The 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
klassjclass Iterate over objects of this class only.
object_filterjvmtiHeapObjectFilter Indicates the objects for which the callback function is called.
heap_object_callback jvmtiHeapObjectCallback The iterator function to be called for each klass instance which does not have a tag.

If heap_object_callback is NULL, do not process objects which are not tagged.
user_data void * User supplied data to be passed to the callback.

Agent passes a pointer to a void. On return, the void has been set. If user_data is NULL, NULL is passed as the user supplied data.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_ILLEGAL_ARGUMENT object_filter is not a jvmtiHeapObjectFilter.

Get Objects With Tags

jvmtiError
GetObjectsWithTags(jvmtiEnv* env,
            jint tag_count,
            const jlong* tags,
            jint* count_ptr,
            jobject** object_result_ptr,
            jlong** tag_result_ptr)
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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_tag_objects Can set and get tags, as described in the Heap category.

Parameters
Name Type Description
tag_countjint Number of tags to scan for.
tagsconst jlong * Scan for objects with these tags. Zero is not permitted in this array.

Agent passes in an array of tag_count elements of jlong.
count_ptr jint * Return the number of objects with any of the tags in tags.

Agent passes a pointer to a jint. On return, the jint has been set.
object_result_ptr jobject ** Returns the array of objects with any of the tags in tags.

Agent passes a pointer to a jobject*. On return, the jobject* points to a newly allocated array of size *count_ptr. The array should be freed with Deallocate. If object_result_ptr is NULL, this information is not returned. The objects returned by object_result_ptr are JNI local references and must be managed.
tag_result_ptr jlong ** For each object in object_result_ptr, return the tag at the corresponding index.

Agent passes a pointer to a jlong*. On return, the jlong* points to a newly allocated array of size *count_ptr. The array should be freed with Deallocate. If tag_result_ptr is NULL, this information is not returned.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_tag_objects. Use AddCapabilities.
JVMTI_ERROR_ILLEGAL_ARGUMENT Zero is present in tags.
JVMTI_ERROR_ILLEGAL_ARGUMENT tag_count is less than 0.
JVMTI_ERROR_NULL_POINTER tags is NULL.
JVMTI_ERROR_NULL_POINTER count_ptr is NULL.


Local Variable

Local Variable functions: These functions are used to retrieve or set the value of a local variable. The variable is identified by the depth of the frame containing its value and the variable's slot number within that frame. The mapping of variables to slot numbers can be obtained with the function GetLocalVariableTable.


Get Local Variable - Object

jvmtiError
GetLocalObject(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jobject* value_ptr)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
value_ptrjobject* On return, points to the variable's value.

Agent passes a pointer to a jobject. On return, the jobject has been set. The object returned by value_ptr is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER value_ptr is NULL.

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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
value_ptrjint* On return, points to the variable's value.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER value_ptr is NULL.

Get Local Variable - Long

jvmtiError
GetLocalLong(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jlong* value_ptr)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
value_ptrjlong* On return, points to the variable's value.

Agent passes a pointer to a jlong. On return, the jlong has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER value_ptr is NULL.

Get Local Variable - Float

jvmtiError
GetLocalFloat(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jfloat* value_ptr)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
value_ptrjfloat* On return, points to the variable's value.

Agent passes a pointer to a jfloat. On return, the jfloat has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER value_ptr is NULL.

Get Local Variable - Double

jvmtiError
GetLocalDouble(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jdouble* value_ptr)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
value_ptrjdouble* On return, points to the variable's value.

Agent passes a pointer to a jdouble. On return, the jdouble has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_NULL_POINTER value_ptr is NULL.

Set Local Variable - Object

jvmtiError
SetLocalObject(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jobject value)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
valuejobject The new value for the variable.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.
JVMTI_ERROR_INVALID_OBJECT value is not an object.

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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
valuejint The new value for the variable.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.

Set Local Variable - Long

jvmtiError
SetLocalLong(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jlong value)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
valuejlong The new value for the variable.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.

Set Local Variable - Float

jvmtiError
SetLocalFloat(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jfloat value)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
valuejfloat The new value for the variable.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.

Set Local Variable - Double

jvmtiError
SetLocalDouble(jvmtiEnv* env,
            jthread thread,
            jint depth,
            jint slot,
            jdouble value)
This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

Parameters
Name Type Description
threadjthread The thread of the frame containing the variable's value. If thread is NULL, the current thread is used.
depthjint The depth of the frame containing the variable's value.
slotjint The variable's slot number.
valuejdouble The new value for the variable.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_INVALID_SLOT Invalid slot.
JVMTI_ERROR_TYPE_MISMATCH The variable is not an appropriate type for the function used.
JVMTI_ERROR_OPAQUE_FRAME Not a visible frame
JVMTI_ERROR_INVALID_THREAD thread is not a thread object.
JVMTI_ERROR_THREAD_NOT_ALIVE thread is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT depth is less than zero.
JVMTI_ERROR_NO_MORE_FRAMES There are no stack frames at the specified depth.


Breakpoint

Breakpoint functions:


Set Breakpoint

jvmtiError
SetBreakpoint(jvmtiEnv* env,
            jmethodID method,
            jlocation location)
Set a breakpoint at the instruction indicated by 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_breakpoint_events Can set and thus get Breakpoint events

Parameters
Name Type Description
methodjmethodID The method in which to set the breakpoint
locationjlocation the index of the instruction at which to set the breakpoint

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_breakpoint_events. Use AddCapabilities.
JVMTI_ERROR_DUPLICATE The designated bytecode already has a breakpoint.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_INVALID_LOCATION location is not a valid location.

Clear Breakpoint

jvmtiError
ClearBreakpoint(jvmtiEnv* env,
            jmethodID method,
            jlocation location)
Clear the breakpoint at the bytecode indicated by method and location.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_breakpoint_events Can set and thus get Breakpoint events

Parameters
Name Type Description
methodjmethodID The method in which to clear the breakpoint
locationjlocation the index of the instruction at which to clear the breakpoint

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_breakpoint_events. Use AddCapabilities.
JVMTI_ERROR_NOT_FOUND There's no breakpoint at the designated bytecode.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_INVALID_LOCATION location is not a valid location.


Watched Field

Watched Field functions:


Set Field Access Watch

jvmtiError
SetFieldAccessWatch(jvmtiEnv* env,
            jclass klass,
            jfieldID field)
Generate a 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_field_access_events Can set watchpoints on field access - SetFieldAccessWatch

Parameters
Name Type Description
klassjclass The class containing the field to watch
fieldjfieldID The field to watch

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_field_access_events. Use AddCapabilities.
JVMTI_ERROR_DUPLICATE The designated field is already being watched for accesses.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.

Clear Field Access Watch

jvmtiError
ClearFieldAccessWatch(jvmtiEnv* env,
            jclass klass,
            jfieldID field)
Cancel a field access watch previously set by SetFieldAccessWatch, on the field specified by klass and field.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_field_access_events Can set watchpoints on field access - SetFieldAccessWatch

Parameters
Name Type Description
klassjclass The class containing the field to watch
fieldjfieldID The field to watch

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_field_access_events. Use AddCapabilities.
JVMTI_ERROR_NOT_FOUND The designated field is not being watched for accesses.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.

Set Field Modification Watch

jvmtiError
SetFieldModificationWatch(jvmtiEnv* env,
            jclass klass,
            jfieldID field)
Generate a 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_field_modification_events Can set watchpoints on field modification - SetFieldModificationWatch

Parameters
Name Type Description
klassjclass The class containing the field to watch
fieldjfieldID The field to watch

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_field_modification_events. Use AddCapabilities.
JVMTI_ERROR_DUPLICATE The designated field is already being watched for modifications.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.

Clear Field Modification Watch

jvmtiError
ClearFieldModificationWatch(jvmtiEnv* env,
            jclass klass,
            jfieldID field)
Cancel a field modification watch previously set by SetFieldModificationWatch, on the field specified by klass and field.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_generate_field_modification_events Can set watchpoints on field modification - SetFieldModificationWatch

Parameters
Name Type Description
klassjclass The class containing the field to watch
fieldjfieldID The field to watch

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_generate_field_modification_events. Use AddCapabilities.
JVMTI_ERROR_NOT_FOUND The designated field is not being watched for modifications.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.


Class

Class functions: Class types:


Get Loaded Classes

jvmtiError
GetLoadedClasses(jvmtiEnv* env,
            jint* class_count_ptr,
            jclass** classes_ptr)
Return an array of all classes loaded in the virtual machine. The number of classes in the array is returned via 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.

Capabilities
Required Functionality

Parameters
Name Type Description
class_count_ptrjint* On return, points to the number of classes.

Agent passes a pointer to a jint. On return, the jint has been set.
classes_ptrjclass** On return, points to an array of references, one for each class.

Agent passes a pointer to a jclass*. On return, the jclass* points to a newly allocated array of size *class_count_ptr. The array should be freed with Deallocate. The objects returned by classes_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER class_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER classes_ptr is NULL.

Get Classloader Classes

jvmtiError
GetClassLoaderClasses(jvmtiEnv* env,
            jobject initiating_loader,
            jint* class_count_ptr,
            jclass** classes_ptr)
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 via class_count_ptr, and the array itself via classes_ptr.

This function may only be called during the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
initiating_loader jobject An initiating class loader.

If initiating_loader is NULL, the classes initiated by the bootstrap loader will be returned.
class_count_ptrjint* On return, points to the number of classes.

Agent passes a pointer to a jint. On return, the jint has been set.
classes_ptrjclass** On return, points to an array of references, one for each class.

Agent passes a pointer to a jclass*. On return, the jclass* points to a newly allocated array of size *class_count_ptr. The array should be freed with Deallocate. The objects returned by classes_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER class_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER classes_ptr is NULL.

Get Class Signature

jvmtiError
GetClassSignature(jvmtiEnv* env,
            jclass klass,
            char** signature_ptr,
            char** generic_ptr)
For the class indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
signature_ptr char ** On return, points to the JNI type signature of the class, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If signature_ptr is NULL, the signature is not returned.
generic_ptr char ** On return, points to the generic signature of the class, encoded as a modified UTF-8 string. If there is no generic signature attribute for the class, then, on return, points to NULL.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If generic_ptr is NULL, the generic signature is not returned.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.

Get Class Status

jvmtiError
GetClassStatus(jvmtiEnv* env,
            jclass klass,
            jint* status_ptr)
Get the status of the class. Zero or more of the following bits can be set.
Class Status Flags
Constant Value Description
JVMTI_CLASS_STATUS_VERIFIED1 Class bytecodes have been verified
JVMTI_CLASS_STATUS_PREPARED2 Class preparation is complete
JVMTI_CLASS_STATUS_INITIALIZED4 Class initialization is complete. Static initializer has been run.
JVMTI_CLASS_STATUS_ERROR8 Error during initialization makes class unusable
JVMTI_CLASS_STATUS_ARRAY16 Class is an array. If set, all other bits are zero.
JVMTI_CLASS_STATUS_PRIMITIVE32 Class is a primitive class (for example, java.lang.Integer.TYPE). If set, all other bits are zero.

This function may only be called during the start or the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
status_ptrjint* On return, points to the current state of this class as one or more of the class status flags.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER status_ptr is NULL.

Get Source File Name

jvmtiError
GetSourceFileName(jvmtiEnv* env,
            jclass klass,
            char** source_name_ptr)
For the class indicated by klass, return the source file name via source_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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_source_file_name Can get the source file name of a class

Parameters
Name Type Description
klassjclass The class to query.
source_name_ptrchar** On return, points to the class's source file name, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_source_file_name. Use AddCapabilities.
JVMTI_ERROR_ABSENT_INFORMATION Class information does not include a source file name. This includes cases where the class is an array class or primitive class.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER source_name_ptr is NULL.

Get Class Modifiers

jvmtiError
GetClassModifiers(jvmtiEnv* env,
            jclass klass,
            jint* modifiers_ptr)
For the class indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
modifiers_ptrjint* On return, points to the current access flags of this class.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER modifiers_ptr is NULL.

Get Class Methods

jvmtiError
GetClassMethods(jvmtiEnv* env,
            jclass klass,
            jint* method_count_ptr,
            jmethodID** methods_ptr)
For the class indicated by klass, return a count of methods via method_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.

Capabilities
Required Functionality
Optional Features
Capability Effect
can_maintain_original_method_order Can return methods in the order they occur in the class file

Parameters
Name Type Description
klassjclass The class to query.
method_count_ptrjint* On return, points to the number of methods declared in this class.

Agent passes a pointer to a jint. On return, the jint has been set.
methods_ptrjmethodID** On return, points to the method ID array.

Agent passes a pointer to a jmethodID*. On return, the jmethodID* points to a newly allocated array of size *method_count_ptr. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_CLASS_NOT_PREPARED klass is not prepared.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER method_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER methods_ptr is NULL.

Get Class Fields

jvmtiError
GetClassFields(jvmtiEnv* env,
            jclass klass,
            jint* field_count_ptr,
            jfieldID** fields_ptr)
For the class indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
field_count_ptrjint* On return, points to the number of fields declared in this class.

Agent passes a pointer to a jint. On return, the jint has been set.
fields_ptrjfieldID** On return, points to the field ID array.

Agent passes a pointer to a jfieldID*. On return, the jfieldID* points to a newly allocated array of size *field_count_ptr. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_CLASS_NOT_PREPARED klass is not prepared.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER field_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER fields_ptr is NULL.

Get Implemented Interfaces

jvmtiError
GetImplementedInterfaces(jvmtiEnv* env,
            jclass klass,
            jint* interface_count_ptr,
            jclass** interfaces_ptr)
Return the direct super-interfaces of this class. For a class, this function returns the interfaces declared in its 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
interface_count_ptrjint* On return, points to the number of interfaces.

Agent passes a pointer to a jint. On return, the jint has been set.
interfaces_ptrjclass** On return, points to the interface array.

Agent passes a pointer to a jclass*. On return, the jclass* points to a newly allocated array of size *interface_count_ptr. The array should be freed with Deallocate. The objects returned by interfaces_ptr are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_CLASS_NOT_PREPARED klass is not prepared.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER interface_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER interfaces_ptr is NULL.

Is Interface

jvmtiError
IsInterface(jvmtiEnv* env,
            jclass klass,
            jboolean* is_interface_ptr)
Determines whether a class object reference represents an interface. The 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
is_interface_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER is_interface_ptr is NULL.

Is Array Class

jvmtiError
IsArrayClass(jvmtiEnv* env,
            jclass klass,
            jboolean* is_array_class_ptr)
Determines whether a class object reference represents an array. The 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
is_array_class_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER is_array_class_ptr is NULL.

Get Class Loader

jvmtiError
GetClassLoader(jvmtiEnv* env,
            jclass klass,
            jobject* classloader_ptr)
For the class indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
classloader_ptrjobject* On return, points to the class loader that loaded this class. If the class was not created by a class loader or if the class loader is the bootstrap class loader, points to NULL.

Agent passes a pointer to a jobject. On return, the jobject has been set. The object returned by classloader_ptr is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER classloader_ptr is NULL.

Get Source Debug Extension

jvmtiError
GetSourceDebugExtension(jvmtiEnv* env,
            jclass klass,
            char** source_debug_extension_ptr)
For the class indicated by klass, return the debug extension via source_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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_source_debug_extension Can get the source debug extension of a class

Parameters
Name Type Description
klassjclass The class to query.
source_debug_extension_ptrchar** On return, points to the class's debug extension, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_source_debug_extension. Use AddCapabilities.
JVMTI_ERROR_ABSENT_INFORMATION Class information does not include a debug extension.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_NULL_POINTER source_debug_extension_ptr is NULL.

Redefine Classes

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)
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:
  • their bytecodes are the same except for indices into the constant pool and
  • the referenced constants are equal.
An original method version which is not equivalent to the new method version is called obsolete and is assigned a new methid ID; the original method ID now refers to the new method version. A method ID can be tested for obsolescence with 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
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.
Optional Features
can_redefine_any_class RedefineClasses can be called on any class (can_redefine_classes must also be set)

jvmtiClassDefinition - Class redefinition description
Field Type Description
klassjclass Class object for this class
class_byte_countjint Number of bytes defining class (below)
class_bytesconst unsigned char* Bytes defining class (in Class File Format of the Java Virtual Machine Specification)

Parameters
Name Type Description
class_countjint The number of classes specified in class_definitions
class_definitionsconst jvmtiClassDefinition* The array of new class definitions

Agent passes in an array of class_count elements of jvmtiClassDefinition.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_redefine_classes. Use AddCapabilities.
JVMTI_ERROR_NULL_POINTER One of class_bytes is NULL.
JVMTI_ERROR_UNMODIFIABLE_CLASS An element of class_definitions cannot be modified.
JVMTI_ERROR_INVALID_CLASS An element of class_definitions is not a valid class.
JVMTI_ERROR_UNSUPPORTED_VERSION A new class file has a version number not supported by this VM.
JVMTI_ERROR_INVALID_CLASS_FORMAT A new class file is malformed (The VM would return a ClassFormatError).
JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION The new class file definitions would lead to a circular definition (the VM would return a ClassCircularityError).
JVMTI_ERROR_FAILS_VERIFICATION The class bytes fail verification.
JVMTI_ERROR_NAMES_DONT_MATCH The class name defined in a new class file is different from the name in the old class object.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED A new class file would require adding a method.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED A new class version changes a field.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED A direct superclass is different for a new class version, or the set of directly implemented interfaces is different.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED A new class version does not declare a method declared in the old class version.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED A new class version has different modifiers.
JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED A method in the new class version has different modifiers than its counterpart in the old class version.
JVMTI_ERROR_ILLEGAL_ARGUMENT class_count is less than 0.
JVMTI_ERROR_NULL_POINTER class_definitions is NULL.


Object

Object functions: Object types:


Get Object Size

jvmtiError
GetObjectSize(jvmtiEnv* env,
            jobject object,
            jlong* size_ptr)
For the object indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
objectjobject The object to query.
size_ptrjlong* On return, points to the object's size in bytes.

Agent passes a pointer to a jlong. On return, the jlong has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_OBJECT object is not an object.
JVMTI_ERROR_NULL_POINTER size_ptr is NULL.

Get Object Hash Code

jvmtiError
GetObjectHashCode(jvmtiEnv* env,
            jobject object,
            jint* hash_code_ptr)
For the object indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
objectjobject The object to query.
hash_code_ptrjint* On return, points to the object's hash code.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_OBJECT object is not an object.
JVMTI_ERROR_NULL_POINTER hash_code_ptr is NULL.

Get Object Monitor Usage

typedef 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)
Get information about the object's monitor. The fields of the jvmtiMonitorUsage structure are filled in with information about usage of the monitor.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_monitor_info Can GetObjectMonitorUsage

jvmtiMonitorUsage - Object monitor usage information
Field Type Description
ownerjthread The thread owning this monitor, or NULL if unused
entry_countjint The number of times the owning thread has entered the monitor
waiter_countjint The number of threads waiting to own this monitor
waitersjthread* The waiter_count waiting threads
notify_waiter_countjint The number of threads waiting to be notified by this monitor
notify_waitersjthread* The notify_waiter_count threads waiting to be notified

Parameters
Name Type Description
objectjobject The object to query.
info_ptrjvmtiMonitorUsage* On return, filled with monitor information for the specified object.

Agent passes a pointer to a jvmtiMonitorUsage. On return, the jvmtiMonitorUsage has been set. The object returned in the field owner of jvmtiMonitorUsage is a JNI local reference and must be managed. The pointer returned in the field waiters of jvmtiMonitorUsage is a newly allocated array. The array should be freed with Deallocate. The objects returned in the field waiters of jvmtiMonitorUsage are JNI local references and must be managed. The pointer returned in the field notify_waiters of jvmtiMonitorUsage is a newly allocated array. The array should be freed with Deallocate. The objects returned in the field notify_waiters of jvmtiMonitorUsage are JNI local references and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_monitor_info. Use AddCapabilities.
JVMTI_ERROR_INVALID_OBJECT object is not an object.
JVMTI_ERROR_NULL_POINTER info_ptr is NULL.


Field

Field functions:


Get Field Name (and Signature)

jvmtiError
GetFieldName(jvmtiEnv* env,
            jclass klass,
            jfieldID field,
            char** name_ptr,
            char** signature_ptr,
            char** generic_ptr)
For the field indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class of the field to query.
fieldjfieldID The field to query.
name_ptr char ** On return, points to the field name, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If name_ptr is NULL, the name is not returned.
signature_ptr char ** On return, points to the field signature, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If signature_ptr is NULL, the signature is not returned.
generic_ptr char ** On return, points to the generic signature of the field, encoded as a modified UTF-8 string. If there is no generic signature attribute for the field, then, on return, points to NULL.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If generic_ptr is NULL, the generic signature is not returned.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.

Get Field Declaring Class

jvmtiError
GetFieldDeclaringClass(jvmtiEnv* env,
            jclass klass,
            jfieldID field,
            jclass* declaring_class_ptr)
For the field indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
fieldjfieldID The field to query.
declaring_class_ptrjclass* On return, points to the declaring class

Agent passes a pointer to a jclass. On return, the jclass has been set. The object returned by declaring_class_ptr is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.
JVMTI_ERROR_NULL_POINTER declaring_class_ptr is NULL.

Get Field Modifiers

jvmtiError
GetFieldModifiers(jvmtiEnv* env,
            jclass klass,
            jfieldID field,
            jint* modifiers_ptr)
For the field indicated by klass and field 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.

Capabilities
Required Functionality

Parameters
Name Type Description
klassjclass The class to query.
fieldjfieldID The field to query.
modifiers_ptrjint* On return, points to the access flags.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.
JVMTI_ERROR_NULL_POINTER modifiers_ptr is NULL.

Is Field Synthetic

jvmtiError
IsFieldSynthetic(jvmtiEnv* env,
            jclass klass,
            jfieldID field,
            jboolean* is_synthetic_ptr)
For the field indicated by 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_synthetic_attribute Can test if a field or method is synthetic - IsFieldSynthetic and IsMethodSynthetic

Parameters
Name Type Description
klassjclass The class of the field to query.
fieldjfieldID The field to query.
is_synthetic_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_synthetic_attribute. Use AddCapabilities.
JVMTI_ERROR_INVALID_CLASS klass is not a class object or the class has been unloaded.
JVMTI_ERROR_INVALID_FIELDID field is not a jfieldID.
JVMTI_ERROR_NULL_POINTER is_synthetic_ptr is NULL.


Method

Method functions: Method types:


Get Method Name (and Signature)

jvmtiError
GetMethodName(jvmtiEnv* env,
            jmethodID method,
            char** name_ptr,
            char** signature_ptr,
            char** generic_ptr)
For the method indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
name_ptr char ** On return, points to the method name, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If name_ptr is NULL, the name is not returned.
signature_ptr char ** On return, points to the method signature, encoded as a modified UTF-8 string.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If signature_ptr is NULL, the signature is not returned.
generic_ptr char ** On return, points to the generic signature of the method, encoded as a modified UTF-8 string. If there is no generic signature attribute for the method, then, on return, points to NULL.

Agent passes a pointer to a char*. On return, the char* points to a newly allocated array. The array should be freed with Deallocate. If generic_ptr is NULL, the generic signature is not returned.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.

Get Method Declaring Class

jvmtiError
GetMethodDeclaringClass(jvmtiEnv* env,
            jmethodID method,
            jclass* declaring_class_ptr)
For the method indicated by method, return the class that defined it via declaring_class_ptr.

This function may only be called during the start or the live phase.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
declaring_class_ptrjclass* On return, points to the declaring class

Agent passes a pointer to a jclass. On return, the jclass has been set. The object returned by declaring_class_ptr is a JNI local reference and must be managed.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NULL_POINTER declaring_class_ptr is NULL.

Get Method Modifiers

jvmtiError
GetMethodModifiers(jvmtiEnv* env,
            jmethodID method,
            jint* modifiers_ptr)
For the method indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
modifiers_ptrjint* On return, points to the access flags.

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NULL_POINTER modifiers_ptr is NULL.

Get Max Locals

jvmtiError
GetMaxLocals(jvmtiEnv* env,
            jmethodID method,
            jint* max_ptr)
For the method indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
max_ptrjint* On return, points to the maximum number of local slots

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER max_ptr is NULL.

Get Arguments Size

jvmtiError
GetArgumentsSize(jvmtiEnv* env,
            jmethodID method,
            jint* size_ptr)
For the method indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
size_ptrjint* On return, points to the number of argument slots

Agent passes a pointer to a jint. On return, the jint has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER size_ptr is NULL.

Get Line Number Table

typedef struct {
    jlocation start_location;
    jint line_number;
} jvmtiLineNumberEntry;
jvmtiError
GetLineNumberTable(jvmtiEnv* env,
            jmethodID method,
            jint* entry_count_ptr,
            jvmtiLineNumberEntry** table_ptr)
For the method indicated by 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_line_numbers Can get the line number table of a method

jvmtiLineNumberEntry - Line number table entry
Field Type Description
start_locationjlocation the jlocation where the line begins
line_numberjint the line number

Parameters
Name Type Description
methodjmethodID The method to query.
entry_count_ptrjint* On return, points to the number of entries in the table

Agent passes a pointer to a jint. On return, the jint has been set.
table_ptrjvmtiLineNumberEntry** On return, points to the line number table pointer.

Agent passes a pointer to a jvmtiLineNumberEntry*. On return, the jvmtiLineNumberEntry* points to a newly allocated array of size *entry_count_ptr. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_line_numbers. Use AddCapabilities.
JVMTI_ERROR_ABSENT_INFORMATION Class information does not include line numbers.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER entry_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER table_ptr is NULL.

Get Method Location

jvmtiError
GetMethodLocation(jvmtiEnv* env,
            jmethodID method,
            jlocation* start_location_ptr,
            jlocation* end_location_ptr)
For the method indicated by 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 and end_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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
start_location_ptrjlocation* On return, points to the first location, or -1 if location information is not available. If the information is available and GetJLocationFormat returns JVMTI_JLOCATION_JVMBCI then this will always be zero.

Agent passes a pointer to a jlocation. On return, the jlocation has been set.
end_location_ptrjlocation* On return, points to the last location, or -1 if location information is not available.

Agent passes a pointer to a jlocation. On return, the jlocation has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_ABSENT_INFORMATION Class information does not include method sizes.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER start_location_ptr is NULL.
JVMTI_ERROR_NULL_POINTER end_location_ptr is NULL.

Get Local Variable Table

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)
Return local variable information.

This function may only be called during the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_access_local_variables Can set and get local variables

jvmtiLocalVariableEntry - Local variable table entry
Field Type Description
start_locationjlocation The code array index where the local variable is first valid (that is, where it must have a value).
lengthjint The length of the valid section for this local variable. The last code array index where the local variable is valid is start_location + length.
namechar* The local variable name, encoded as a modified UTF-8 string.
signaturechar* The local variable's type signature, encoded as a modified UTF-8 string. The signature format is the same as that defined in The Java Virtual Machine Specification for Field Descriptors.
generic_signaturechar* The local variable's generic signature, encoded as a modified UTF-8 string. The value of this field will be NULL for any local variable which does not have a generic type.
slotjint The local variable's slot. See Local Variables.

Parameters
Name Type Description
methodjmethodID The method to query.
entry_count_ptrjint* On return, points to the number of entries in the table

Agent passes a pointer to a jint. On return, the jint has been set.
table_ptrjvmtiLocalVariableEntry** On return, points to an array of local variable table entries.

Agent passes a pointer to a jvmtiLocalVariableEntry*. On return, the jvmtiLocalVariableEntry* points to a newly allocated array of size *entry_count_ptr. The array should be freed with Deallocate. The pointers returned in the field name of jvmtiLocalVariableEntry are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field signature of jvmtiLocalVariableEntry are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field generic_signature of jvmtiLocalVariableEntry are newly allocated arrays. The arrays should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_access_local_variables. Use AddCapabilities.
JVMTI_ERROR_ABSENT_INFORMATION Class information does not include local variable information.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER entry_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER table_ptr is NULL.

Get Bytecodes

jvmtiError
GetBytecodes(jvmtiEnv* env,
            jmethodID method,
            jint* bytecode_count_ptr,
            unsigned char** bytecodes_ptr)
For the method indicated by 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_bytecodes Can get bytecodes of a method GetBytecodes

Parameters
Name Type Description
methodjmethodID The method to query.
bytecode_count_ptrjint* On return, points to the length of the byte code array

Agent passes a pointer to a jint. On return, the jint has been set.
bytecodes_ptrunsigned char** On return, points to the pointer to the byte code array

Agent passes a pointer to a unsigned char*. On return, the unsigned char* points to a newly allocated array of size *bytecode_count_ptr. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_bytecodes. Use AddCapabilities.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NATIVE_METHOD method is a native method.
JVMTI_ERROR_NULL_POINTER bytecode_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER bytecodes_ptr is NULL.

Is Method Native

jvmtiError
IsMethodNative(jvmtiEnv* env,
            jmethodID method,
            jboolean* is_native_ptr)
For the method indicated by 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.

Capabilities
Required Functionality

Parameters
Name Type Description
methodjmethodID The method to query.
is_native_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NULL_POINTER is_native_ptr is NULL.

Is Method Synthetic

jvmtiError
IsMethodSynthetic(jvmtiEnv* env,
            jmethodID method,
            jboolean* is_synthetic_ptr)
For the method indicated by 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.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
can_get_synthetic_attribute Can test if a field or method is synthetic - IsFieldSynthetic and IsMethodSynthetic

Parameters
Name Type Description
methodjmethodID The method to query.
is_synthetic_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_get_synthetic_attribute. Use AddCapabilities.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NULL_POINTER is_synthetic_ptr is NULL.

Is Method Obsolete

jvmtiError
IsMethodObsolete(jvmtiEnv* env,
            jmethodID method,
            jboolean* is_obsolete_ptr)
Determine if a method ID refers to an obsolete method version. See RedefineClasses for details.

This function may only be called during the start or the live phase.

Capabilities
Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function.
Capability Effect
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.

Parameters
Name Type Description
methodjmethodID The method ID to query.
is_obsolete_ptrjboolean* On return, points to the boolean result of this function.

Agent passes a pointer to a jboolean. On return, the jboolean has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The environment does not possess the capability can_redefine_classes. Use AddCapabilities.
JVMTI_ERROR_INVALID_METHODID method is not a jmethodID.
JVMTI_ERROR_NULL_POINTER is_obsolete_ptr is NULL.


Raw Monitor

Raw Monitor functions:


Create Raw Monitor

jvmtiError
CreateRawMonitor(jvmtiEnv* env,
            const char* name,
            jrawMonitorID* monitor_ptr)
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 the GarbageCollectionStart, GarbageCollectionFinish, and ObjectFree events.

Capabilities
Required Functionality

Parameters
Name Type Description
nameconst char* A name to identify the monitor, encoded as a modified UTF-8 string.

Agent passes in an array of char.
monitor_ptrjrawMonitorID* On return, points to the created monitor.

Agent passes a pointer to a jrawMonitorID. On return, the jrawMonitorID has been set.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER name is NULL.
JVMTI_ERROR_NULL_POINTER monitor_ptr is NULL.

Destroy Raw Monitor

jvmtiError
DestroyRawMonitor(jvmtiEnv* env,
            jrawMonitorID 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 the GarbageCollectionStart, GarbageCollectionFinish, and ObjectFree events.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NOT_MONITOR_OWNER Not monitor owner
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.

Raw Monitor Enter

jvmtiError
RawMonitorEnter(jvmtiEnv* env,
            jrawMonitorID monitor)
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 during 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.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.

Raw Monitor Exit

jvmtiError
RawMonitorExit(jvmtiEnv* env,
            jrawMonitorID monitor)
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 the GarbageCollectionStart, GarbageCollectionFinish, and ObjectFree events.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NOT_MONITOR_OWNER Not monitor owner
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.

Raw Monitor Wait

jvmtiError
RawMonitorWait(jvmtiEnv* env,
            jrawMonitorID monitor,
            jlong millis)
Wait for notification of the raw monitor.

Causes the current thread to wait until either another thread calls 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.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor
millisjlong The timeout, in milliseconds. If the timeout is zero, then real time is not taken into consideration and the thread simply waits until notified.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NOT_MONITOR_OWNER Not monitor owner
JVMTI_ERROR_INTERRUPT Wait was interrupted, try again
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.

Raw Monitor Notify

jvmtiError
RawMonitorNotify(jvmtiEnv* env,
            jrawMonitorID monitor)
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 the GarbageCollectionStart, GarbageCollectionFinish, and ObjectFree events.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NOT_MONITOR_OWNER Not monitor owner
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.

Raw Monitor Notify All

jvmtiError
RawMonitorNotifyAll(jvmtiEnv* env,
            jrawMonitorID monitor)
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 the GarbageCollectionStart, GarbageCollectionFinish, and ObjectFree events.

Capabilities
Required Functionality

Parameters
Name Type Description
monitorjrawMonitorID The monitor

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NOT_MONITOR_OWNER Not monitor owner
JVMTI_ERROR_INVALID_MONITOR monitor is not a jrawMonitorID.


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 the NewGlobalRef JNI call in order to count reference creation.
JNIEnv 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();
   }
}
      
Sometime after 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

jvmtiError
SetJNIFunctionTable(jvmtiEnv* env,
            const jniNativeInterface* 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. Use 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.

Capabilities
Required Functionality

Parameters
Name Type Description
function_tableconst jniNativeInterface * Points to the new JNI function table.

Agent passes in a pointer to jniNativeInterface.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER function_table is NULL.

Get JNI Function Table

jvmtiError
GetJNIFunctionTable(jvmtiEnv* env,
            jniNativeInterface** function_table)
Get the JNI function table. The JNI function table is copied into allocated memory. If 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.

Capabilities
Required Functionality

Parameters
Name Type Description
function_table jniNativeInterface ** On return, *function_table points a newly allocated copy of the JNI function table.

Agent passes a pointer to a jniNativeInterface*. On return, the jniNativeInterface* points to a newly allocated array. The array should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER function_table is NULL.


Event Management

Event Management functions:


Set Event Callbacks

jvmtiError
SetEventCallbacks(jvmtiEnv* env,
            const jvmtiEventCallbacks* callbacks,
            jint size_of_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 is NULL or when the event is beyond size_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.

Capabilities
Required Functionality

Parameters
Name Type Description
callbacksconst jvmtiEventCallbacks * The new event callbacks.

Agent passes in a pointer to jvmtiEventCallbacks. If callbacks is NULL, remove the existing callbacks.
size_of_callbacksjint sizeof(jvmtiEventCallbacks)--for version compatibility.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_ILLEGAL_ARGUMENT size_of_callbacks is less than 0.

Set Event Notification Mode

typedef enum {
    JVMTI_ENABLE = 1,
    JVMTI_DISABLE = 0
} jvmtiEventMode;
jvmtiError
SetEventNotificationMode(jvmtiEnv* env,
            jvmtiEventMode mode,
            jvmtiEvent event_type,
            jthread event_thread,
             ...)
Control the generation of events.
Event Enable/Disable (jvmtiEventMode)
Constant Value Description
JVMTI_ENABLE1 If mode is JVMTI_ENABLE, the event event_type will be enabled
JVMTI_DISABLE0 If mode is JVMTI_DISABLE, the event event_type will be disabled
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.

Initially, no events are enabled at either the thread level or the global level.

Any needed capabilities (see Event Enabling Capabilities below) must be possessed before calling this function.

Details on events are described below.

This function may only be called during the OnLoad or the live phase.

Capabilities
Required Functionality
Event Enabling Capabilities
Capability Events
can_generate_field_modification_eventsFieldModification
can_generate_field_access_eventsFieldAccess
can_generate_single_step_eventsSingleStep
can_generate_exception_eventsException
ExceptionCatch
can_generate_frame_pop_eventsFramePop
can_generate_breakpoint_eventsBreakpoint
can_generate_method_entry_eventsMethodEntry
can_generate_method_exit_eventsMethodExit
can_generate_compiled_method_load_eventsCompiledMethodLoad
CompiledMethodUnload
can_generate_monitor_eventsMonitorContendedEnter
MonitorContendedEntered
MonitorWait
MonitorWaited
can_generate_vm_object_alloc_eventsVMObjectAlloc
can_generate_native_method_bind_eventsNativeMethodBind
can_generate_garbage_collection_eventsGarbageCollectionStart
GarbageCollectionFinish
can_generate_object_free_eventsObjectFree

Parameters
Name Type Description
modejvmtiEventMode JVMTI_ENABLE or JVMTI_DISABLE
event_typejvmtiEvent the event to control
event_thread jthread The thread to control

If event_thread is NULL, event is controlled at the global level.
...... for future expansion

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_INVALID_THREAD event_thread is non-NULL and is not a valid thread.
JVMTI_ERROR_THREAD_NOT_ALIVE event_thread is non-NULL and is not live (has not been started or is now dead).
JVMTI_ERROR_ILLEGAL_ARGUMENT thread level control was attempted on events which do not permit thread level control.
JVMTI_ERROR_MUST_POSSESS_CAPABILITY The Required Event Enabling Capability is not possessed.
JVMTI_ERROR_ILLEGAL_ARGUMENT mode is not a jvmtiEventMode.
JVMTI_ERROR_INVALID_EVENT_TYPE event_type is not a jvmtiEvent.

Generate Events

jvmtiError
GenerateEvents(jvmtiEnv* env,
            jvmtiEvent event_type)
Generate events to represent the current state of the VM. For example, if 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.

Capabilities
Required Functionality
Optional Features
Capability Effect
can_generate_compiled_method_load_events Can generate events when a method is compiled or unloaded

Parameters
Name Type Description
event_typejvmtiEvent The type of event to generate. Must be one of these:

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_MUST_POSSESS_CAPABILITY event_type is JVMTI_EVENT_COMPILED_METHOD_LOAD and can_generate_compiled_method_load_events is false.
JVMTI_ERROR_ILLEGAL_ARGUMENT event_type is other than JVMTI_EVENT_COMPILED_METHOD_LOAD or JVMTI_EVENT_DYNAMIC_CODE_GENERATED.
JVMTI_ERROR_INVALID_EVENT_TYPE event_type is not a jvmtiEvent.


Extension Mechanism

Extension Mechanism functions: Extension Mechanism function types: Extension Mechanism types: These functions allow a JVM TI implementation to provide functions and events beyond those defined in this specification.

Both extension functions and extension events have parameters each of which has a 'type' and 'kind' chosen from the following tables:
Extension Function/Event Parameter Types (jvmtiParamTypes)
Constant Value Description
JVMTI_TYPE_JBYTE101 Java programming language primitive type - byte. JNI type jbyte.
JVMTI_TYPE_JCHAR102 Java programming language primitive type - char. JNI type jchar.
JVMTI_TYPE_JSHORT103 Java programming language primitive type - short. JNI type jshort.
JVMTI_TYPE_JINT104 Java programming language primitive type - int. JNI type jint.
JVMTI_TYPE_JLONG105 Java programming language primitive type - long. JNI type jlong.
JVMTI_TYPE_JFLOAT106 Java programming language primitive type - float. JNI type jfloat.
JVMTI_TYPE_JDOUBLE107 Java programming language primitive type - double. JNI type jdouble.
JVMTI_TYPE_JBOOLEAN108 Java programming language primitive type - boolean. JNI type jboolean.
JVMTI_TYPE_JOBJECT109 Java programming language object type - java.lang.Object. JNI type jobject. Returned values are JNI local references and must be managed.
JVMTI_TYPE_JTHREAD110 Java programming language object type - java.lang.Thread. JVM TI type jthread. Returned values are JNI local references and must be managed.
JVMTI_TYPE_JCLASS111 Java programming language object type - java.lang.Class. JNI type jclass. Returned values are JNI local references and must be managed.
JVMTI_TYPE_JVALUE112 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_JFIELDID113 Java programming language field identifier - JNI type jfieldID.
JVMTI_TYPE_JMETHODID114 Java programming language method identifier - JNI type jmethodID.
JVMTI_TYPE_CCHAR115 C programming language type - char.
JVMTI_TYPE_CVOID116 C programming language type - void.
JVMTI_TYPE_JNIENV117 JNI environment - JNIEnv. Should be used with the correct jvmtiParamKind to make it a pointer type.
Extension Function/Event Parameter Kinds (jvmtiParamKind)
Constant Value Description
JVMTI_KIND_IN91 Ingoing argument - foo.
JVMTI_KIND_IN_PTR92 Ingoing pointer argument - const foo*.
JVMTI_KIND_IN_BUF93 Ingoing array argument - const foo*.
JVMTI_KIND_ALLOC_BUF94 Outgoing allocated array argument - foo**. Free with Deallocate.
JVMTI_KIND_ALLOC_ALLOC_BUF95 Outgoing allocated array of allocated arrays argument - foo***. Free with Deallocate.
JVMTI_KIND_OUT96 Outgoing argument - foo*.
JVMTI_KIND_OUT_BUF97 Outgoing array argument (pre-allocated by agent) - foo*. Do not Deallocate.
typedef struct {
    char* name;
    jvmtiParamKind kind;
    jvmtiParamTypes base_type;
    jboolean null_ok;
} jvmtiParamInfo;

jvmtiParamInfo - Extension Function/Event Parameter Info
Field Type Description
namechar* The parameter name, encoded as a modified UTF-8 string
kindjvmtiParamKind The kind of the parameter - type modifiers
base_typejvmtiParamTypes The base type of the parameter - modified by kind
null_okjboolean Is a NULL argument permitted? Applies only to pointer and object types.


Extension Function

typedef jvmtiError (JNICALL *jvmtiExtensionFunction)
    (jvmtiEnv* jvmti_env, 
      ...);
This is the implementation-specific extension function.

Parameters
Name Type Description
jvmti_env jvmtiEnv * The JVM TI environment is the only fixed parameter for extension functions.
...... The extension function-specific parameters

Get Extension Functions

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)
Returns the set of extension functions.

This function may only be called during the OnLoad or the live phase.

Capabilities
Required Functionality

jvmtiExtensionFunctionInfo - Extension Function Info
Field Type Description
func jvmtiExtensionFunction The actual function to call
idchar* The identifier for the extension function, encoded as a modified UTF-8 string. Uses package name conventions. For example, com.sun.hotspot.bar
short_descriptionchar* A one sentence description of the function, encoded as a modified UTF-8 string.
param_countjint The number of parameters excluding jvmtiEnv *jvmti_env
params jvmtiParamInfo * Array of param_count parameters (jvmtiEnv *jvmti_env excluded)
error_countjint The number of possible error returns (excluding universal errors)
errors jvmtiError * Array of error_count possible errors

Parameters
Name Type Description
extension_count_ptrjint* On return, points to the number of extension functions

Agent passes a pointer to a jint. On return, the jint has been set.
extensionsjvmtiExtensionFunctionInfo** Returns an array of extension function info, one per function

Agent passes a pointer to a jvmtiExtensionFunctionInfo*. On return, the jvmtiExtensionFunctionInfo* points to a newly allocated array of size *extension_count_ptr. The array should be freed with Deallocate. The pointers returned in the field id of jvmtiExtensionFunctionInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field short_description of jvmtiExtensionFunctionInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field params of jvmtiExtensionFunctionInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field name of jvmtiParamInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field errors of jvmtiExtensionFunctionInfo are newly allocated arrays. The arrays should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER extension_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER extensions is NULL.

Get Extension Events

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)
Returns the set of extension events.

This function may only be called during the OnLoad or the live phase.

Capabilities
Required Functionality

jvmtiExtensionEventInfo - Extension Event Info
Field Type Description
extension_event_indexjint The identifying index of the event
idchar* The identifier for the extension event, encoded as a modified UTF-8 string. Uses package name conventions. For example, com.sun.hotspot.bar
short_descriptionchar* A one sentence description of the event, encoded as a modified UTF-8 string.
param_countjint The number of parameters excluding jvmtiEnv *jvmti_env
params jvmtiParamInfo * Array of param_count parameters (jvmtiEnv *jvmti_env excluded)

Parameters
Name Type Description
extension_count_ptrjint* On return, points to the number of extension events

Agent passes a pointer to a jint. On return, the jint has been set.
extensionsjvmtiExtensionEventInfo** Returns an array of extension event info, one per event

Agent passes a pointer to a jvmtiExtensionEventInfo*. On return, the jvmtiExtensionEventInfo* points to a newly allocated array of size *extension_count_ptr. The array should be freed with Deallocate. The pointers returned in the field id of jvmtiExtensionEventInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field short_description of jvmtiExtensionEventInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field params of jvmtiExtensionEventInfo are newly allocated arrays. The arrays should be freed with Deallocate. The pointers returned in the field name of jvmtiParamInfo are newly allocated arrays. The arrays should be freed with Deallocate.

Errors
This function returns either a universal error or one of the following errors
Error Description
JVMTI_ERROR_NULL_POINTER extension_count_ptr is NULL.
JVMTI_ERROR_NULL_POINTER extensions is NULL.

Extension Event

typedef void (JNICALL *jvmtiExtensionEvent)
    (jvmtiEnv* jvmti_env, 
      ...);
This is the implementation-specific event. The event handler is set with 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:
    void JNICALL myHandler(jvmtiEnv* jvmti_env, jint myInt, ...)
Note the terminal "..." which indicates varargs.

Parameters