Whole document tree
ContentsIntroduction IntroductionThe JavaTM Virtual Machine Debug Interface (JVMDI) is a programming interface used by debuggers and other programming tools. It provides a way both to inspect the state and to control the execution of applications running in the JavaTM Virtual Machine.JVMDI is a two-way interface. The JVMDI client can be notified of interesting occurrences through events. The JVMDI can query and control the application through many different functions, either in response to events or independent of them. JVMDI clients run in the same virtual machine as the application being debugged and access JVMDI through a native interface. The native, in-process interface allows maximal control with minimal intrusion on the part of a debugging tool. Typically, JVMDI clients are relatively compact. They can be controlled by a separate process which implements the bulk of a debugger's function without interfering with the target application's normal execution. JVMDI is one layer within the Java Platform Debugger Architecture. This architecture also contains higher-level, out-of-process debugger interfaces. The higher-level interfaces are more appropriate than JVMDI for many debugger tools. See the JPDA Homepage for more information on Java Platform Debugger Architecture. Using JVMDI FunctionsFor function and constant definitions, add #include <jvmdi.h>to your source code.
Like Java Native Interface (JNI) functions, JVMDI functions
are accessed through a function table.
The JVMDI function table can be obtained through the JNI
JVMDI_Interface_1 *jvmdi; ... (*jvm)->GetEnv(jvm, &jvmdi, JVMDI_VERSION_1);
JVMDI functions always return a
JVMDI functions identify objects with JNI references. References passed to JVMDI functions can be either global or local, but they must be strong references. All references returned by JVMDI functions are strong, global references. In the event that the JVMDI function encounters an error (any return value other than JVMDI_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.
JVMDI extends the data types defined by JNI with the following:
JVMDI functions fall into these categories:
Memory Management
Many JVMDI functions require memory allocation.
By default, memory comes from platform-specific allocation functions,
such as a Set Allocation HooksjvmdiError SetAllocationHooks(JVMDI_AllocHook ahook, JVMDI_DeallocHook dhook) Set the functions which will perform allocation and deallocation. The hook functions are defined as follows. typedef jvmdiError (*JVMDI_AllocHook)(jlong size, jbyte** memPtr) typedef jvmdiError (*JVMDI_DeallocHook)(jbyte* buffer)
JVMDI will call
The
The Parameters:
Allocate MemoryjvmdiError Allocate(jlong size, jbyte** memPtr)
Allocate an area of memory through the JVMDI allocator. The allocated
memory should be freed with Parameters:
This function returns either a universal error or one of the following errors:
Deallocate MemoryDeallocatejvmdiError Deallocate(jbyte* mem) mem using the JVMDI allocator. This function should
be used to deallocate any memory allocated and returned by a JVMDI function
or any memory allocated with Allocate .
Parameters:
This function returns either a universal error or one of the following errors:
Thread Execution FunctionsGet Thread StatusjvmdiError GetThreadStatus(jthread thread, jint *threadStatusPtr, jint *suspendStatusPtr) Get status information for a thread. Parameters: This function returns either a universal error or one of the following errors:
Get All ThreadsjvmdiError GetAllThreads(jint *threadsCountPtr, jthread **threadsPtr) Get all running threads known to the virtual machine. Native threads which are not attached to the VM are not included in the returned list. Parameters: This function returns either a universal error or one of the following errors:
Suspend ThreadjvmdiError SuspendThread(jthread thread)
Suspend the specified thread. If the calling thread is specified,
this function will not return until some other thread calls
Parameters:
This function returns either a universal error or one of the following errors:
Resume ThreadjvmdiError ResumeThread(jthread thread)
Resume a suspended thread. Any thread suspended through
Parameters:
This function returns either a universal error or one of the following errors:
Stop ThreadjvmdiError StopThread(jthread thread, jobject exception)
Send the specified asynchronous exception to the specified thread
(similar to Parameters:
The function returns one of the following error code: Interrupt ThreadjvmdiError InterruptThread(jthread thread)
Interrupt the specified thread
(similar to Parameters:
The function returns one of the following error code: Get Thread Infotypedef struct { char *name; /* Name in UTF-8 */ jint priority; jboolean is_daemon; jthreadGroup thread_group; jobject context_class_loader; } JVMDI_thread_info; jvmdiError GetThreadInfo(jthread thread, JVMDI_thread_info *infoPtr) Get thread information. The fields of the JVMDI_thread_info structure are filled in with details of the specified thread. Parameters:
This function returns either a universal error or one of the following errors:
Get Owned Monitor Infotypedef struct { jint owned_monitor_count; jobject *owned_monitors; } JVMDI_owned_monitor_info; jvmdiError GetOwnedMonitorInfo(jthread thread, JVMDI_owned_monitor_info *infoPtr) Get information about the monitors owned by the specified thread. The fields of the JVMDI_owned_monitor_info structure are filled in with details of the owned monitors. If this function is called for a thread different than the current thread, the specified thread must be suspended.
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Get Current Contended MonitorjvmdiError GetCurrentContendedMonitor(jthread thread, jobject *monitorPtr)
Get the object, if any, whose monitor the specified thread is waiting to
enter or waiting to regain through
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Run Debug Threadtypedef void (*JVMDI_StartFunction)(void *); jvmdiError RunDebugThread(jthread thread, JVMDI_StartFunction proc, void *arg, int priority);
Starts the execution of a debugger thread. with the specifed native function.
The start function is given the single argument, The new thread is started as a daemon thread.
Upon execution of Parameters:
This function returns one of the following error codes:
Thread GroupsGet Top Thread GroupsjvmdiError GetTopThreadGroups(jint *groupCountPtr, jthreadGroup **groupsPtr) Return all top-level (parentless) thread groups in the VM. Parameters:
This function returns one of the following error codes:
Get Thread Group Infotypedef struct { jthreadGroup parent; char *name; /* Name in UTF-8 */ jint max_priority; jboolean is_daemon; } JVMDI_thread_group_info; jvmdiError GetThreadGroupInfo(jthreadGroup group, JVMDI_thread_group_info *infoPtr) Get information about the thread group. The fields of the JVMDI_thread_group_info structure are filled in with details of the specified thread group. Parameters:
This function returns one of the following error codes:
Get Thread Group ChildrenGet the threads and thread groups created within the given thread group.jvmdiError GetThreadGroupChildren(jthreadGroup group, jint *threadCountPtr, jthread **threadsPtr, jint *groupCountPtr, jthreadGroup **groupsPtr) Parameters:
This function returns one of the following error codes:
Stack Frame AccessGet Thread's Frame CountjvmdiError GetFrameCount(jthread thread, jint *countPtr) Get the number of frames currently in the specified thread's call stack. If this function is called for a thread different than the current thread, the specified thread must be suspended. Parameters: This function returns either a universal error or one of the following errors:
Get Thread's Current FramejvmdiError GetCurrentFrame(jthread thread, jframeID *framePtr)
Get the
If this function is called for a thread different than the current thread,
the specified thread must be suspended.
The returned frame ID value
remains valid only until Parameters: This function returns either a universal error or one of the following errors:
Get Caller FrameForjvmdiError GetCallerFrame(jframeID called, jframeID *framePtr) frame , return the frame that called it via
framePtr .
Both called and the caller must be in a Java or JNI
method.
Parameters:
This function returns either a universal error or one of the following errors:
Frame LocationjvmdiError GetFrameLocation(jframeID frame, jclass *classPtr, jmethodID *methodPtr, jlocation *locationPtr) For a Java frame, return the location of the instruction currently executing. Parameters:
This function returns either a universal error or one of the following errors:
Notify Frame PopWhenjvmdiError NotifyFramePop(jframeID frame); frame is popped from the stack, generate a
JVMDI_EVENT_FRAME_POP event. See Events.
Parameters:
This function returns either a universal error or one of the following errors:
Local Variable AccessGet Local VariablejvmdiError GetLocalObject(jframeID frame, jint slot, jobject *valuePtr) jvmdiError GetLocalInt(jframeID frame, jint slot, jint *valuePtr) jvmdiError GetLocalLong(jframeID frame, jint slot, jlong *valuePtr) jvmdiError GetLocalFloat(jframeID frame, jint slot, jfloat *valuePtr) jvmdiError GetLocalDouble(jframeID frame, jint slot, jdouble *valuePtr)
These functions are used to retrieve the value of a local variable.
Parameters:
The functions return one of the following error codes:
Set Local VariablejvmdiError SetLocalObject(jframeID frame, jint slot, jobject value) jvmdiError SetLocalInt(jframeID frame, jint slot, jint value) jvmdiError SetLocalLong(jframeID frame, jint slot, jlong value) jvmdiError SetLocalFloat(jframeID frame, jint slot, jfloat value) jvmdiError SetLocalDouble(jframeID frame, jint slot, jdouble value)
These functions are used to set the value of a local variable.
Parameters:
The functions return one of the following error codes:
BreakpointsSet a BreakpointjvmdiError SetBreakpoint(jclass clazz, jmethodID method, jlocation location)
Set a breakpoint at the instruction indicated by
Whenever the designated instruction is about to be executed, a
Parameters:
This function returns either a universal error or one of the following errors:
Clear a BreakpointjvmdiError ClearBreakpoint(jclass clazz, jmethodID method, jlocation location)
Clear the breakpoint at the bytecode indicated by Parameters:
This function returns either a universal error or one of the following errors:
Clear All BreakpointsClear all breakpoints in this virtual machine.jvmdiError ClearAllBreakpoints() Watched FieldsSet a Field Access WatchjvmdiError SetFieldAccessWatch(jclass clazz, jfieldID field)
Generate a JVMDI_EVENT_FIELD_ACCESS event
when the field specified
by
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Clear a Field Access WatchjvmdiError ClearFieldAccessWatch(jclass clazz, jfieldID field)
Cancel a field access watch previously set by
SetFieldAccessWatch, on the
field specified
by Parameters:
This function returns either a universal error or one of the following errors:
Set a Field Modification WatchjvmdiError SetFieldModificationWatch(jclass clazz, jfieldID field)
Generate a JVMDI_EVENT_FIELD_MODIFICATION event
when the field specified
by
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Clear a Field Modification WatchjvmdiError ClearFieldModificationWatch(jclass clazz, jfieldID field)
Cancel a field modification watch previously set by
SetFieldModificationWatch, on the
field specified
by Parameters:
This function returns either a universal error or one of the following errors:
Class InformationClass SignatureFor the class indicated byjvmdiError GetClassSignature(jclass clazz, char **sigPtr) clazz , return the class signature
via sigPtr . The return value is a UTF-8 string.
The returned signature for primitive classes (for example, java.lang.Integer.TYPE) is the signature of the corresponding primitive type (for example, "I"). Parameters:
This function returns either a universal error or one of the following errors:
Class StatusGet the status of the class. Zero or more of the following bits can be set.jvmdiError GetClassStatus(jclass clazz, jint *statusPtr)
The status value for primitive classes (for example, java.lang.Integer.TYPE) and for arrays is undefined. Parameters:
This function returns either a universal error or one of the following errors:
Source File NameFor the class indicated byjvmdiError GetSourceFileName(jclass clazz, char **sourceNamePtr) clazz , return the source file
name via sourceNamePtr . The returned UTF-8 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 JVMDI_ERROR_ABSENT_INFORMATION. Parameters:
This function returns either a universal error or one of the following errors:
Class Modifier FlagsFor the class indicated byjvmdiError GetClassModifiers(jclass clazz, jint *modifiersPtr) clazz , return the access
flags
via modifiersPtr .
Access flag
definitions and information about
class modifiers
can be found 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 modifers are always false. If the class is an array class or a primitive class then its final modifier is always true and its interface modifer is always false. The values of its other modifiers are not determined by this specification. Parameters:
This function returns either a universal error or one of the following errors:
Class MethodsFor the class indicated byjvmdiError GetClassMethods(jclass clazz, jint *methodCountPtr, jmethodID **methodsPtr) clazz , return a count of
methods via methodCountPtr and a list of
method IDs via methodsPtr . The method list contains
constructors and static initializers as well as true methods.
Only directly declared methods are returned (not inherited methods).
Methods are returned in the order they occur in the class file.
An empty method list is returned for array classes and primitive classes
(for example, java.lang.Integer.TYPE).
Parameters:
This function returns either a universal error or one of the following errors:
Class FieldsFor the class indicated byjvmdiError GetClassFields(jclass clazz, jint *fieldCountPtr, jfieldID **fieldsPtr) clazz , return a count of fields
via fieldCountPtr and a list of field IDs via
fieldsPtr .
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.
Parameters:
This function returns either a universal error or one of the following errors:
Implemented InterfacesReturn the direct superinterfaces of this class. For a class, this function returns the interfaces declared in itsjvmdiError GetImplementedInterfaces(jclass clazz, jint *interfaceCountPtr, jclass **interfacesPtr); 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).
Parameters:
This function returns either a universal error or one of the following errors:
Is an InterfaceDetermines whether a class object reference represents an interface. ThejvmdiError IsInterface(jclass clazz, jboolean *isInterfacePtr) jboolean result is
JNI_TRUE if the "class" is actually an interface,
JNI_FALSE otherwise.
Parameters:
This function returns either a universal error or one of the following errors:
Is an ArrayDetermines whether a class object reference represents an array. ThejvmdiError IsArrayClass(jclass clazz, jboolean *isArrayClassPtr) jboolean result is
JNI_TRUE if the class is an array,
JNI_FALSE otherwise.
Parameters:
This function returns either a universal error or one of the following errors:
Class LoaderFor the class indicated byjvmdiError GetClassLoader(jclass clazz, jobject *classloaderPtr) clazz , return via
classloaderPtr a reference to the class loader for the
class. If the class was not created by a class loader,
classloaderPtr points to NULL .
Parameters:
This function returns either a universal error or one of the following errors:
Object InformationObject Hash CodeFor the object indicated byjvmdiError GetObjectHashCode(jobject object, jint *hashCodePtr) object
return via hashCodePtr a hash code that can be used in
maintaining hash table of object references. This function guarantees
the same hash code value for a particular object throughout its life
Parameters:
This function returns either a universal error or one of the following errors:
Get Monitor Infotypedef struct { jthread owner; jint entry_count; jint waiter_count; jthread *waiters; } JVMDI_monitor_info; jvmdiError GetMonitorInfo(jobject object, JVMDI_monitor_info *infoPtr) Get information about the the object's monitor The fields of the JVMDI_owned_monitor_info structure are filled in with details of the monitor. Each thread that might affect the monitor state must either be suspended or must be the current thread.
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Field InformationField Name and SignatureFor the field indicated byjvmdiError GetFieldName(jclass clazz, jfieldID field, char **namePtr, char **signaturePtr) clazz and field ,
return the field name via namePtr and field signature via
signaturePtr .
Parameters:
This function returns either a universal error or one of the following errors:
Field Declaring ClassFor the field indicated byjvmdiError GetFieldDeclaringClass(jclass clazz, jfieldID field, jclass *declaringClassPtr) clazz and field
return the class that defined it via declaringClassPtr .
The declaring class will either be clazz . a superclass, or
an implemented interface.
Parameters:
This function returns either a universal error or one of the following errors:
Field Modifier FlagsFor the field indicated byjvmdiError GetFieldModifiers(jclass clazz, jfieldID field, jint *modifiersPtr) clazz and field
return the access flags via modifiersPtr .
Access flag
definitions and information about
field modifiers
can be found in the
Java
virtual machine specification.
Parameters:
This function returns either a universal error or one of the following errors:
Is Field SyntheticjvmdiError IsFieldSynthetic(jclass clazz, jfieldID field, jboolean *isSyntheticPtr)
For the field indicated by
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Method InformationMethod Name and SignaturejvmdiError GetMethodName(jclass clazz, jmethodID method, char **namePtr, char **signaturePtr)
For the method indicated by Parameters:
This function returns either a universal error or one of the following errors:
Method Declaring ClassFor the method indicated byjvmdiError GetMethodDeclaringClass(jclass clazz, jmethodID method, jclass *declaringClassPtr) clazz and method ,
return the Class that defined it via declaringClassPtr .
Parameters:
This function returns either a universal error or one of the following errors:
Method Modifier FlagsFor the method indicated byjvmdiError GetMethodModifiers(jclass clazz, jmethodID method, jint *modifiersPtr) clazz and method
return the access flags via modifiersPtr .
Access flag
definitions and information about
method modifiers
can be found in the
Java
virtual machine specification.
Parameters:
This function returns either a universal error or one of the following errors:
Maximum StackFor the method indicated byjvmdiError GetMaxStack(jclass clazz, jmethodID method, jint *maxPtr) clazz and method ,
return via maxPtr the maximum number of words that can be
on the stack while the method is executing.
Parameters:
This function returns either a universal error or one of the following errors:
Locals SlotsFor the method indicated byjvmdiError GetMaxLocals(jclass clazz, jmethodID method, jint *maxPtr); clazz and method ,
return via maxPtr the number of local variable slots used
by the whole method.
Note that two-word arguments use two slots.
Parameters:
This function returns either a universal error or one of the following errors:
Argument SlotsFor the method indicated byjvmdiError GetArgumentsSize(jclass clazz, jmethodID method, jint *sizePtr) clazz and method ,
return via maxPtr the number of local variable slots used
by the method's arguments.
Note that two-word arguments use two slots.
Parameters:
This function returns either a universal error or one of the following errors:
Source Line NumbersFor the method indicated byjvmdiError GetLineNumberTable(jclass clazz, jmethodID method, jint *entryCountPtr, JVMDI_line_number_entry **tablePtr) clazz and method ,
return a table of source line number entries. The size of the table is
returned via entryCountPtr and the table itself is
returned via tablePtr .
A table entry is an instance of the following structure:
typedef struct { jlocation start_location; jint line_number; } JVMDI_line_number_entry; Parameters:
This function returns either a universal error or one of the following errors:
Method LocationFor the method indicated byjvmdiError GetMethodLocation(jclass clazz, jmethodID method, jlocation *startLocationPtr, jlocation *endLocationPtr) clazz and method ,
return the beginning and ending addresses through
startLocationPtr and endLocationPtr . In a
conventional byte code indexing scheme, these values are always zero
and the byte code count minus one.
Parameters:
This function returns either a universal error or one of the following errors:
Local VariablesFor the method indicated byjvmdiError GetLocalVariableTable(jclass clazz, jmethodID method, jint *entryCountPtr, JVMDI_local_variable_entry **tablePtr) clazz and method ,
return a table of local variables.
The size of the table is
returned via entryCountPtr and the table itself is
returned via tablePtr .
A table entry has this structure:
typedef struct { jlocation start_location; /* variable valid start_location */ jint length; /* upto start_location+length */ char *name; /* name in UTF-8 */ char *signature; /* type signature in UTF-8 */ jint slot; /* variable slot, see JVMDI_GetLocal*() */ } JVMDI_local_variable_entry; Parameters:
This function returns either a universal error or one of the following errors:
Exception HandlersFor the method indicated byjvmdiError GetExceptionHandlerTable(jclass clazz, jmethodID method, jint *entryCountPtr, JVMDI_exception_handler_entry **tablePtr) clazz and method ,
return a table of exception handlers.
The size of the table is
returned via entryCountPtr and the table itself is
returned via tablePtr .
A table entry has this structure:
typedef struct { jlocation start_location; jlocation end_location; jlocation handler_location; jclass exception; /* if null, all exceptions */ } JVMDI_exception_handler_entry; A call to this function may trigger class loading for the thrown exception classes that have not yet been loaded. It should not be called while threads are suspended. Parameters:
This function returns either a universal error or one of the following errors:
Thrown ExceptionsFor the method indicated byjvmdiError GetThrownExceptions(jclass clazz, jmethodID method, jint *exceptionCountPtr, jclass **exceptionsPtr) clazz and method ,
return an array of exception classes the method might throw.
The number of exceptions is returned via exceptionCountPtr .
The exceptions array is returned via exceptionsPtr .
A call to this function may trigger class loading for the thrown exception classes that have not yet been loaded. It should not be called while threads are suspended. Parameters:
This function returns either a universal error or one of the following errors:
Get BytecodesFor the method indicated byjvmdiError GetBytecodes(jclass clazz, jmethodID method, jint *bytecodeCountPtr, jbyte **bytecodesPtr) clazz and method ,
return the byte codes that implement the method. The number of
bytecodes is returned via bytecodeCountPtr . The byte codes
themselves are returned via bytecodesPtr .
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Is Method NativejvmdiError IsMethodNative(jclass clazz, jmethodID method, jboolean *isNativePtr)
For the method indicated by Parameters:
This function returns either a universal error or one of the following errors:
Is Method SyntheticjvmdiError IsMethodSynthetic(jclass clazz, jmethodID method, jboolean *isSyntheticPtr)
For the method indicated by
This is an optional feature which may not be implemented for all
virtual machines. Use Parameters:
This function returns either a universal error or one of the following errors:
Raw Monitor SupportCreate Raw MonitorCreate a raw monitor.jvmdiError CreateRawMonitor(char *name, JVMDI_RawMonitor *monitorPtr) Parameters:
This function returns either a universal error or one of the following errors:
Destroy Raw MonitorDestroy the raw monitor.jvmdiError DestroyRawMonitor(JVMDI_RawMonitor monitor) Parameters:
This function returns either a universal error or one of the following errors:
Raw Monitor EnterGain exclusive ownership of a raw monitor.jvmdiError RawMonitorEnter(JVMDI_RawMonitor monitor) Parameters:
This function returns either a universal error or one of the following errors:
Raw Monitor ExitRelease exclusive ownership of a raw monitor.jvmdiError RawMonitorExit(JVMDI_RawMonitor monitor) Parameters:
This function returns either a universal error or one of the following errors:
Raw Monitor WaitWait for notification of the raw monitor.jvmdiError RawMonitorWait(JVMDI_RawMonitor monitor, jlong millis) Parameters:
This function returns either a universal error or one of the following errors: Raw Monitor NotifyNotify a single thread waiting on the raw monitor.jvmdiError RawMonitorNotify(JVMDI_RawMonitor monitor) Parameters:
This function returns either a universal error or one of the following errors:
Raw Monitor Notify AllNotify all threads waiting on the raw monitor.jvmdiError RawMonitorNotifyAll(JVMDI_RawMonitor monitor) Parameters:
This function returns either a universal error or one of the following errors:
EventsSet Event HookSet the function to be called on every event. Details on events are described later in this document.typedef void (*JVMDI_EventHook)(JNIEnv *env , JVMDI_Event *event); jvmdiError SetEventHook(JVMDI_EventHook hook) Parameters:
This function returns a universal error on error. Enable/Disable EventsControl the generation of events. IfjvmdiError SetEventNotificationMode(jint mode, jint eventType, jthread thread, ...) mode is JVMDI_ENABLE,
the event eventType is enabled; if mode is
JVMDI_DISABLE, the event is 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 the thread level. All events except the following are enabled at the global level.
Parameters:
This function returns either a universal error or one of the following errors:
Miscellaneous FunctionsGet Loaded ClassesjvmdiError GetLoadedClasses(jint *classCountPtr, jclass **classesPtr)
Return an array of all classes loaded in the virtual machine.
The number of classes in the array is returned via
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. Parameters:
This function returns either a universal error or one of the following errors:
Get Classloader ClassesjvmdiError GetClassLoaderClasses(jobject initiatingLoader, jint *classCountPtr, jclass **classesPtr) Returns an array of all classes for which this class loader has been recorded as the 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.
For JDK 1.1 implementations which don't
recognize the distinction between initiating and defining classloaders,
this function should return all classes loaded in the virtual machine.
The number of classes in the array is returned via
The Parameters:
This function returns either a universal error or one of the following errors:
Get Version NumberReturn the JVMDI version viajvmdiError GetVersionNumber(jint *versionPtr) versionPtr
The return value is the version identifier. The low-order 16 bits represent
the minor version number. The next 12 bits represent the major version
number. The high-order 4 bits are undefined.
Parameters:
This function returns either a universal error or one of the following errors:
Get CapabilitiesReturn viatypedef struct { unsigned int can_watch_field_modification : 1; unsigned int can_watch_field_access : 1; unsigned int can_get_bytecodes : 1; unsigned int can_get_synthetic_attribute : 1; unsigned int can_get_owned_monitor_info : 1; unsigned int can_get_current_contended_monitor : 1; unsigned int can_get_monitor_info : 1; } JVMDI_capabilities; jvmdiError GetCapabilities(JVMDI_capabilities *capabilitiesPtr) capabilitiesPtr the optional JVMDI
features supported by this implementation. The capabilities
structure contains a number of boolean flags indicating whether
the named feature is supported.
Parameters:
This function returns either a universal error or one of the following errors:
Errors
Every JVMDI function returns a Universal ErrorsThe following errors may be returned by any JVMDI function (and are thus not listed in the function descriptions):
Function Specific ErrorsThe following errors are returned by some JVMDI functions (and are listed in the function descriptions):
Handling EventsJVMDI clients can be informed of many events that occur in application programs.
To handle Events, designate a hook function with
Some JVMDI events identify objects with JNI references.
All such references are passed to the event hook function via
the Events can be enabled and disabled with the function SetEventNotificationMode. Some events are enabled at application startup; others are not. Refer to the documentation for this function for details. A thread that generates an event does not change its execution status. If an event should cause a thread to be suspended, then the event hook function is responsible for explicitly suspending the thread with SuspendThread.
The typedef struct { jint kind; /* the discriminant */ union { /* kind = JVMDI_EVENT_SINGLE_STEP */ JVMDI_single_step_event_data single_step; /* kind = JVMDI_EVENT_BREAKPOINT */ JVMDI_breakpoint_event_data breakpoint; /* kind = JVMDI_EVENT_FRAME_POP */ /* kind = JVMDI_EVENT_METHOD_ENTRY */ /* kind = JVMDI_EVENT_METHOD_EXIT */ JVMDI_frame_event_data frame; /* kind = JVMDI_EVENT_FIELD_ACCESS */ JVMDI_field_access_event_data field_access; /* kind = JVMDI_EVENT_FIELD_MODIFICATION */ JVMDI_field_modification_event_data field_modification; /* kind = JVMDI_EVENT_EXCEPTION */ JVMDI_exception_event_data exception; /* kind = JVMDI_EVENT_EXCEPTION_CATCH */ JVMDI_exception_catch_event_data exception_catch; /* kind = JVMDI_EVENT_USER_DEFINED */ JVMDI_user_event_data user; /* kind = JVMDI_EVENT_THREAD_END or */ /* JVMDI_EVENT_THREAD_START */ JVMDI_thread_change_event_data thread_change; /* kind = JVMDI_EVENT_CLASS_LOAD, */ /* JVMDI_EVENT_CLASS_UNLOAD, or */ /* JVMDI_EVENT_CLASS_PREPARE */ JVMDI_class_event_data class_event; /* kind = JVMDI_EVENT_VM_DEATH, JVMDI_EVENT_VM_INIT */ /* no additional fields */ } u; } JVMDI_Event; More information on specific events is given in the sections below. Single Step Events (JVMDI_EVENT_SINGLE_STEP)typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; } JVMDI_single_step_event_data;
Single step events allow the JVMDI client to trace thread execution
at the finest granularity allowed by the VM. A single step event is
generated whenever a thread reaches a new location.
Typically, single step events represent the completion of one VM
instruction as defined the VM Specification; however, some implementations
may define location differently. In any case the
No single step events are generated from within native methods.
Single step events are disabled by default and can be enabled for a
thread by calling
Breakpoint Events (JVMDI_EVENT_BREAKPOINT)typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; } JVMDI_breakpoint_event_data;
Breakpoint Events are generated whenever a thread reaches a location
designated as a breakpoint with SetBreakpoint.
The
Breakpoint reporting, in general, can be enabled or disabled by calling
Field Events (JVMDI_EVENT_FIELD_ACCESS, JVMDI_EVENT_FIELD_MODIFICATION)/* kind = JVMDI_EVENT_FIELD_ACCESS */ typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; jclass field_clazz; jobject object; jfieldID field; } JVMDI_field_access_event_data; /* kind = JVMDI_EVENT_FIELD_MODIFICATION */ typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; jclass field_clazz; jobject object; jfieldID field; char signature_type; jvalue new_value; } JVMDI_field_modification_event_data;
Field Events are generated whenever a thread accesses or modifies
a field
designated as a watchpoint
with
Field watchpoint reporting, in general, can be enabled or disabled by calling
Frame Events (JVMDI_EVENT_FRAME_POP, JVMDI_EVENT_METHOD_ENTRY, JVMDI_EVENT_METHOD_EXIT)typedef struct { jthread thread; jclass clazz; jmethodID method; jframeID frame; } JVMDI_frame_event_data;
Method entry events are generated upon entry of Java or native methods.
Method exit events are generated upon exit from a Java or native methods.
Frame pop events are generated upon exit from a single method
in a single frame as specified
in a call to
The
Method entry and exit are disabled by default and can be enabled by calling
Exception Events (JVMDI_EVENT_EXCEPTION)typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; jobject exception; jclass catch_clazz; jmethodID catch_method; jlocation catch_location; } JVMDI_exception_event_data; Exception events are generated whenever an exception is first detected in a Java method. The exception may have been thrown by a Java or native method, but in the case of native methods, the event is not generated until the exception is first seen by a Java method. If an exception is set and cleared in a native method (and thus is never visible to Java code), no exception event is generated.
The
Exception events are enabled by default and can be disabled by calling
typedef struct { jthread thread; jclass clazz; jmethodID method; jlocation location; jobject exception; } JVMDI_exception_catch_event_data; Exception catch events are generated whenever a thrown exception is caught. If the exception is caught in a Java method, the event is generated when the catch clause is reached. If the exception is caught in a native method, the event is generated as soon as control is returned to a Java method. Exception catch events are generated for any exception for which a throw was detected in a Java method.
The
Exception catch events are disabled by default and can be enabled by calling
User Defined Events (JVMDI_EVENT_USER_DEFINED)typedef struct { jobject object; jint key; } JVMDI_user_event_data; The meaning of user defined events and the fields in the user event data structure are defined by particular JVMDI implementations. Thread Events (JVMDI_EVENT_THREAD_END, JVMDI_EVENT_THREAD_START)typedef struct { jthread thread; } JVMDI_thread_change_event_data;
Thread start events are generated by a new thread before its initial
method executes. Thread end events are generated by a terminating thread
after its initial method has finished execution. A thread may be
listed in the array returned by
Thread events are enabled by default and can be disabled by calling
Class Events (JVMDI_EVENT_CLASS_LOAD, JVMDI_EVENT_CLASS_UNLOAD, JVMDI_EVENT_CLASS_PREPARE)typedef struct { jthread thread; jclass clazz; } JVMDI_class_event_data; Class events signal a change in status for a particular class. A class load event is generated when a class is first loaded. The order of class load events are generated by a particular thread are guaranteed to match the order of class loading within that thread. Arrays of non-primitive types have class load events. Arrays of primitive types do not have class load events (they are considered loaded at the time of VM initialization). Primitive classes (for example, java.lang.Integer.TYPE) do not have class load events. A class prepare event is generated when class preparation is complete. At this point, class fields, methods, and implemented interfaces are available, and no code from the class has been executed. Since array classes never have fields or methods, class prepare events are not generated for them. Class prepare events are not generated for primitive classes (for example, java.lang.Integer.TYPE). A class unload event is generated when the class is about to be unloaded. Class unload events take place during garbage collection and must be handled extremely carefully. The garbage collector holds many locks and has suspended all other threads, so the event handler cannot depend on the ability to acquire any locks. The class unload event handler should do as little as possible, perhaps by queueing information to be processed later.
Class events are enabled by default and can be disabled by calling
VM Initialization Event (JVMDI_EVENT_VM_INIT)The VM initialization event signals the completion of VM initialization. Once this event is generated, the JVMDI client is free to call any JNI or JVMDI function. The VM initialization event can be preceded by or can be concurrent with other events, but the preceding events should be handled carefully, if at all because the VM has not completed its initialization. The thread start event for the main application thread is guaranteed not to occur until after the handler for the VM initialization event returns. VM Death Event (JVMDI_EVENT_VM_DEATH)The VM death event notifies the JVMDI client of the termination of the VM.Multiple Co-located EventsIn many situations it is possible for multiple events to occur at the same location in one thread. When this happens, all of the events are reported through the event hook in the order specified in the following paragraphs.
If the current location is at the entry point of a method, the
If an exception catch has been detected at the current location,
(either because it is the beginning of a catch clause or a native method
which cleared a pending exception has returned), the
If a
If the current location is the exit point of a method (that is, the last
location before returning to the caller), the
Co-located events can be triggered during the processing of some other
event by the JVMDI client at the same location in the same thread.
If such an event, of type y, is triggered during the processing of
an event of type x, and if x
precedes y in the ordering specified above, then the co-located event
y is reported for the current thread and location. If x does not precede
y, then y is not reported for the current thread and location.
For example, if a breakpoint is set at the current location
during the processing of The following events are never considered to be co-located with other events.
Starting a VM with a JVMDI ClientThe initial loading of a JVMDI client at VM startup can vary from VM to VM. The following description applies to the Sun classic VM for Windows and Solaris. The following command-line arguments are required on VM startup to properly load and run JVMDI clients.
|