VarHandles on non-int-sized fields and atomic operations

Martin Buchholz martinrb at google.com
Tue May 24 23:15:51 UTC 2016


More high-level observations on low-level operations:

We already sort-of have an existing field qualifier for atomic: "volatile" !
It is already the case that e.g. volatile long is atomic while
unadorned long is not.
But atomics without CAS make us sad, so we're adding them.
Also, by analogy, Atomic*FieldUpdaters must refer to a volatile variable.
It seems not unreasonable to require that VarHandles also refer to a
volatile field.

If a field is declared
volatile boolean;
then the VM should ensure not only that it can be reasonably
efficiently updated using ordinary read/write as is already the case
but also that it can be reasonably efficiently CAS'ed, and that may
mean giving it 32 bits instead of 8 on some platforms.  But it would
be a VM implementation detail.

It would be even nicer if the field qualifier was literally "atomic",
but I don't think that is going to happen.  The best we can hope for
is:

"volatile" is how you spell "atomic" in Java.



More information about the core-libs-dev mailing list