Ganesh Kumar Choudhary | 6 Jun 2011 20:06
Picon

How to intercept field access using BCEL

Hi,

I have tried to intercept method calls by enhancing method body. Now I want
to intercept field access. I don't know how to do this. Can anyone help me
in this regard.

Thanks,
Ganesh

--

-- 
Man cannot discover new oceans unless he has the courage to lose sight of
the shore.
Zaree Faryal | 8 Jun 2011 07:44
Picon
Favicon

How to push a Custom Type Object on Stack

Hi

I know how to push Primitive Types on Stack using 
InstructinoList.append(new PUSH(ConstantPoolGen,343)); 

Now i want to push Custom Type Object(Obj of some user defined class i.e. Engine 
Class obj) on Stack in BCEL.

thanks
Zaree Faryal | 9 Jun 2011 08:38
Picon
Favicon

Re: How to push a Custom Type Object on Stack

What i want to do is i have a class 
class Automobile {

public void getEngine(int carNo,EngineClass engineClassObj){

System.out.println("EngineNo="+engineClassObj.sisNo);

}
}

Now when i load "Automobile" class  in  memory.
ilist = new InstructionList();
        ilist.append(InstructionConstants.ALOAD_0);
        ilist.append(new PUSH(pgen,345));
////Hear Now i have to also push the Object on Stack
        ilist.append(ifact.createInvoke(_invoking_ClassName, 
_invoking_MethodName, Type.INT,
           new Type[] { Type.INT,Type.OBJECT }, Constants.INVOKEVIRTUAL));
         ilist.append(InstructionConstants.IRETURN);

1-if i use createNew() method and generate new object then how i am going to 
fill its fields value?
2-or if i firstly push all fields values of Engine type Obj on Stack using PUSH 
then i can some how construct object on memory & then push it on Stack.
these are some solution i can think of.

so still need help...  

________________________________
From: Martin von Gagern <Martin.vGagern <at> gmx.net>
(Continue reading)

Martin von Gagern | 8 Jun 2011 11:04
Picon

Re: How to intercept field access using BCEL

Am 06.06.11 20:06, schrieb Ganesh Kumar Choudhary:
> I have tried to intercept method calls by enhancing method body. Now I want
> to intercept field access. I don't know how to do this. Can anyone help me
> in this regard.

You'll have to modify all classes that do access the field. You can
first examine the constant pool of every class, see if it refers to the
field (i.e. has a matching ConstantFieldref). If that is the case,
you'll have to process the bytecode for each method and insert
appropriate function calls before and/or after the field reference. Or,
as an alternative, replace the field load with a method call using some
BCEL-generated method to wrap the field access.

Martin von Gagern | 8 Jun 2011 08:24
Picon

Re: How to push a Custom Type Object on Stack

On 08.06.2011 07:44, Zaree Faryal wrote:
> I know how to push Primitive Types on Stack using 
> InstructinoList.append(new PUSH(ConstantPoolGen,343)); 
> 
> Now i want to push Custom Type Object(Obj of some user defined class i.e. Engine 
> Class obj) on Stack in BCEL.

Simply create the object; it will lie on the stack after creation until
you do something else with it. Or if you don't want to create it but
load it from some "static final" constant, then use GETSTATIC.

Martin

Martin von Gagern | 10 Jun 2011 08:24
Picon

Re: How to push a Custom Type Object on Stack

On 09.06.2011 08:38, Zaree Faryal wrote:
> What i want to do is i have a class 
> class Automobile {
>  public void getEngine(int carNo,EngineClass engineClassObj){
>   System.out.println("EngineNo="+engineClassObj.sisNo);
>  }
> }
> 
> /Now when i load "Automobile" class  in memory./
> ilist = new InstructionList();
>         ilist.append(InstructionConstants.ALOAD_0);
>         ilist.append(new PUSH(pgen,345));
> ////Hear Now i have to also push the Object on Stack/
>         ilist.append(ifact.createInvoke(_invoking_ClassName,
> _invoking_MethodName, Type.INT,
>            new Type[] { Type.INT,Type.OBJECT }, Constants.INVOKEVIRTUAL));
>          ilist.append(InstructionConstants.IRETURN);
> 
> 1-if i use createNew() method and generate new object then how i am
>   going to fill its fields value?
> 2-or if i firstly push all fields values of Engine type Obj on Stack
>   using PUSH then i can some how construct object on memory & then push it
>   on Stack.

I suggest you formulate how you'd create the object in Java, and then
simply run the resulting class through BCELifier to get an idea of how
the corresponding BCEL code would look like.

http://jakarta.apache.org/bcel/apidocs/org/apache/bcel/util/BCELifier.html

(Continue reading)

y a | 1 Jul 2011 09:50
Picon

instrumenting all variable access

HI there

I need to dynamically log all read/write access to any variables/objects
during class execution in the jvm
This is for a phd parallelism research, and i have a strong background in
C/java

a. Are there any existing code out there ?
I played with BCEL to trace some of the opcodes... nice stuff

b. Can someone recommend how to add some semantic info  from the .class
source file ?
For example, i would like to know if a certain variable is a for-loop
counter

Has anyone combined some of the syntax-tree parsers with BCEL ?

Thanks for any suggestions or input

yazriel atty  gmail dotty com

Gmane