On Tue, 17 May 2022 11:57:01 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/foreign/abi/SoftReferenceCache.java >> line 42: >> >>> 40: >>> 41: private class Node { >>> 42: private SoftReference<V> ref; >> >> this code looks like a double check locking so ref should be volatile > > Thanks. I thought the `moniterenter` & `monitorexit` were enough here for > visibility. I've read up on this and it looks like `volatile` is needed to > correctly order the constructor and apply call (and contents) before the > write to the `ref` field. yes, otherwise another thread than the one inside the `monitorenter`/`monitorexit` that is initializing the object can see the object half initialized. ------------- PR: https://git.openjdk.java.net/jdk/pull/8685