Bytecode Instrumentation
| 2004 JavaOne
SM
Conference | Session 3042 Copyright Hewlett Packard Co., 2004.
63
MyTransformer.traceMethod() – 2
Insert the bytecodes and update stack
// First let the super or other constructor be called
if(name.equals("")) {
for(int j=1; j < ihs.length; j++) {
if(ihs[j].getInstruction() instanceof INVOKESPECIAL) {
il.append(ihs[j], patch);
break;
}
}
}
else {
il.insert(ihs[0], patch); // Insert the instructions!!
}
// Update stack size
if(code.getMaxStack() < 2) {
mg.setMaxStack(2);
}
return mg.getMethod();
}