RE: JavaMemoryModel: First reason on broken Double Check Locking

From: David Holmes (dholmes@dltech.com.au)
Date: Tue Mar 12 2002 - 01:00:40 EST


Hanson wrote:
> So, doesn't the JVM spec clearly states that the newly constructed object
> must be complete in terms of it's initialization, BEFORE a reference is
> returned ? If so, the JVM must NOT perform a write action to the helper
> variable until all write actions for initializing the Helper object have
> completed.

Your "if so" statement does not necessarily follow from the preceding
statement. That section of the JVMS is describing the sequence of
initialization and construction from the perspective of the thread doing the
construction. That part of the spec does not explicitly say anything about
what other threads might see and when. The spec could have been written to
cover this case, eg. "For all threads in the VM construction of a new object
behaves as ...." but it wasn't written that way. You can interpret what is
written as being applicable to all threads, but there is nothing that forces
anyone else to interpret it that way. In particular the VM and JIT writers
don't see anything there that mandates the use of the memory barriers that
would be needed to avoid the problem. And in practice you don't want that
either.

These are the problems of a "specification" written in natural language.

David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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