On Thu, 13 Mar 2025 09:45:22 GMT, Per Minborg <pminb...@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

Reply via email to