As we've discussed, proper design of non-trival finalizers requires
However, the draft of the 2nd edition of the JLS says (Section 12.6, page 259):
"Also, the language does not specify which thread will invoke the finalizer."
That has to be changed. Otherwise, you can't guarantee that
synchronization in the finalizer actually enforces mutual exclusion.
For example, say a system statically determined the point on which
some thread local objects became garbage, and invoked the finalizers
inline (to allow the objects to be stack allocated). Then since the
finalizers are being run in the same thread as likely holds any locks
on the objects the finalizer is locking, the locks have no effect.
I think it would be OK to just change the spec to say:
"Finalizers are run in a thread that doesn't hold any locks at the
time the finalizers are invoked".
I think this is separate enough from the memory model issues that we
should fold it into the current JLS revision, rather than waiting for
the JMM JSR.
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:25 EDT