On Mon, May 23, 2016 at 3:15 PM, Aleksey Shipilev <[email protected]> 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.
