The IBM® SDK provides extensions to the JVMTI. The sample shows you how to write a simple JVMTI agent that uses these extensions.
The definitions you need when you write a JVMTI agent are provided in the header files jvmti.h and ibmjvmti.h. These files are in sdk/include.
This function is called by the JVM when the agent is loaded at JVM startup, which allows the JVMTI agent to modify JVM behavior before initialization is complete. The sample agent obtains access to the JVMTI interface using the JNI Invocation API function GetEnv(). The agent calls the APIs GetExtensionEvents() and GetExtensionFunctions() to find the JVMTI extensions supported by the JVM. These APIs provide access to the list of extensions available in the jvmtiExtensionEventInfo and jvmtiExtensionFunctionInfo structures. The sample uses an extension event and an extension function in the following way:
The sample JVMTI agent searches for the extension event VmDumpStart in the list of jvmtiExtensionEventInfo structures, using the identifier COM_IBM_VM_DUMP_START provided in ibmjvmti.h. When the event is found, the JVMTI agent calls the JVMTI interface SetExtensionEventCallback() to enable the event, providing a function DumpStartCallback() that is called when the event is triggered.
Next, the sample JVMTI agent searches for the extension function SetVMDump in the list of jvmtiExtensionFunctionInfo structures, using the identifier COM_IBM_SET_VM_DUMP provided in ibmjvmti.h. The JVMTI agent calls the function using the jvmtiExtensionFunction pointer to set a JVM dump option java:events=thrstart. This option requests the JVM to trigger a javadump every time a VM thread is started.
This callback function issues a message when the associated extension event is called. In the sample code, DumpStartCallback() is used when the VmDumpStart event is triggered.
cl /I<SDK_path>\include /MD /FetiSample.dll tiSample.c /link /DLLwhere <SDK_path> is the path to your SDK installation.
gcc -I<SDK_path>/include -o libtiSample.so -shared tiSample.cwhere <SDK_path> is the path to your SDK installation.
java -agentlib:tiSample -version
When the sample JVMTI agent loads, messages are generated. When the JVMTI agent initiates a javadump, the message JVMDUMP010 is issued.