Hi!

 

I am trying to use LookupSwitch to transforming a previous created class
adding a new variable (�localPC�) and jump to specific locations in each
class method depending on �localPC�. The problem is that execution is not
going to where it should after LookupSwitch. Could anyone help me?

 

Here is the BCEL code (for simplicity, �localPC� is set to zero): 

 

Method[] methods = Repository.lookupClass(�MyClass�).getMethods();

ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());

for(int i=1; i < methods.length; i++) {

    MethodGen mg = new MethodGen(methods[i], clazz.getClassName(), cp);

    InstructionList il = mg.getInstructionList();

    LocalVariableGen lg = mg.addLocalVariable("localPC", Type.INT, null,
null); 

    int index = lg.getIndex();

    �

    il.insert(new LOOKUPSWITCH(matchs, targets, defaultTarget));


    il.insert(new ILOAD(index));

    il.insert(new ISTORE(index));

    il.insert(new ICONST(0)); 

 

    mg.setMaxStack();

    mg.setMaxLocals();

    il.dispose();

}

 

The bytecode stays like this (using javap):

 

   0: iconst_0

   1: istore_2

   2: iload_2

   3: lookupswitch{ //7

            68: 68;

            69: 69;

            70: 70;

            71: 71;

            74: 74;

            75: 75;

            78: 78;

            default: 68 }

   68:      iconst_0  //other Variable

   69:      istore_1  //Other Variable

 

I got Verifier error and can�t understand what is wrong. Using JustIce
showed me that the execution is not going to where it should be after
lookupswitch and the stack is being empty after that�

 

VERIFIED_REJECTED

Constraint violated in method 'my_method()':

Instruction ISTORE constraint violated: Cannot consume 1 stack slots: only 0
slot(s) left on stack!

Stack:

Slots used: 0 MaxStack: 1.

 

InstructionHandle:   69: istore_1[60](1)

 

Execution Frame:

Local Variables:

0: MyClass

1: <unknown object>

2: int

OperandStack:

Slots used: 0 MaxStack: 1.

Execution flow:

   0: iconst_0    [InstructionContext]

   1: istore_2    [InstructionContext]

   2: iload_2     [InstructionContext]

   3: lookupswitch -> 68 ... [InstructionContext]

  69: istore_1    [InstructionContext]

 

Shouldn�t the execution go to 68 and not to 69!!!!!!???? I think that this
is the problem with the stack.

 

Thanks a lot,

 

Giovanni

 

Reply via email to