|how to find gc roots in stack machine? firstname.lastname@example.org (2013-07-01)|
|Re: how to find gc roots in stack machine? email@example.com (Nils M Holm) (2013-07-01)|
|Re: how to find gc roots in stack machine? firstname.lastname@example.org (2013-07-01)|
|Re: how to find gc roots in stack machine? email@example.com (George Neuner) (2013-07-03)|
|Re: how to find gc roots in stack machine? firstname.lastname@example.org (George Neuner) (2013-07-04)|
|From:||"Nils M Holm" <email@example.com>|
|Date:||Mon, 1 Jul 2013 17:33:33 +0200|
|Posted-Date:||03 Jul 2013 22:40:23 EDT|
> I am writing a simple compiler for a simple stack machine. Now I want
> to add a garbage collector. To do this I need a way to be able to find
> all roots in the stack at any given time (or at least at some special
> points in time).
Basically any value on the stack is a potential root. The real problem
is to distinguish values that point to addresses in the address space
of the virtual machine from literal values (which do not point to any
address or to an address outside of the scope of the GC).
A common approach is to check whether a value on the stack is in the
(collectable part of the) address space of the VM. If so, treat it as
a root. This approach is simple and does not require any meta
information. The drawback is, of course, that it may mark objects that
are not longer used. This is called the "conservative" approach to GC.
The other variant, the "precise" approach, usually sacrifices one bit
of information per stack element. This bit is then used to indicate
whether or not that value points to an address.
The book "Garbage Collection" by Jones & Lins is still a valuable
resource on that topic.
Nils M Holm < n m h @ t 3 x . o r g > www.t3x.org
Return to the
Search the comp.compilers archives again.