[jmm-dev] jdk9 APIs

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Aug 12 08:31:18 UTC 2015

On 08/10/2015 09:22 PM, Doug Lea wrote:
> /**
>  * Stand-in for spec purposes of jdk9 java.lang.invoke.VarHandle
>  */
> abstract class NotReallyVarHandle<T> {
>     boolean weakCompareAndSet(Object owner, T cmp, T val);
>     boolean weakCompareAndSetAcquire(Object owner, T cmp, T val);
>     boolean weakCompareAndSetRelease(Object owner, T cmp, T val);

I have a question about these. I understand the acq/rel relaxations for
strong CASes, but what is the relaxation for already weak CAS? In other
words, weakCompareAndSet is spec'ed in j.u.c.atomic as:

"weakCompareAndSet atomically reads and conditionally writes a variable
but does not create any happens-before orderings, so provides no
guarantees with respect to previous or subsequent reads and writes of
any variables other than the target of the weakCompareAndSet."


"Additionally weakCompareAndSet does not provide ordering guarantees
that are usually needed for synchronization control. However, the method
may be useful for updating counters and statistics when such updates are
unrelated to the other happens-before orderings of a program. When a
thread sees an update to an atomic variable caused by a
weakCompareAndSet, it does not necessarily see updates to any other
variables that occurred before the weakCompareAndSet."


More information about the jmm-dev mailing list