[plt-scheme] Re: scheme_weak_reference and MZ_PRECISE_GC

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Sep 9 11:17:55 EDT 2008

At Tue, 09 Sep 2008 16:40:53 +0200, David Hansen wrote:
> On Tue, 9 Sep 2008 05:23:59 -0600 Matthew Flatt wrote:
> 
> > At Tue, 09 Sep 2008 10:57:01 +0200, David Hansen wrote:
> >> what's the alternative to scheme_weak_reference() if MZ_PRECISE_GC is
> >> defined?  Shall I use a finalizer and the fixup callback?  And how would
> >> I use the fixup callback?
> >
> > You can use scheme_make_weak_box() with both 3m and CGC.
> 
> Hmm, but that gives me another Scheme_Object*.  Now I need something to
> weak ref that ;-)

I guess the problem is that the GC can't see the reference to the
object? I can see how that would work with CGC, where objects don't
move and so the only reason the pointer needs to change is when it's
collected. But 3m needs to see all references to Scheme objects.

> OK, I could scheme_dont_gc_ptr() the weak box and scheme_gc_ptr_ok() the
> box in a finalizer of the value the box holds.

If I guess correctly about the situation, that wouldn't work, because
the weak box might move even if it isn't collected. But you could put
the weak box in an immobile box (allocated with
scheme_malloc_immobile_box), and so on.

> I want to keep track of Scheme_Object*s of a custom tagged type.

Do you just need a a weak hash table, where the sets of keys in the
table can act as a list of all the non-GCed objects?

> Can I
> do that from the fixup callback I pass to GC_register_traversers()?

If you know when a GC starts and when it ends, then you could record
all the pointers that are passed to the fixup function. That seems
relatively complicated, though, and I don't think there's currently a
way to know when a GC starts and ends.

> If so, how?  The documentation is a bit dense there.  In case the object
> moved, how do I get the old and new Scheme_Object*?

GC_fixup_self() can do that. It's mentioned in section 3.1.1, but I
should add an entry in the list of procedures.


Matthew



Posted on the users mailing list.