Testing hotspot's Atomic::cmpxchg(jbyte*) ?

Aleksey Shipilev aleksey.shipilev at gmail.com
Fri Aug 19 06:31:58 UTC 2016


On 08/19/2016 08:15 AM, David Holmes wrote:
> I need to test the jbyte version of Atomic::cmpxchg in the VM, but so
> far it doesn't seem to be the case that any library code will actually
> invoke it. At the top Java level there is no AtomicByte class. Unsafe
> defines compareAndSwapByte variants but implements them using
> compareAndSwapInt and isolating the byte of interest. VarHandles seems
> to have direct *SwapByte operations but I can't figure out what they map
> to - there are VM intrinsics but again I can't the actual implementation
> to see if it uses Atomic::cmpxchg(jbyte*).

VarHandles byte CAS/CAE map to Unsafe. Therefore they will use the
Java-ish compareAndExchangeByte from Unsafe, without touching
Atomic::cmpxchg(jbyte).

In retrospect, we did that before Atomic::cmpxchg(jbyte) was available.
Now it might be cleaner to ditch Java version from Unsafe, and make
native entry points like Unsafe_CompareAnd{Exchange,Swap}{Byte,Short}
which would call relevant Atomic::cmpxchg-s.

Then, regular jdk/test/java/lang/invoke/varhandles and
hotspot/tests/compiler/unsafe tests would exercise that path, as they
run in interpreter too.

Thanks,
-Aleksey



More information about the core-libs-dev mailing list