Re: JavaMemoryModel: Revised report on the Java Memory Model

From: Bill Pugh (pugh@cs.umd.edu)
Date: Thu Dec 13 2001 - 11:20:36 EST


At 11:22 AM -0800 12/12/01, Clifford Click wrote:
>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.

Yes. This code would be illegal, because it could cause an
modification to other to be lost.

>
>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?
>

It would be legal in this case.

        Bill



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