[concurrency-interest] jdk9 VarHandle and Fence methods

Andrew Haley aph at redhat.com
Thu Sep 3 14:45:22 EDT 2015

On 08/22/2015 07:15 PM, Vitaly Davidovich wrote:

> I would hope there's no ordering difference between successful and
> unsuccessful CAS.  On x86/64 the instruction itself provides full
> fence irrespective of outcome; compiler doesn't know a priori
> whether it will succeed or not.

Right, but that's a side-effect of the implementation, not a
specification.  The specification says it's a volatile load followed
by a volatile store, and that's all we can assume.  It should be made
plain that if the store does not happen, the store fence doesn't
happen either.  It would be an extremely strange program which relied
on a failed store to have the side-effects of a volatile store.

> Are there platforms where the lowering of the CAS has different cpu
> ordering based on outcome?

Yes.  On AArch64 (and probably every other processor) a Store-Release
Exclusive instruction only has the release semantics if the store is

> LL/SC can fail if cacheline is modified in between (even if value is
> still the expected one) but I'm not aware of that changing ordering
> semantics.  However, if there are cases where this would matter, I
> hope the JVM ensures the requested ordering irrespective of outcome.

I hope so too, but I don't want to see pointless extra memory
barriers.  I don't think that most algorithms will ever need them.


More information about the Concurrency-interest mailing list