RFR: 8261407: ReflectionFactory.checkInitted() is not thread-safe [v2]

David Holmes dholmes at openjdk.java.net
Sun Dec 19 12:42:18 UTC 2021


On Sun, 19 Dec 2021 07:05:31 GMT, liach <duke at openjdk.java.net> wrote:

>> src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java line 695:
>> 
>>> 693: 
>>> 694:         // ensure previous fields are visible before initted is
>>> 695:         Unsafe.getUnsafe().storeStoreFence();
>> 
>> Ensuring ordering on the writer side, without also ensuring ordering on the reader side, doesn't solve an ordering problem. Just make `initted` volatile and this should be safe from a Java Memory Model perspective.
>
> On a side note, would a store load fence (like `VarHandle.storeFence`) after the write be a valid alternative, so the field itself can be get plain?

I don't see such a "fence" in the VarHandle API. ?? The `VarHandle.storeStoreFence()` is no different in memory ordering properties to the `Unsafe.storeStoreFence()`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6889


More information about the core-libs-dev mailing list