I assume that the OS must support a mechanism to perform a global
memory barrier: something initiated by one thread, that forces all
threads to see the writes performed by the initiating thread. A local
memory barrier only forces a processor to become consistent with
global memory, not other processors.
Definition of strong class initialization safety -
add INVOKEVIRTUAL, INVOKESPECIAL, GETFIELD & PUTFIELD to instructions
that require a class to be initialized.
Make clear that if you check that a class is initialized, seeing
that the class has been initialized by another class must involve
seeing all writes done by the thread that initialized the class.
Efficient implementation
After class initializer is run, mark class as PBND
(prepared-but-not-distributed). Before creating an instance of a class
that is PBND, do a global memory barrier. When doing a global memory
barrier, update all classes that are PBND to PAD
(prepared-and-distributed).
If a class initialization check sees that a class is PAD, then no
memory barrier is needed. If it is PBND, then we can either do
a local memory barrier, or do a global memory barrier (changing the
status of the class (and others)).
If while a thread is initializing a class Foo, it sees a recursive
attempt to create a non-thread local instance of the class,
then it must
do a global memory barrier before the instance is created, but still
mark the class as PBND after the initializer runs. This barrier for
recursive creation only has to be done once (it guarantees that the
recursive creation can't allow another thread to see the class data
structures in a corrupted form.
Note: when doing a garbage collection, we can also change all classes
that are marked PBND to PAD.
Note: This handles the case where multiple classes are initialized
before an instance is created (e.g., superclasses) without requiring
a memory barrier for each, and also avoids
doing global memory barriers for abstract classes and interfaces.
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:18 EDT