CAS form release only

I accidentally stumbled upon the Striped64.java class from the Kamon Monitoring tool. On 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 cannot find out what a CAS release form is . Can someone shed some light on this?

+5
source share
2 answers

I cannot find out which form of CAS is available for release only.

This refers to the limitations of ordering memory on an atom in terms of a C ++ memory model . Some of them are not fully expressed in terms of the java memory model that precedes C ++ (see also the JMM cookbook for developers ) and therefore they are not currently available through the standard library.

This will change from Java9, where varhandles will expose memory calls that correspond to C ++ semantics, with the exception of the order of consumption.

Also note that the associated java class was copied from the jsr166 repository, which is an upstream version of the JDK juc packages.

+4
source

Usually for unstable recording you will get the following barriers.

 [StoreStore] [LoadStore] x=10 [StoreLoad] 

StoreLoad has 2 goals:

  • It prevents higher loads up to x = 10.
  • he makes all the changes that occurred before the appearance of "x = 10" on other processors.

StoreLoad is potentially expensive since it expects the storage buffer to be exhausted.

The above approach combined with the following for reading X

 tmp=x [LoadLoad] [LoadStore] 

Ensure that access to the volatile variable is consistent.

A release of only the form will look like this

 [StoreStore] [LoadStore] x=10 

As you can see, the [StoreLoad] barrier has disappeared.

On the reading side, this is the same as regular mutable reading.

I donโ€™t know how the โ€œrelease-only CAS formโ€ fits into the image

And, as 8472 already pointed out, the new VarHandles in Java 9 will reveal the unconstrained receipt / release guarantees.

+2
source

Source: https://habr.com/ru/post/1263668/


All Articles