Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / May 2007

Tip: Looking for answers? Try searching our database.

Manipulate java thread stack in this way

Thread view: 
Yao Qi - 28 May 2007 18:28 GMT
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 could not find a byte code sequence to transform stack
layout in this way.

Could anybody here give some advice on this problem?  Thanks.

Signature

Yao Qi <qiyaoltc@gmail.com>    GNU/Linux Developer
http://duewayqi.googlepages.com/

Yevtushenko has... an ego that can crack crystal at a distance of twenty feet.
        -- John Cheever

Tom Hawtin - 28 May 2007 23:25 GMT
>    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 |
[quoted text clipped - 13 lines]
>             +--------+
>             |  ...   |

So you have

..., 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.