[concurrency-interest] question the about the JMM

David Holmes dcholmes at optusnet.com.au
Thu Dec 6 18:58:51 EST 2007

Larry Riedel wrote:
> If "x" is volatile though, I would expect the cache
> coherence protocol to make sure r3==1 if r2==1.

The cache coherence protocol knows nothing about "volatile". If x is
volatile then it is up to the VM to issue the right instructions to ensure
visibility whatever the coherence protocol is. On many systems the VM
doesn't have to do anything special for this to happen.

The problem with using "cache coherence" as a logical model for the JMM is
two-fold. First, it is insufficient as it doesn't address reorderings that
the runtime compiler is allowed to do. Second it leads people into false
conclusions because they apply knowledge of real cache coherency protocols
to the model eg:

1. The JMM says if "x" isn't volatile then it need get flushed to main
memory and so won't be visible.
2. My system (like most) uses a write-through cache and so visibility is
never a problem.
3. Therefore on my systems I don't need to use "volatile".

As I've said many times on this list now, the old JMM model based on "main
memory" and "flushing" was appealing in its simplicity and intuitiveness,
but it was an oversimplification that misleads people. If you only think in
terms of happens-before then you can't go wrong.

David Holmes

More information about the Concurrency-interest mailing list