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>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

Reply via email to