On Mon, 22 Apr 2024 17:09:39 GMT, Chen Liang <li...@openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/lang/StableValue.java line 130: >> >>> 128: * } else { >>> 129: * V newValue = supplier.get(); >>> 130: * stable.setOrThrow(newValue); >> >> If ::computeIfUnset allows racy sets, then it isn't equivalent to this code >> as ::setOrThrow will throw on a race, correct? > > Indeed, this if-else should be guarded by a synchronized block, except the > lock is on the internal mutex which is not publicly exposed. `computeIfUnset()` is indeed guarded by a synchronized block, only it sits on the method declaration of `computeIfUnsetVolatile0`. I think we should have an internal mutex. This will also correspond to the stable collections which have internal mutexes for each index/key. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18794#discussion_r1575972396