[virtmach] VM with garbage collection

Chris Dollin virtmach@iecc.com
Fri, 11 Jan 2002 12:08:41 +0000

On Friday 11 January 2002 10:02, Stephan wrote:

> I am trying to build a VM for a garbage collected language.
> The byte code will typically contain many references to
> garbage collected objects. This means that the GC must be
> somehow able to distinguish bytecode instructions from
> pointers to GC-able objects.

> 2. Apparently, the Smalltalk 80 VM splits a code vector in 2 parts:
>    a part with the byte codes and a "constant vector" containing 
>    pointers to GCable objects. The bytecode contains indexes into
>    the constant vector. This leads to 1 extra redirection whenever
>    a GCable object has to be found. Moreover, it leads to problems
>    when there are more than 256 constants in a procedure.

This is the approach I took in my own VM (and I stole it from the
Poplog VM). The extra indirection seems to be an acceptable
cost (arguing without empirical evidence):

    * given the overheads of an interpreted VM, one extra
       indirection in the relevant instructions isn't much overhead

    * multiple references to the same object share the same index,
        so the code is smaller and more uniform

    * the GC code is decoupled from the instruction format

For technical reasons I was operating with some additional

    - all my instructions are 16 bits wide
    - an instruction has at most one "external" reference

I deat with the external reference limit by adding an additional
instruction, call it PBIC r (push bigly-indexed constant), which
added the topof-stack integer * sizeof rfield to r before using the
result as the index, thus deferring the problem to making big

Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html