I have been reading about VarHandle in Java, from the documentation the access modes are grouped into the following categories:
read access modes, such as reading a variable with volatile memory ordering effects;
write access modes, such as updating a variable with release memory ordering effects;
atomic update access modes, such as a compare-and-set on a variable with volatile memory order effects for both read and writing;
numeric atomic update access modes, such as get-and-add with plain memory order effects for writing and acquire memory order effects for reading.
bitwise atomic update access modes, such as get-and-bitwise-and with release memory order effects for writing and plain memory order effects for reading.
Found following code sample from Using JDK 9 Memory Order Modes
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
class Point {
volatile int x, y;
private static final VarHandle X;
static {
try {
X = MethodHandles.lookup().
findVarHandle(Point.class, "x",
int.class);
} catch (ReflectiveOperationException e) {
throw new Error(e);
}
}
// ...
}
What I am trying to figure out is how does it achieve this, what is the underlying implementation and how to use all these access modes ?