Microsoft SDK for Java

Retrieving Static Class Information

The profiler interfaces include a number of methods that allow a profiler to retrieve static information regarding the Java process being executed. Static information on Java classes can also be retrieved by a program that uses the debugger interfaces. While the profiler interfaces are not as numerous 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 static information on Java classes.

The starting point for retrieving static information on Java classes 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, MethodEntry, NotifyEvent2, and MethodExit2. Using these UniqueIDs (ClassIDs and MethodIDs, for example), a profiler can call methods implemented by the Microsoft VM to gather detailed static information on all the classes, class methods, and class fields used by a Java application or applet.

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. The UniqueID passed to the NotifyEvent method when a class is unloaded (JVM_EVENT_TYPE_CLASS_UNLOAD) is the ClassID of the class that was unloaded. Note that the ClassID and MethodIDs from a class become invalid after the class has been unloaded. Once a class is unloaded, the profiler must not make calls to the Microsoft VM with a ClassID or MethodIDs for the unloaded class.

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

Method Event type UniqueID Comments
NotifyEvent JVM_EVENT_TYPE_
CLASS_LOAD_STARTED
None Passes class name as a UTF-8 string. Notification on class loads (JVM_MONITOR_CLASS_
LOADS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_
CLASS_LOAD_FINISHED
ClassID Notification on class loads (JVM_MONITOR_CLASS_
LOADS) must be enabled. 
NotifyEvent JVM_EVENT_TYPE_
CLASS_UNLOAD
ClassID Notification on class loads (JVM_MONITOR_CLASS_
LOADS) must be enabled.
NotifyEvent JVM_EVENT_TYPE_JIT_
COMPILE_STARTED
MethodID Notification on JIT compilation (JVM_MONITOR_JIT_
COMPILATION) must be enabled.
NotifyEvent JVM_EVENT_TYPE_JIT_
COMPILE_FINISHED
MethodID Notification on JIT compilation (JVM_MONITOR_JIT_
COMPILATION) must be enabled.
MethodEntry Method entered MethodID Notification on method calls (JVM_MONITOR_METHOD_CALLS or JVM_MONITOR_SPECIFIC_METHOD_CALLS) must be enabled.
MethodExit2 Method exited MethodID Notification on method calls (JVM_MONITOR_METHOD_CALLS or JVM_MONITOR_SPECIFIC_METHOD_CALLS) 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. Some of the methods that can be used for this purpose are as follows.

Use ClassInformation and MethodInformation to retrieve basic information on a class and its methods. Most of this information parallels the information available with the Java Reflection APIs.

Use FieldInformation, GetClassFields, and StaticClassInformation to retrieve additional static information on a class and its methods and fields.

Use GetSpecialClassProperties to return a list of classes with special properties. Classes for which special information is available include instances of java.lang.Class, java.lang.reflect.Method, java.lang.reflect.Field, java.lang.String, and java.lang.StringBuffer. Use DescribeObject to retrieve this additional descriptive information.

Use ClassInformation2 to retrieve more detailed information about a class, its methods, its interfaces, and its superclass. An interface may appear in the returned interface list more than once. Base interfaces of explicitly implemented interfaces will be in the list. Consequently, it is not necessary to call ClassInformation2 again for each listed interface to retrieve the interfaces implemented by a superclass.

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