VarHandles on non-int-sized fields and atomic operations
Martin Buchholz
martinrb at google.com
Mon May 23 22:32:20 UTC 2016
On Mon, May 23, 2016 at 3:15 PM, Aleksey Shipilev
<aleksey.shipilev at oracle.com> wrote:
>> Since atomic fields need different field layout from regular fields,
>> it seems to make sense to require that fields which will be accessed
>> via a VarHandle are clearly marked as being "atomic" in some way.
>
> Mark that as "volatile int" :) Because if marking boolean field with
> some "atomic" quantifier would blow up its storage to at least int,
> that's what you get in the end anyhow.
But that's violating the abstraction boundary!
You can use AtomicBoolean without being aware of whether you are
actually generating 1-bit, 8-bit or 32-bit CASes. That's the JVM's
job!
It's going back to Evil Old C if we start having to encode our
booleans using ints, just because of the instructions common on
today's CPUs. It's true that users had to do this with Unsafe, but
aren't VarHandles supposed to be a public high level replacement?
I think we're losing something if any VarHandles to primitive types
fail to have a CAS.
More information about the core-libs-dev
mailing list