Re: JavaMemoryModel: Revised report on the Java Memory Model

From: Clifford Click (cliff.click@sun.com)
Date: Wed Dec 12 2001 - 14:22:21 EST


Bill Pugh wrote:
>
> We've put a revised version of our proposal on the Java Memory Model
> on our web page:
> http://www.cs.umd.edu/~pugh/java/memoryModel/semantics.pdf

"The fact that two variables may be stored in adjacent bytes is immaterial.
 Two variables can be simultaneously updated by different threads without
 needing to use synchronization to account for the fact that they are adjacent."

If I make an optimization to combine stores to adjacent fields,
does it break this?
  e.g.:
    class foo {
      byte x, other, y;
      void m() {
        x = 1; y = 2;
      }
    }
emits code as:
  ld-8bits adr-other into Rtmp
  Rtmp <<= 8
  Rtmp |= 0x010002
  store-32bits adr-x, Rtmp

Can some other thread be upset when I smack 'other' back to it's old value?
Seem's like the answer should be Yes.

Case 2:
      void m() {
        byte tmp = other; other = tmp;
        x = 1; y = 2;
      }

Now I've textually got a useless store, so another thread writing
means a race-condition so this optimization becomes legit, right?

Thanks,
Cliff

Cliff Click Compiler Designer and Researcher
cliffc at acm.org Java Software
(408) 276-7046 MS USCA14-102
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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