[gclist] Buffy finalizer slayer.

Charles Fiterman cef@geodesic.com
Fri, 11 Jun 1999 09:33:20 -0500


At 10:02 AM 6/11/99 -0400, David Chase wrote:
>At 08:03 AM 6/11/99 -0500, Charles Fiterman wrote:
>>So instead of running a finalizer lets send out a death notice. I call
>>objects receiving a death notice watcher objects. One way of building a
>>watcher object is to include a weak pointer to the object to be shut down.
>
>>Finalizers may allocate storage and trigger a collect from within the
>>collector.
>
>>Finalizer objects require extra collector overhead in a world where we are
>>judged by latency. Watcher objects run at the convenience of the mutator.
>
>You should probably go have a look at weak/soft/phantom references
>in the "Java 2" (aka jdk1.2) documentation.  However, I find these
>weak references are no easier or cheaper to implement than
>finalization.  It has also been our experience ("our" == me and
>colleagues) that Finalizer objects do not run "within" the collector;
>instead, the collector queues them and hands them off to the mutator,
>where they are run in one of a collection of threads designated
>for this purpose (not under user control, but not randomly chosen,
>either).

Java finalizers are unordered. The Boehm collector uses pointers to order
finalizers. This involves scanning finalizer objects and the things they
point to etc. Which is a lot of overhead especially if you have a long
chain of finalizer objects which only get run at one per collection by the
Boehm collector. I call this the billion dollar lottery bug.
Congratulations you've won dollar a year for a billion years but we've put
those dollar bills in a big stack and you've got to count through the stack
twice every year to get the one at the bottom.  

I think alphabetic by class name makes far more sense than topological
pointer order and alphabetic by class name is chosen to be ludicrous. But
alphabetic by class name has no cycles and the finalizers all get run when
their objects are discovered. Its simple to document and natural to use and
its n*log(n) rather than n*n in overhead and once your program works its
portable to other systems with no surprises. At one point I considered
giving objects finalizer order numbers they could manipulate. There are bad
problems when you hit true multiple inheritance, another bad mistake Java
avoided, I gave the notion up.