On Sun, 19 Dec 2021 05:56:55 GMT, David Holmes <dhol...@openjdk.org> wrote:
>> liach has updated the pull request incrementally with one additional commit >> since the last revision: >> >> Just use volatile directly to ensure read order > > 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? ------------- PR: https://git.openjdk.java.net/jdk/pull/6889