[LLVMdev] Re: Garbage collection questions

Sandro Magi naasking at gmail.com
Thu Mar 9 13:18:39 PST 2006

I've written a reference-counting garbage collector for LLVM, but I'm
still unclear on a few things.

The following piece of code that appears on
http://llvm.cs.uiuc.edu/docs/GarbageCollection.html is unclear:

   ;; As the pointer goes out of scope, store a null value into
   ;; it, to indicate that the value is no longer live.
   store %Object* null, %Object** %X

How exactly does this indicate X is no longer live? Is this internal
code-generator logic/magic?

The problem I'm currently unsure of, is how roots would affect
refcounts. Should the gcread/gcwrite not be used with stack refs, etc?

1. If root refs are NOT included in the count, then objects of
refcount 0 must be tracked in a list of scheduled deletions, but will
be continually deferred until the root goes out of scope (the deletion
list is filtered during a collection by the roots callback).

2. If root refs ARE included in the count, then this deferral overhead
is avoided, at the expense of more refcount increment/decrement costs
(on entry and exit from each function).

I'm wondering which would be preferable. The collector is currently
written assuming #1 is the case, as this is what the docs seemed to
imply. Shall I just post the code?


More information about the llvm-dev mailing list