Possible subtle memory model error in ClassValue

Andrew Haley aph at redhat.com
Sun Aug 9 14:52:52 UTC 2020

On 8/7/20 10:35 PM, John Rose wrote:

 > (Here’s a tidbit of JMM politics: I once heard Doug Lea considering
 > whether maybe all fields should be treated more like final fields.
 > I don’t know if this is still a live idea, but it would make this
 > bug go way, since nearly all constructors would then get fences of
 > some sort.)

I'd support that: accidental unsafe publication like this is a really
counter-intuitive language feature.

 > Bottom line:  Add a release fence before type.cVM is set, and add
 > a (no-op on x86) acquire fence in getCache.

A StoreStore fence would be enough here, and cheaper on some systems.
The memory dependency ordering from the load of classValueMap to the
load of classValueMap.cache means we don't need an acquire fence.

After all, final fields have the needed guarantee, only StoreStore
fences, and no load fences.

Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the core-libs-dev mailing list