RFR: 8366671: Refactor Thread::SpinAcquire and Thread::SpinRelease [v7]

David Holmes dholmes at openjdk.org
Thu Nov 20 06:20:12 UTC 2025


On Wed, 19 Nov 2025 14:09:53 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: Addressed reviewer's comments

I am happier with this reduced form but as per comments don't change the implementation now please.

Thanks

src/hotspot/share/utilities/spinCriticalSection.cpp line 34:

> 32:   }
> 33: 
> 34:   SpinYield sy(4096, 5, 1000000);

This is supposed to be a refactor. If you want to change the implementation then I suggest a separate PR with full performance analysis.

src/hotspot/share/utilities/spinCriticalSection.hpp line 33:

> 31:   friend class SpinCriticalSection;
> 32:   template<class Lambda, class...Args>
> 33:   friend class SpinSingleSection;

Shouldn't this be removed?

-------------

Changes requested by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28264#pullrequestreview-3485868831
PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2544483791
PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2544486968


More information about the hotspot-dev mailing list