You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by kalyan ram <ck...@yahoo.com> on 2003/06/15 22:45:04 UTC

help with the bcel

Hai
     I am trying to write a program using bcel api
such the before every method first statement,an object
call abc will be created and it will call a method
runCode().
     class Test
      {
            public static void main()
            {
               Instrument abc = new Instrument();
                abc.runCode();
             }
       }
I followed  the sample HelloWorldBuilder.java program
but I am getting verifier error saying Illegal
constant pool index.I have the Instrument.class which
has runCode method in the same directory as Test
class.
The code is enclosed -  the following code executes
for every method.
/////////////////////////////////////////////
InstructionFactory factory = new InstructionFacto(cg);
InstructionList il = new InstructionList();
// create instrumentor object and store it in local
variable abc
il.append(factory.createNew("Instrument"));
il.append(InstructionConstants.DUP);
//call instrumentor
il.append(factory.createInvoke("Instrument","<init>",Type.VOID,Type.NO_ARGS,Constants.INVOKESPECIAL));
		
//create a local variable
LocalVariableGen lg = mg.addLocalVariable("abc",new
ObjectType("Instrument"),null,null);
int abc = lg.getIndex();
//il.append(InstructionConstants.ACONST_NULL);
lg.setStart(il.append(new ASTORE(abc))); //abc should
be available from here
  			
 il.append(new ALOAD(abc));

il.append(factory.createInvoke("Instrument","runCode",Type.VOID,Type.NO_ARGS,Constants.INVOKEVIRTUAL));
InstructionList il1  = mg.getInstructionList();
InstructionHandle[] ihs = il1.getInstructionHandles();

/* Instrument method start */
 il1.insert(ihs[0],il);
/////////////////////////////////////////////////
What all i am trying to do is:
Instrument abc = new Instrument();
abc.runCode();
at the beginning of evry method.

The error is :
Exception in thread "main" java.lang.VerifyError:
(class: Test, method: main signature:
([Ljava/lang/String;)V) Illegal
type in constant pool

I am really stuck at this...Please help me out.Your
help is highly appreciated.

Thank you
Ram

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


RE: help with the bcel

Posted by "Shah, Sapan" <sa...@patni.com>.
Yes, I think, it will be easily achieved using AOP.

-----Original Message-----
From: Ishaaq Chandy [mailto:ishaaqchandy@yahoo.com]
Sent: Wednesday, June 18, 2003 8:54 AM
To: BCEL Users List
Subject: Re: help with the bcel


Isn't something like this more easily implemented
using AspectJ (http://www.eclipse.org/aspectj)?


--- kalyan ram <ck...@yahoo.com> wrote:
> Hai
>      I am trying to write a program using bcel api
> such the before every method first statement,an
> object
> call abc will be created and it will call a method
> runCode().
>      class Test
>       {
>             public static void main()
>             {
>                Instrument abc = new Instrument();
>                 abc.runCode();
>              }
>        }
> I followed  the sample HelloWorldBuilder.java
> program
> but I am getting verifier error saying Illegal
> constant pool index.I have the Instrument.class
> which
> has runCode method in the same directory as Test
> class.
> The code is enclosed -  the following code executes
> for every method.
> /////////////////////////////////////////////
> InstructionFactory factory = new
> InstructionFacto(cg);
> InstructionList il = new InstructionList();
> // create instrumentor object and store it in local
> variable abc
> il.append(factory.createNew("Instrument"));
> il.append(InstructionConstants.DUP);
> //call instrumentor
>
il.append(factory.createInvoke("Instrument","<init>",Type.VOID,Type.NO_ARGS,
Constants.INVOKESPECIAL));
>
> //create a local variable
> LocalVariableGen lg = mg.addLocalVariable("abc",new
> ObjectType("Instrument"),null,null);
> int abc = lg.getIndex();
> //il.append(InstructionConstants.ACONST_NULL);
> lg.setStart(il.append(new ASTORE(abc))); //abc
> should
> be available from here
>
>  il.append(new ALOAD(abc));
>
>
il.append(factory.createInvoke("Instrument","runCode",Type.VOID,Type.NO_ARGS
,Constants.INVOKEVIRTUAL));
> InstructionList il1  = mg.getInstructionList();
> InstructionHandle[] ihs =
> il1.getInstructionHandles();
>
> /* Instrument method start */
>  il1.insert(ihs[0],il);
> /////////////////////////////////////////////////
> What all i am trying to do is:
> Instrument abc = new Instrument();
> abc.runCode();
> at the beginning of evry method.
>
> The error is :
> Exception in thread "main" java.lang.VerifyError:
> (class: Test, method: main signature:
> ([Ljava/lang/String;)V) Illegal
> type in constant pool
>
> I am really stuck at this...Please help me out.Your
> help is highly appreciated.
>
> Thank you
> Ram
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> bcel-user-help@jakarta.apache.org
>


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Re: help with the bcel

Posted by Ishaaq Chandy <is...@yahoo.com>.
Isn't something like this more easily implemented
using AspectJ (http://www.eclipse.org/aspectj)?


--- kalyan ram <ck...@yahoo.com> wrote:
> Hai
>      I am trying to write a program using bcel api
> such the before every method first statement,an
> object
> call abc will be created and it will call a method
> runCode().
>      class Test
>       {
>             public static void main()
>             {
>                Instrument abc = new Instrument();
>                 abc.runCode();
>              }
>        }
> I followed  the sample HelloWorldBuilder.java
> program
> but I am getting verifier error saying Illegal
> constant pool index.I have the Instrument.class
> which
> has runCode method in the same directory as Test
> class.
> The code is enclosed -  the following code executes
> for every method.
> /////////////////////////////////////////////
> InstructionFactory factory = new
> InstructionFacto(cg);
> InstructionList il = new InstructionList();
> // create instrumentor object and store it in local
> variable abc
> il.append(factory.createNew("Instrument"));
> il.append(InstructionConstants.DUP);
> //call instrumentor
>
il.append(factory.createInvoke("Instrument","<init>",Type.VOID,Type.NO_ARGS,Constants.INVOKESPECIAL));
> 		
> //create a local variable
> LocalVariableGen lg = mg.addLocalVariable("abc",new
> ObjectType("Instrument"),null,null);
> int abc = lg.getIndex();
> //il.append(InstructionConstants.ACONST_NULL);
> lg.setStart(il.append(new ASTORE(abc))); //abc
> should
> be available from here
>   			
>  il.append(new ALOAD(abc));
> 
>
il.append(factory.createInvoke("Instrument","runCode",Type.VOID,Type.NO_ARGS,Constants.INVOKEVIRTUAL));
> InstructionList il1  = mg.getInstructionList();
> InstructionHandle[] ihs =
> il1.getInstructionHandles();
> 
> /* Instrument method start */
>  il1.insert(ihs[0],il);
> /////////////////////////////////////////////////
> What all i am trying to do is:
> Instrument abc = new Instrument();
> abc.runCode();
> at the beginning of evry method.
> 
> The error is :
> Exception in thread "main" java.lang.VerifyError:
> (class: Test, method: main signature:
> ([Ljava/lang/String;)V) Illegal
> type in constant pool
> 
> I am really stuck at this...Please help me out.Your
> help is highly appreciated.
> 
> Thank you
> Ram
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> bcel-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org