Bytecode Instrumentation
| 2004 JavaOne
SM
Conference | Session 3042 Copyright Hewlett Packard Co., 2004.
31
Start-up Using JVMTI
•
Start-up
─ -agentlib:<agent-lib-name>=<options>
─ Agent_OnLoad() called when library loaded
─ Set-up the callbacks
jvmtiEventCallbacks callbacks;
Callbacks.ClassFileLoadHook =
&cbClassFileLoadHook
;
─ Load the java_crw_demo native BCI library
•
Application running
─ When class loaded (or reloaded):
─ Callback made to cbClassFileLoadHook()
– Generate unique class identification number
– Instrument bytecode
– Supply Java method(s) to call from instrumentation
– Return modified class file