Re: JavaMemoryModel: Finalizers

From: Bill Pugh (
Date: Sun Apr 06 2003 - 23:01:28 EDT

At 11:25 AM -0700 4/6/03, Joshua Bloch wrote:
> To echo Joe, I think the finalizer guardian idiom, whatever its
>other deficiencies, does not have the problem you suggest: it does
>use the implicit reference to its enclosing instance.

Yes, but the reference to the guardian is dead:

At 8:55 AM -0800 4/5/03, Joshua Bloch wrote:
>// Finalizer Guardian idiom
>public class Foo {
>// Sole purpose of this object is to finalize outer Foo object
>private final Object finalizerGuardian = new Object() {
>protected void finalize() throws Throwable {
>// Finalize outer Foo object
>... // Remainder omitted

While the this$0 field of the FinalizerGuardian class will be read,
the finalizerGuardian field of class Foo will never be read, the JVM
should be free to run the finalizer immediately.

Maybe this is too harsh. Maybe we need a rule that liveness
optimizations can only apply to methods variables, and that any
object reachable via a field of a reachable object is itself

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:43 EDT