[jmm-dev] jdk9 APIs [Fences specifically]

Doug Lea dl at cs.oswego.edu
Sat Aug 15 11:47:01 UTC 2015

On 08/14/2015 09:14 PM, Hans Boehm wrote:

> thanks largely to Paul,
> memory_order_relaxed accesses are implicitly cache coherent.

Right. We cannot of course require this for plain Java variables
that otherwise correspond to C++ relaxed, so this remains
among the minor C++/Java memory-model-related usage differences.

Coherence would probably not be desirable in C++ either if some
form of opaque access methods were available, but it might be
too late to change that.

It might be worth contemplating adding C++ memory_order_opaque.
rather than relying on ill-defined C-volatile casts.
Or you could just rename memory_order_consume!

The resulting usages would correspond to opaque Java VarHandle
get/set methods, matching compatibility in expressiveness.

While conceived as a desperation move in both C++ and Java,
there's a sense in which this fits naturally as a fence/mode:
They all disallow transformations on reads/writes that are
otherwise allowed by the execution model.

Finding better names and actual specs might be slightly
challenging. The sense of "opaque" here is not obvious
to potential users, but the alternatives I've thought
of (like program_order) are worse in that they could be


More information about the jmm-dev mailing list