Bytecode Instrumentation
| 2004 JavaOne
SM
Conference | Session 3042 Copyright Hewlett Packard Co., 2004.
62
MyTransformer.traceMethod() – 1
Create the instruction list
private static Method traceMethod(Method m, int methodIndex) {
Code code = m.getCode();
int flags = m.getAccessFlags();
String name = m.getName();
// Create instruction list to be inserted at method start.
InstructionList patch = new InstructionList();
patch.append(new PUSH(cp, 0));
patch.append(new PUSH(cp, methodIndex));
patch.append(new INVOKESTATIC(monitoringMethodToCall));
// Get the bytecode instruction list
MethodGen mg = new MethodGen(m, class_name, cp);
InstructionList il = mg.getInstructionList();
InstructionHandle[] ihs = il.getInstructionHandles();