Rewriting bytecode

Keith McGuigan Keith.McGuigan at Sun.COM
Thu Sep 3 11:53:47 PDT 2009


Nagy Mostafa wrote:
> Hi Everyone, 
> I am trying to re-write every method's bytecode right before it executes 
> to expand the opcode field to 4 bytes instead of 1. What is the best way 
> to do that ? From looking at the code, I am confused about the methodOop 
> layout and not sure how to do the resizing. Any code or documentation 
> pointers will be appreciated. 

Have you considered java.lang.Instrument to do this, instead of doing it 
in the VM?

If you must do it from with the VM, perhaps start with reading 
src/share/vm/prims/jvmtiRedefineClasses.hpp and go from there.

Changing the bytecode stream is tricky business, especially changing the 
length of it as you propose.  You'll have to update all jump updates and 
catch clause bounds (and line number tables, etc, if you're into the 
whole debugging thing);  and they'll of course be corner cases where the 
expanded code size (or jump offset) will overflow the storage that it's 
currently in and you'll have to rewrite some of the instructions to 
compensate.  It's all doable, I'm sure... but tricky.

What are you trying to accomplish?

--
- Keith


More information about the hotspot-dev mailing list