Re: JavaMemoryModel: Problem on single processor

From: Bill Pugh (pugh@cs.umd.edu)
Date: Thu May 25 2000 - 20:23:02 EDT


At 8:24 AM +1000 5/26/00, David Holmes wrote:
> > This does not work. According to both the existing specification, and
>> proposed new specifications, the write to singletons[i] can be moved
>> inside the synchronized block.
>
>It can? I am surprised in the sense that I view memory barriers as implicit
>code motion barriers and so, unless the compiler/JIT can be 100% certain
>that what it is doing is correct it should not move code across
>synchronization points.
>

Under the existing semantics, monitorenter and monitorexit act only
as one-way barriers, not full memory barriers. This is, in fact, the
right thing.

In particular, it is legal to reorder a load/store and a following
monitorenter, and it is legal to reorder a monitorexit and a
following load/store. (In other words, you can move stuff from
outside a synchronized block inside the block, but you can't move
stuff from inside to outside.

Changing the semantics to allow for removal of "useless"
synchronization will make it even weaker than that.

        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:25 EDT