JavaMemoryModel: Class initialisation procedure: locks vs. volatiles

From: David Holmes (dholmes@dltech.com.au)
Date: Sun Apr 13 2003 - 19:55:59 EDT


Section 2.17.5 of the JVMS describes in detail the process of class
initialization. It is expressed as a sequence of actions that involve
synchronizing on the Class object and checking the state of the class
and performing initialization as needed.

An obvious optimisation would be to declare the state of the class as
a volatile and hence allow a fast-path out of the initialization
process without needing to acquire the lock of the class object.

The new semantics for volatile would seem to make the optimisation
correct.

Can anyone see a problem with this optimisation?

If not, should "we" suggest an amendment to that section of the JVMS?

Thanks,

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:44 EDT