RE: JavaMemoryModel: Singleton question - and not about DCL!

From: David Holmes (
Date: Sun May 25 2003 - 21:27:18 EDT


> If so, is there an implicit memory read barrier on *every*
> static method call? Or is it only the first static method
> call to any particular class from any particular thread?

The class loading/linking and initialization process is specified such
that each thread must acquire the lock of the Class object to check if
the given class has been initialized before an "active use" of that
class occurs. Hence there is an initial "memory barrier" in each
thread. Of course once the VM knows that a given thread has done this
and found the class initialized then no subsequent locking/barriers
are needed.

I suggested in another thread that we should relax the locking
requirements of class initialization to that of checking a volatile
isInitialized field. That would make it unnecessary for every thread
to lock the Class object, whilst still maintaining the necessary
visibility/ordering controls. The lock would still be used for actual
initialization of course. (A correct DCL struture using volatiles).

David Holmes

JavaMemoryModel mailing list -

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