Re: About the volatile and MESI Protocal

Florian Weimer via Concurrency-interest <[email protected]> Sat, 19 Feb 2022 11:30:19 +0100
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <[email protected]>
* Nathan Reynolds via Concurrency-interest:

> Without volatile or fences, JIT is free to hoist the "if (bChanged ==
> !bChanged)" out of the for loop.  If for some reason JIT decides to not
> hoist, JIT could also load bChanged into a single register each iteration
> and then execute "if (bChanged == !bChanged)" using the value in the single
> register.  On the other hand, if JIT is smart enough, it can get rid of the
> if statement and block altogether since it can never be true according to
> the Java Memory Model.  Since this is very unlike a real code scenario, I
> doubt JIT has been enhanced for this last case.

I don't think this is a property of the memory model, it merely
follows from choices Java implementation have made regarding compiler
barriers for volatile field access.