Manipulate JAVA thread stack in this way
2 Message(s) by 2 Author(s) originally posted in java machine
| From: Yao Qi |
Date: Monday, May 28, 2007
|
We are doing byte
code instrumentation, and at one moment (before call a
method, o.f(long);), the
stack layout of our
program thread is shown as follows,
top--> +--------+
| long |
+--------+
| Object |
+--------+
| ... |
we want to transform this stack layout to this, shown as follows, top--> +--------+
| Object |
+--------+
| long |
+--------+
| Object |
+--------+
| Object |
+--------+
| ... |
I read the
JVM spec on byte code instructions from
http://JAVA.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc3.html
but I still couldn't find a byte code sequence to transform stack
layout in this way.
Could anybody here give some advice on this problem? Thanks.
--
Yao Qi
<qiyaoltc@xxxxxxxxxxx> GNU/Linux Developer
http://duewayqi.googlepages.com/
Yevtushenko has... an ego that can crack crystal at a distance of twenty feet.
-- John Cheever
| From: Tom Hawtin |
Date: Monday, May 28, 2007
|
wrote in message:
top--> +--------+
| long |
long is two entries. This is the
real problem, as
swap wont work as
intended. (Not a popular piece of byte code design, but presumably a
bit
easier for interpreters on 32-bit systems.)
+--------+
| Object |
+--------+
| ... |
we want to transform this stack layout to this, shown as follows,
top--> +--------+
| Object |
+--------+
| long |
+--------+
| Object |
+--------+
| Object |
+--------+
| ... | So you've
..., C, B, A
where A and B are the long and C the reference, and you want
..., C, C, B, A, C
The trick is to use dup_x and then discard unwanted values.
So
..., C, B, A
dup2_x1
..., B, A, C, B, A
pop2
..., B, A, C
dup_x2
..., C, B, A, C
dup_x2
..., C, C, B, A, C
I think. (And make sure you set the max
frame size appropriately.)
If you are writing code from scratch, then local variables are very
useful. Probably not so convenient for instrumentation.
Tom Hawtin
Next Message: TF-IDF algorithm in JAVA
Blogs related to Manipulate JAVA thread stack in this way
An Archived Post…
But this little junker has one of the best ways possible for one to kill time while waiting for appointments: The
Java-based Bowling Game. Once again, I am not sophisticated enough for X-Box or Nintendo… I am more of a Pong kind of guy…
...