RFR: 8351565: Implement JEP 502: Stable Values (Preview)
Luca Kellermann
duke at openjdk.org
Thu Mar 13 12:03:11 UTC 2025
On Thu, 13 Mar 2025 09:45:22 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/lang/stable/StableValueImpl.java line 128:
>>
>>> 126: final T newValue = supplier.get();
>>> 127: // The mutex is reentrant so we need to check if the value was actually set.
>>> 128: return wrapAndCas(newValue) ? newValue : orElseThrow();
>>
>> Reentrancy into here seems really buggy, I would endorse disallowing it instead. In that case, a `ReentrantLock` seems better than the native monitor as we can cheaply check `lock.isHeldByCurrentThread()`
>
> StableValueImpl was carefully designed to minimize memory footprint. Adding a lock would inflate memory usage substantially.
There is also `Thread.holdsLock()`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1993371561
More information about the core-libs-dev
mailing list