JavaMemoryModel: finalization

From: Bill Pugh (
Date: Fri Apr 04 2003 - 16:57:10 EST

Sorry to have sat out on much of this discussion. I haven't read
through every posting, so let me know if I missed out on some
important point.

My 2 cents:

First, I think we clearly need to have the following requirements:

* The finalizer sees all writes that are happen before the end
   of the constructor.

* The finalizer sees all writes to fields of the object that occur before
   the finalizer is invoked.

I don't think we want or need any additional rules.

At 12:07 PM -0800 3/20/03, Boehm, Hans wrote:
>2) We should add a constraint that any object is reachable (for
>finalization/GC purposes) when its lock is released. Since prior
>memory references are ordered before the lock release, that should
>ensure that visible operations on A[x_index] are complete before the
>finalizer runs.

If the finalizer is synchronized, you will get this guarantee automatically.

And I don't see any problem with requiring that people use
synchronization in their finalizers.

Since we want to allow compilers to be able to remove useless
synchronization, we shouldn't enforce any other semantics (such as
guaranteeing liveness) for useless synchronization.

At 12:07 PM -0800 3/20/03, Boehm, Hans wrote:
>- If Object x refers to object y via a final or volatile field and x
>is reachable, then y must be reachable.

No. I think we want to allow the compiler to remove unused fields.

If you want to guarantee visibility for finalization, another
alternative is to have a volatile field that is written at the end of
every method, and that is read at the beginning of the finalizer.

No operations before the write to the volatile field can be reordered
with the volatile write, and the finalizer cannot be invoked until
after the volatile write has been performed. And all of the writes in
any of the methods will be visible to the finalizer.


JavaMemoryModel mailing list -

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