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

Kim Barrett kbarrett at openjdk.org
Wed Nov 19 20:39:09 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

Changes requested by kbarrett (Reviewer).

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

> 28: #include "runtime/javaThread.hpp"
> 29: 
> 30: class SpinCriticalSectionHelper : AllStatic {

SpinCriticalSectionHelper is only used (and only usable by)
SpinCriticalSection. There doesn't seem to be any benefit to the separation
now.

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

> 41: // which employs a spin lock.
> 42: //
> 43: // We use this critical section _only for low-contention code, and

Either s/_only/_only_/ or s/_only/only/

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

PR Review: https://git.openjdk.org/jdk/pull/28264#pullrequestreview-3484643323
PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2543485977
PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2543489482


More information about the hotspot-dev mailing list