RFR: 8366671: Refactor Thread::SpinAcquire and Thread::SpinRelease [v6]
David Holmes
dholmes at openjdk.org
Tue Nov 18 06:55:05 UTC 2025
On Mon, 17 Nov 2025 11:59:29 GMT, Anton Artemov <aartemov at openjdk.org> wrote:
>> Hi,
>>
>> please consider the following changes:
>>
>> In this PR `Thread::SpinAcquire()` and `Thread::SpinRelease()` methods are refactored into a utility class `SpinCriticalSection`. The motivation is to make it easier for developers to use this lightweight synchronization mechanism in the codebase. The two aforementioned methods were used in JFR to create short critical sections with a helper class, but that was not the case for the object monitor code.
>>
>> Additionally, `SpinSingleSection` class is added, which allows to execute a payload code inside of a lambda function by only one thread.
>>
>> Tested in tiers 1 - 5.
>
> Anton Artemov has updated the pull request incrementally with one additional commit since the last revision:
>
> 8366671: Removed redundant include.
I'm really not convinced about this one. First the "motivation" is mis-placed as (as Kim noted from the existing code) we do not want this to be a general purpose synchronization utility that encourages everyone to use it through the codebase. So really this is about creating a basic wrapper RAII class - as JFR did - but make it and the underlying API more generic by extracting from the JFR and Threads code. A RAII helper is nice to have but not essential for very short critical sections where we can't really miss a return path, but I'm almost swayed by that. I'm not at all convinced we need the template variant though.
src/hotspot/share/runtime/objectMonitor.cpp line 320:
> 318: check_object_context();
> 319: if (_object_strong.is_empty()) {
> 320: auto setObjectStrongLambda = [&](OopHandle& object_strong, const WeakHandle& object) {
I don't understand why we need the complexity of the `SpinSingleSection` and use of lambda's/functors.
This seems like try-lock usage, though I'm not at all sure why (i.e. if we don't get the lock who is taking care of making a strong reference?)
-------------
PR Review: https://git.openjdk.org/jdk/pull/28264#pullrequestreview-3475442011
PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2536305734
More information about the hotspot-dev
mailing list