[Gc] Defeating finalization

Boehm, Hans hans.boehm at hp.com
Thu Apr 20 13:06:34 PDT 2006


It appears to me that what you are proposing should work fine.  To faithfully implement guardians, I think you need GC_register_finalizer_no_order.  (I personally don't believe that's a wise design choice, even though it appears to deal withy cyclic finalization.  Which explains why the documentation tends to discourage it.)

Note that neither [0] nor our current GC implementation pays sufficient attention to what I would now consider to be by far the most serious issue with finalizers/guardians/weak-pointers/...:  Objects may be unreachable while one of their methods (or a function taking the object as a parameter) is still running and accessing some external state associated with the object.  See for example the slides at http://www.hpl.hp.com/personal/Hans_Boehm/misc_slides/java_finalizers.pdf .

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com 
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Ludovic Courtès
> Sent: Thursday, April 20, 2006 6:28 AM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Defeating finalization
> 
> Hi,
> 
> I'm looking for a way to implement guardians [0] on top of 
> `libgc'.  One solution I thought of is the following:
> 
>   1. Register a finalization function for each guarded object;
> 
>   2. Whenever that function is called, have it store a pointer to the
>      object being finalized in a list of ``zombie'' objects that the
>      guardian can eventually return to user code.  Roughly, the
>      finalization procedure would look like the following:
> 
>        static void
>        my_fake_finalizer (GC_PTR obj, GC_PTR client_data)
>        {
>          enqueue (&zombie_list, obj);
>        }
> 
> 
> The obvious question is: Is this permitted?  IOW, what 
> happens if a finalizer creates new references to an object 
> being finalized?
> 
> Thanks,
> Ludovic.
> 
> 
> [0] R. Kent Dybvig et al., "Guardians in a Generation-Based Garbage
>     Collector", ACM SIGPLAN Conference on Programming Language Design
>     and Implementation, June 1993,
>     http://www.cs.indiana.edu/~dyb/papers/guardians-pldi93.ps.gz .
> 
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list