[jmm-dev] jdk9 APIs (CAS)

Doug Lea dl at cs.oswego.edu
Wed Aug 19 11:44:58 UTC 2015

Thanks to Cliff Click for prodding me to realize that the signatures
for new analogs of C/C++ moded CAS should, like those versions, return
values not booleans (i.e, on failure, the value causing CAS to fail,
else the given value). And renamed to compareAndExchange to better
convey this. (Only 6 of the possible mode X weakness cases make sense,)
Any objections?

The current tentative VarHandles API looks like:

abstract class NotReallyVarHandle<T> {
     // Load

     T getRelaxed(Object owner);
     T getAcquire(Object owner);
     T getVolatile(Object owner);
     T getOpaque((Object owner);

     // Store

     void setRelaxed(Object owner, T val);
     void setRelease(Object owner, T val);
     void setVolatile(Object owner, T val);
     void setOpaque(Object owner, T val);

     // CAS
     boolean compareAndSet(Object owner, T cmp, T val);

     // Value-returning compare and exchange

     T compareAndExchangeVolatile(Object owner, T cmp, T val);
     T compareAndExchangeAcquire(Object owner, T cmp, T val);
     T compareAndExchangeRelease(Object owner, T cmp, T val);

     T weakCompareAndExchangeRelaxed(Object owner, T cmp, T val);
     T weakCompareAndExchangeAcquire(Object owner, T cmp, T val);
     T weakCompareAndExchangeRelease(Object owner, T cmp, T val);

     // special RMW

     T getAndSet(Object owner, T val);
     T getAndAdd(Object owner, T delta);
     T addAndGet(Object owner, T delta);

More information about the jmm-dev mailing list