Make load/store of 64-bit long and double atomic

Andrew Haley aph at redhat.com
Tue Jul 12 12:35:56 UTC 2016


On 07/07/16 12:29, John Crowley wrote:

> Would like to make a suggestion re the JVM and non-atomic load/store
> for long and double values since both are 64-bit.  (Sec 17.7 of the
> JLS version 8 - have not been able to find a JLS V9 yet). Did some
> searching through JSRs and mailing lists, but did not see this
> addressed - please send me a link if it has been and I just missed
> it.
> 
> Right now, in a multi-threaded environment the developer must make
> these volatile to ensure correct operation - which I would suspect
> that 95% of Java developers do not realize. (I certainly didn’t for
> over 20 years!)

After more discussion on jmm-dev, it's clear that
VarHandle.{get,set}Opaque() will do exactly what you want: guarantee
atomic accesses to longs and doubles without the overhead of volatile
accesses.  I think that's enough for practical usage in Java.

Andrew.


More information about the hotspot-dev mailing list