I have accidentally run into Striped64.java class from Kamon Monitoring tool. At line 95 I found this comment:
JVM intrinsics note: It would be possible to use a release-only
form of CAS here, if it were provided.
Although I understand what CAS is, I am unable to find out what a release-only form of CAS is. Could someone shed some light on this?
I am unable to find out what a release-only form of CAS is.
That refers to memory ordering constraints on atomics in the terms of the C++ memory model. Some of those are not fully expressible in the terms of the java memory model which predates the C++ one (see also the JMM cookbook for developers) and thus they are currently not made available through the standard library.
This will change with Java9 where varhandles will expose memory accesses that match C++ semantics, except consume order.
Also note that the java class you linked has been copied from the jsr166 repository, which is the upstream version of the JDK j.u.c. packages.
Normally for a volatile write you will get the following barriers
[StoreStore]
[LoadStore]
x=10
[StoreLoad]
The StoreLoad has 2 purposes:
The StoreLoad is potentially expensive since it waits for the store buffer to get drained.
The above approach, in combination with the following for the read of X
tmp=x
[LoadLoad]
[LoadStore]
Will make sure that accessing a volatile variable is sequential consistent.
A release only form would look like this
[StoreStore]
[LoadStore]
x=10
As you can see the [StoreLoad] barrier is gone.
On the reading side, it is the same as a regular volatile read.
I don't know how 'release-only form of CAS' fits into the picture
And like the8472 already indicated, the new VarHandles in Java 9 will expose the relaxed 'acquire/release' ordering guarantees.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With