RE: JavaMemoryModel: Another Java threading issue (finalization)

From: Boehm, Hans (
Date: Tue Apr 01 2003 - 16:05:42 EST

> From: Jerry Schwarz []
> In short, I do not believe that unless we limit what constitutes an
> allowable optimization beyond its normal meaning (doesn't
> change the effect
> of the program) that we can ever guarantee that the output of
> the program
> is not
> finalizer called
> Say what you want
Do we agree that requiring an object to be reachable until the last time its lock is released is a sufficient limit on the optimizer?

Thinking about this some more, I think it also has the beneficial effect that we can delete the "Guarantees for finalizers" section from the memory model specification.

The right programming model for finalizers is clearly to synchronize both the finalizer and any other method that might be the last method call on an object. As Jerry has also pointed out, anything else is virtually guaranteed to be broken. This proposal guarantees that methodology to be correct, while making it clearer that it is essentially required.

If you use this methodology, any updates to the object are automatically visible in the finalizer, due to the synchronization. Hence, there should not be a real need to specifically say anything about finalizers in the memory model spec.

Thus I believe that including a reachability guarantee for synchronization would reduce the length of the overall spec, which would clearly be a good thing.

JavaMemoryModel mailing list -

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