Questions on jvm interpreter
Dmitry Samersoff
Dmitry.Samersoff at oracle.com
Fri Mar 30 01:51:56 PDT 2012
Saravanaraj,
Changing condition on fly is not a straightforward, (* but doable *)
because you have to change switch table as well as a number comparison
bytecodes.
Leaving out of scope licensing problem, you can try to use one of
existing decompiler to decompile a class file back to java and
change as match as you can off line.
Also you can consider to write a C code to manipulate bytecode instead
of using ASM - see see hprof in ivmti demo directory.
-Dmitry
On 2012-03-30 10:13, Saravanaraj Velusamy wrote:
> Dmitry et al,
>
> Thanks a ton for your inputs.
>
> I forgot to mention an important constraint. We will have access only to
> the compiled class file and not the source. So we are of the opinion
> that modifying jvm interpreter or the usage of low level bytecode
> manipulation library are our only options to solve the problem.
>
> Please correct, if our understanding is wrong.
>
> Regards,
> Saravanaraj
>
>
> On Fri, Mar 30, 2012 at 1:44 AM, Dmitry Samersoff
> <Dmitry.Samersoff at oracle.com <mailto:Dmitry.Samersoff at oracle.com>> wrote:
>
> Saravanaraj,
>
> I would recommend method below:
> 1. Add a static method to your class.
> Use value returned by this method to drive all conditions.
> 2. Use ASM library to change body of this static method as necessary
> in runtime.
>
> -Dmitry
>
>
> On 2012-03-29 20:48, Remi Forax wrote:
> > Take a look to java.lang.instrument that allow you to alter the
> bytecode
> > using by example ASM at runtime.
> >
> > Cheers,
> > Rémi
> >
> > Sent from my Phone
> >
> > ----- Reply message -----
> > From: "Saravanaraj Velusamy" <svelusa at ncsu.edu
> <mailto:svelusa at ncsu.edu>>
> > To: <distro-pkg-dev at openjdk.java.net
> <mailto:distro-pkg-dev at openjdk.java.net>>,
> > <hotspot-compiler-dev at openjdk.java.net
> <mailto:hotspot-compiler-dev at openjdk.java.net>>
> > Subject: Questions on jvm interpreter
> > Date: Thu, Mar 29, 2012 10:20
> >
> >
> > Hi All,
> >
> > We are trying to alter the branch conditions taken by a java
> program at
> > run time.
> >
> > For example if a Java code has conditions like this
> >
> > if( var == value1)
> > PATH1;
> > else
> > PATH2;
> >
> > Lets say we want to it take PATH2 (even though var might be equal to
> > value1). We might not change all branch statements in the class
> file and
> > we can assume there is another source (say a text file) which contains
> > what conditions needs to be changed.
> >
> > We have two ideas to do the same.
> > 1) To change the bytecode at that point during execution (like
> changing
> > if_icmpeq to if_icmpne)
> > 2) Find the place which contains the result of the first
> comparison and
> > complement the result of the comparison.
> >
> > The example has a simple conditional statement. We would also want to
> > consider loops, switch cases later.
> >
> > We would like to know what is the best way to go about and pointers in
> > the code related to this. We are currently looking into
> > bytecodeInterpreter.cpp of Zero instead of hotspot to avoid generated
> > assembly for interpreter.
> > Is there any way to find out the class file belonging to the current
> > opcode ? Since we are not interested in the standard Java class files
> > like String, Integer etc and focus on the ones from the User written
> > classes and methods.
> >
> > We have looked into BCEL, ASM, JVMTI and found out that we cannot
> change
> > the behavior at run time.
> >
> > Thanks in advance.
> > - Saravanaraj
>
>
> --
> Dmitry Samersoff
> Java Hotspot development team, SPB04
> * There will come soft rains ...
>
>
--
Dmitry Samersoff
Java Hotspot development team, SPB04
* There will come soft rains ...
More information about the hotspot-compiler-dev
mailing list