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

Kim Barrett kbarrett at openjdk.org
Wed Nov 19 20:29:22 UTC 2025


On Wed, 19 Nov 2025 14:04:41 GMT, Anton Artemov <aartemov at openjdk.org> wrote:

>> src/hotspot/share/utilities/spinCriticalSection.hpp line 58:
>> 
>>> 56: class SpinSingleSection {
>>> 57: private:
>>> 58:   volatile int* const _lock;
>> 
>> Why an `int`-type value for the lock, rather than `bool`? I know why, but it should probably be
>> stated explicitly, else someone might be tempted to change it in the future.
>
> I believe it is for historical reasons?

I think it's because `bool` is (typically? always? I don't recall) of size 1,
and size 1 cmpxchg isn't supported by a lot of hardware, so we emuluate it for
those. Mostly we don't worry about that, but this is supposed to be low-level
and performance-critical (else why aren't we just using a mutex?). Or maybe it
is historical, and the starting point for some of this code is so old that it
predates our emulation of 1-byte cmpxchg for some platforms. :)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28264#discussion_r2543455013


More information about the hotspot-dev mailing list