JavaMemoryModel: Major yuck! GET/PUTSTATIC prohibits reordering

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


Consider the following classes:

class A {
  static int x = 1;
  }
class B {
  static int y = 2;
  static {
    A.x = 3;
    }
  }

and the expression A.x + B.y. Normally, you would think that
you would be able to reorder the reads of A.x and B.y. But, if
the expression is the very first reference to class B, then
the expression A.x + B.y should return 3. Reordering
the reads of A.x and B.y makes it return 5.

So, any GETSTATIC, PUTSTATIC, INVOKESTATIC or NEW that
might be the first reference to a class has to be treated
as a memory barrier and register flush, and you cannot reorder
it with any other instruction.

Yuck !

I feel ill. Somebody please tell me I'm wrong.....

        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