Re: Making operand stack copy

Andrew Huntwork <[email protected]>
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
yes you can.  but how hard it's going to be depends on your exact problem.

If you want to save function arguments, it's easy, because you already 
know the types of the arguments and you can generate the appropriate 
load instructions using getArgumentTypes and 
InstructionFactory.createStore.

If on the other hand you want to save the whole stack, you have problems:

f(a,b?c(d) : e,g,h,i)

if you want to save the stack before calling c, it has at least one 
object a on it that's not an argument to your function, so it's 
difficult to know what instructions to generate to correctly save the 
entire stack.

But it's not impossible.  BCEL implements a bytecode verifier that 
definitely knows for every instruction everything that's on the stack. 
You can probably use 
org.apache.bcel.verifier.structurals.ControlFlowGraph and some 
modification of ExecutionVisitor.

Alternatively, SandMark, which uses BCEL, has a StackSimulator* object 
that's specifically for finding out this type of information.  sandmark 
does this save and restore operation in many places.  ask on 
[email protected] for help with sandmark.

[*] 
http://cgi.cs.arizona.edu/~sandmark/SandMark3.1.1/API/sandmark/util/stacksimulator/StackSimulator.html

(no, sandmark does not still use old (de.fub.bytecode) bcel, these are 
just old javadocs)

Shrinivas Balkrishna Joshi wrote:
> Hi All,
>   I want to know if one can use BCEL to make a copy of JVM operand stack.
> Actually I want to save parameters being passed to a particular function
> before the function is called. If there are less than 3 parameters I can
> use DUP instruction to create copy of stack values and save the arguments.
> However, this method wont help in function calls involving more than 3
> parameters. So I was just wondering whether one can make a copy of whole
> stack at a particular instance of program execution and manipulate it
> using BCELA API.
> Thanking you in anticipation
> -Shrinivas Joshi ([email protected])
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.