Microsoft SDK for Java

Retrieving Dynamic Information with the Profiler

The profiler interfaces include a number of methods that allow a profiler to retrieve dynamic information regarding the Java process being executed. Dynamic information on Java processes can also be retrieved by a program that uses the debugger interfaces. While the profiler interfaces do not have as many and varied features as the debugger interfaces, the overhead incurred on the Microsoft VM by using the profiler interfaces is significantly lower than that incurred by using the debugger interfaces. Consequently, it is recommended that profilers use the profiler interfaces to retrieve dynamic information on a Java process.

The starting point for retrieving dynamic information on a Java process is based on using the UniqueIDs passed to the event notification methods that are implemented by a profiler. The methods that receive UniqueIDs of various types include NotifyEvent, NotifyEvent2, MethodEntry, and MethodExit2. Using these UniqueIDs (ClassIDs and MethodIDs, for example), a profiler can call methods implemented by the Microsoft VM to gather detailed dynamic information on all threads, stack frames, class instances, and class fields that are used by a Java process.

If event notification is enabled for class loads (JVM_MONITOR_CLASS_LOADS), a profiler will be notified when Java classes are loaded and unloaded. The UniqueID passed to the NotifyEvent method when a class load is finished (JVM_EVENT_TYPE_CLASS_LOAD_FINISHED) is the ClassID of the class that was loaded.

If event notification is enabled for method calls (JVM_MONITOR_METHOD_CALLS or JVM_MONITOR_SPECIFIC_METHOD_CALLS), a profiler will be notified when a Java method is entered and exited. The MethodEntry method is passed the StackID and MethodID of the method about to be entered. The MethodExit2 method is passed the StackID and MethodID of the method that is about to be exited to. If event notification is enabled for JVM_MONITOR_SPECIFIC_METHOD_CALLS, the profiler can enable and disable whether it will receive method event calls on a method-by-method basis.

After gathering static information (as noted in the section on Retrieving Static Class Information), a profiler can retrieve dynamic information on these objects.

The following table indicates some event notification methods and associated UniqueIDs that can be used for gathering dynamic information.

Method Event Type ObjectID Comments
NotifyEvent JVM_EVENT_TYPE_
EXCEPTION_OCCURRED.
StackID Notification on exceptions (JVM_MONITOR_
EXCEPTIONS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_
THREAD_CREATE.
ThreadID Notification on threads (JVM_MONITOR_THREADS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_
THREAD_DESTROY.
ThreadID. Notification on threads (JVM_MONITOR_THREADS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_GC_
STARTED.
None Notification on garbage collections (JVM_MONITOR_GARBAGE_
COLLECTIONS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_GC_
FINISHED.
None Notification on garbage collections (JVM_MONITOR_GARBAGE_
COLLECTIONS) must be enabled.

Using ClassIDs, a profiler can call methods implemented by the Microsoft VM to navigate the hierarchy of a class and gather static information on class methods and fields. Using ClassIDs, FieldIDs, ObjectIDs, ThreadIDs, StackIDs, and other UniqueIDs, a profiler can determine dynamic information regarding the executing Java process.

Use GetMethodEntryParameters to retrieve the parameters that were passed to a method before execution of the method begins. The calling convention for the method about to be executed can be any of the values defined in the JVM_CALLING_CONVENTION enumeration. A profiler can only call GetMethodEntryParameters during a MethodEntry callback notification. The Microsoft VM returns a pointer to the base of the array of parameters that are passed to the current method, a bitmask of call flags, and a value that represents the calling convention for the method.

Use GetMethodExitReturnValue to retrieve the return value from the method call that just returned. The profiler can only call GetMethodExitReturnValue during a MethodExit or MethodExit2 callback notification. The Microsoft VM returns the MethodID of the method that is exiting and its return value. To properly interpret the return value (its type and value), a profiler would need to parse the signature for this method. Retrieve this parameter signature by calling MethodInformation.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.