Re: Good strategy for determining root set in C++

"Campbell, Matt" <[email protected]> Fri, 14 Apr 2006 01:06:16 -0400
Newsgroups gmane.comp.programming.garbage-collection.general
Message-ID <[email protected]>
Hi,

Yes, unfortunantly I understand this could never be an ideal solution.  As for using a non-moving collector, I already assumed that could not be done, at least in a C++ implementation.  I have read through papers and some source code on the Boehm collector so I am familiar with that. (Well, at least, the concepts).  I was trying to parse through the code to figure out how they are determining root sets, but the code isn't exactly the easiest to read in places.  I certainly do not want to hack the compiler either. :-)

In any case, thanks for the feedback.  Do you have any insight to offer as to how the boehm collector is determining the root sets.  I understand that I have to check each word in the stack and data segment to see if it is in the managed heap, etc. but I wasn't sure how to get the starting and ending addresses of those particular locations.

Thanks again, and I found it interesting that GCJ uses a conservative collector.  I didn't know that!

-Matt


-----Original Message-----
From: Eliot Moss [mailto:[email protected]]
Sent: Thu 4/13/2006 9:50 PM
To: Campbell, Matt
Cc: [email protected]
Subject: [gclist] Good strategy for determining root set in C++
 
Just a very quick answer, Matthew ....

C++ would generally be called an "uncooperative" language for GC. The
compiler basically is not going to help you. Which means you have to code
it in somehow, assuming you want accurate root sets. If you are willing to
go for assuming that anything that looks like a root is a root, as in the
Boehm-Demers-Weiser method (often called the "Boehm collector"), then that
is a less intrusive technique, but restricts you to non-moving collection,
at least for objects referenced ambiguously from roots.

In theory one could hack the compiler to tell you more, but it would fail
for some programs, e.g., if they do their own address arithmetic or do
funky pointer encodings (rare, but possible).

Java systems (for example) generally build the support in (but gcj, built
basically as a front-end to gcc, uses the Boehm collector because the
compiler back-end does not do the work necessary to identify pointers
unambiguously).

Put another way, I consider it more a compiler issue than a language issue,
though both play a part, and the tradition has never built up for GC for C
and C++.

-- Eliot Moss
==============================================================================
J. Eliot B. Moss, Associate Professor     http://www.cs.umass.edu/~moss    www
Director, Arch. and Lang. Impl. Lab.      +1-413-545-4206                voice
Department of Computer Science            +1-413-695-4226                 cell
140 Governor's Drive, Room 372            +1-413-545-1249                  fax
University of Massachusetts at Amherst    [email protected]              email
Amherst, MA  01003-9264  USA              +1-413-545-3733 Priscilla Coe  sec'y
==============================================================================