Related articles |
---|
how to find gc roots in stack machine? n.oje.bar@gmail.com (2013-07-01) |
Re: how to find gc roots in stack machine? nmh@t3x.org (Nils M Holm) (2013-07-01) |
Re: how to find gc roots in stack machine? anton@mips.complang.tuwien.ac.at (2013-07-01) |
Re: how to find gc roots in stack machine? gneuner2@comcast.net (George Neuner) (2013-07-03) |
Re: how to find gc roots in stack machine? gneuner2@comcast.net (George Neuner) (2013-07-04) |
From: | "Nils M Holm" <nmh@t3x.org> |
Newsgroups: | comp.compilers |
Date: | Mon, 1 Jul 2013 17:33:33 +0200 |
Organization: | Compilers Central |
Keywords: | GC, code |
Posted-Date: | 03 Jul 2013 22:40:23 EDT |
n.oje.bar@gmail.com:
> 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
comp.compilers page.
Search the
comp.compilers archives again.