Re: Stack map with AnalyzerAdapter

Eliot Moss <[email protected]> Wed, 19 Mar 2014 11:14:58 -0400
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
On 3/19/2014 9:43 AM, [email protected] wrote:
> Hello,
>
> I want to do a javaagent which is replacing primitive types by an object
> version. When I replace the primitive type double, I must instrument the
> instructions like DUP2 and verify on the top of the operand stack if the type
> is a double or an other like long.
>
> After the first visitFrame call, my stack representation in AnalyzerAdapter is
> false. I find the opcodes for DOUBLE (I have replace it by an object) and there
> is some TOP opcodes added.
>
> Is there a way to keep the stack map representation consistant when the
> primitives types are replaced?

You can tell your class writer to (re)generate the frame information
using ClassWriter.COMPUTE_FRAMES.  Depending, you might also want to
tell your ClassReader to SKIP_FRAMES.

I note, though, that in the case of doubles and longs, the size of
your values will be smaller (since a reference to a Double or Long
object is single size).  You will need to keep track of this so
that, for example, you rewrite a DUP2 after pushing a long (which
you change into a Long) to a DUP.  And so forth.  This is all
possible, but will take some work.  This suggests that you may
want for the ClassReader to supply frames to you with EXPAND_FRAMES
on and SKIP_FRAMES off, and then for you to manage a model of the
stack between calls to visitFrame.  Really all you will need is
an indication of which stack slots you shrank from two slots to
one.  I think you can avoid that with local variables, since it
will be clear that lstore, dstore, lload, and dload need to be
rewritten.  And don't forget ldc, of course.

Regards -- Eliot Moss
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws