[Gc] Basic questions

Boehm, Hans hans_boehm@hp.com
Wed, 14 May 2003 11:43:50 -0700


> -----Original Message-----
> From: Fergus Henderson [mailto:fjh@cs.mu.oz.au]
> 
> On 14-May-2003, Boehm, Hans <hans_boehm@hp.com> wrote:
> > > -----Original Message-----
> > > From: Emmanuel Stapf [ES] [mailto:manus@eiffel.com]
> > > 
> > > Thanks for the detailed explanation. I feel that one could 
> > > make GC_malloc
> > > determine whether or not it should use its default 
> > > implementation or if it should
> > > be calling GC_malloc_ignore_off_page. The choice could be 
> > > made based on runtime
> > > configuration, no?
> >
> > The problem is that when you use GC_malloc_ignore_off_page(), you
> > promise that a pointer to (near) the base of the object will be
> > stored someplace where it's visible to the GC.  That's not 
> required for
> > a GC_malloc() call.
> 
> I think Emmanuel Stapf was referring to the case when 
> ALL_INTERIOR_POINTERS
> is not defined, in which case you do have that guarantee.
> 
Not entirely, unfortunately.  Without ALL_INTERIROR_POINTERS (really
GC_all_interior_pointers == 0 in newer collector versions), interior
pointers from the heap and static data are not recognized; interior
pointers from the stack and registers still are.

The issue really is if the last use of a large object pointed to by p
is in code like:

for (i = 0; i < limit; ++i) {
    use(p[i]);
}

and the compiler turns this into (or you manually turn it into)

my_limit = p + limit;
for (; p < my_limit; ++p) {
    use(*p);
}

If *p was allocated with GC_malloc in a default configured collector, this is
safe, with or without interior pointer recognition.  If you used
GC_malloc_ignore_off_page, you should really either make p volatile or insert
a reference to p[0] after the loop to minimize the chance of breakage.

(The real fix here is to have the compiler understand this and do the right thing
in the presence of a "conservative gc" flag.  The problem is that, at least in
the case of gcc, it doesn't break in practice, and hence nobody actually gets
around to doing this.)

Hans