Re: JavaMemoryModel: Major yuck! GET/PUTSTATIC prohibits reordering

From: Bill Pugh (pugh@cs.umd.edu)
Date: Thu Nov 11 1999 - 22:34:33 EST


The example I'd given previously could be fixed by changing the spec
to allow class initializers to happen early.

But here is an example for which that fix doesn't work:

class A {
   static int [] a = new int[10];
   static { B.b = new int[10]; }
   }
class B {
   static int [] b;
   }

Under the existing semantics, A.a[0] + B.b[0] is guaranteed to return 0, while
if a compiler reorders the reads of A.a and B.b, it will get a null
pointer exception. In this case, the reordering makes the class
initializer for A run too late.

I think the fix for this is going to be to check to see which classes
have static initializers who's effect can be seen outside the class.
If the static initializer effects only the static variables of the
class, then I think it can be reordered. Otherwise, ...

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



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