Rewriting byte codes

Erik Corry erik at arbat.com
Tue Apr 2 03:29:22 PST 2002


On Mon, Apr 01, 2002 at 09:35:13AM +0200, Erik Corry wrote:
> 
> On Sun, Mar 31, 2002 at 03:40:48PM -0800, Jim Pick wrote:
>> 
>> Erik Corry wrote:
>>> What would be needed at a minimum would
>>> be:
>>> 
>>> * Split local variables that can be either reference or non-reference
>>>   into two.  (The alternative is to keep track of when they are what).
>> 
>> What do the other VMs with non-conservative GC do?
> 
> Hotspot splits them, but any VM needs to keep track of the stack.

I just had a neat idea:

Allocate on both sides of the local variable pointer.  Then you
can use negative offsets on instructions that use references and
positive offsets on instructions that use nonreferences.  All your
references are collected on one side of the local variable pointer.
You don't have to allocate twice as much space either if you compact
the local variables, which is a simple single-pass operation which
can never overflow the 256 or the 65536-variable boundaries.

The 'local variable map' for an entire method is then just a count
of reference local variables.  (You have to allocate 64 bits per
nonreference local variable though, otherwise it's not single pass,
but that's probably a good idea anyway due to alignment issues).

You can do something similar with the stack, but it's not quite as
neat, since you would probably rather like a single pointer to the
top-of-stack, and if you have separate reference and nonreference
stacks you need two top-of-stack pointers :-(  Also there are 
polymorphic bytecodes for the stack, like dup and swap, though
they could perhaps be replaced by monomorphic versions.

-- 
Erik Corry erik at arbat.com


More information about the kaffe mailing list