Re: JavaMemoryModel: Problem on single processor

From: Bill Pugh (pugh@cs.umd.edu)
Date: Thu May 25 2000 - 22:07:52 EDT


At 10:56 AM +1000 5/26/00, David Holmes wrote:
> > 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.
>
>One would expect however that more general code motion is not allowed. For
>example, moving a method invocation from outside a synchronized block into
>the synchronized block - try figuring out where that deadlock came from ;-)

You may not reorder two monitorenter or two monitorexit instructions.

This, if you have:

foo();
synchronized(this) {
        bar();
        }

Then you cannot move the call to foo inside the synchronized region
unless you are guaranteed that foo with not perform any monitor
enter/exit instructions.

>
>Thinking further I am not at all happy with what you have suggested.

If your code is correctly synchronized, you won't be able to notice
the difference.

No one should be thinking of monitor enter/exit as a memory barrier,
and I would argue against adding explicit memory barriers to Java.

        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