[prev in list] [next in list] [prev in thread] [next in thread]
List: bcel-user
Subject: Problems adding IF into a bytecode class
From: Marco Bessi <bessimarco () gmail ! com>
Date: 2010-09-01 14:29:54
Message-ID: AANLkTin_xcpjA_M7u2i-43PfDrzy+0otbU0tNFdY2jAd () mail ! gmail ! com
[Download RAW message or body]
Hi to all,
I need to insert the followings bytecode instructions inside a method of a
.class file.
if(a == null){ //a is an object
Classe.staticMethod();
}
long x = System.nanoTime();
I try two way but I have always an Exception.!
TRY 1: (I create a InstructionList (ilFirst) where I insert the followings
instructions.)
InstructionList ilFirst = new InstructionList();
ilFirst.append(new ALOAD(a));
Instruction invokeInterIF = factory.createInvoke("memory.Classe",
"staticMethod", Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC);
ilFirst.append(invokeInterIF);
InstructionHandle ihEndIF =
ilFirst.append(factory.createInvoke("java.lang.System", "nanoTime",
Type.LONG, Type.NO_ARGS, Constants.INVOKESTATIC));
ilFirst.insert(invokeInterIF, new IFNULL(ihEndIF));
[continue]
TRY 2: (I create a InstructionList (ilFirst) where I insert the followings
instructions. I create another InstructionList (ilThanIf ) to insert the
instructions inside the IF)
InstructionList ilFirst = new InstructionList();
ilFirst.append(new ALOAD(a));
InstructionList ilThanIf = new InstructionList();
ilThanIf.insert(factory.createInvoke("memory.Classe", "staticMethod",
Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC));
ilFirst.append(InstructionFactory.createBranchInstruction((short) 199,
ilThanIf.getStart())); //IFNONNULL
ilFirst.append(factory.createInvoke("java.lang.System", "nanoTime",
Type.LONG, Type.NO_ARGS, Constants.INVOKESTATIC));
[continue]
The Exception is:
- TRY1:
Exception in thread "AWT-EventQueue-0"
org.apache.bcel.generic.ClassGenException: Assigning branch instruction
ifnull[198](3) -> invokestatic 110 to plain handle
-TRY 2:
Exception in thread "AWT-EventQueue-0"
org.apache.bcel.generic.ClassGenException: Invalid branch target position
offset for ifnonnull[199](3):-1: -1: invokestatic[184](3) 89
There are someone that know I can solve this problem? I haven't found
anything in the web about the InstructionHandle. I suppose that the problem
is there because the exceptions are on the IFNULL() or IFNONNULL() that
wants a InstructionHandle for parameter!
Thanks.
Marco.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic