Bytecode Instrumentation
| 2004 JavaOne
SM
Conference | Session 3042 Copyright Hewlett Packard Co., 2004.
73
Bytecode sequence writing
•
It’s easy when you use:
java –jar bcel-5.1.jar
org.apache.bcel.util.BCELifier A1_mod.class
private void createMethod_1() {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(ACC_PUBLIC,
Type.VOID, Type.NO_ARGS, new String[] { },
"a1", "A1", il, _cp);
InstructionHandle ih_0 = il.append(new PUSH(_cp, 0)
);
il.append(new PUSH(_cp, 0));
il.append(_factory.createInvoke("MyMon",
"countMethodEntry", Type.VOID, newType[] {
Type.INT, Type.INT }, Constants.INVOKESTATIC));