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

Anton Artemov aartemov at openjdk.org
Mon Dec 8 09:24:03 UTC 2025


On Sun, 7 Dec 2025 22:37:12 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> I hadn't noticed the 'safe' variant of Thread::current_or_null, but it seems like it might be appropriate from the implementation if this can be called very early in VM initialization for ParkEvents.
>> 
>> 
>> inline Thread* Thread::current_or_null_safe() {
>>   if (ThreadLocalStorage::is_initialized()) {
>>     return ThreadLocalStorage::thread();
>>   }
>>   return nullptr;
>> }
>> 
>> 
>> It seems to cover more than the case of being called in a signal handler.  I think it's not a bad usage.  I was going to vote the other way until I saw the implementation.
>
> Coleen I am not at all sure what you mean by that. The "safe" implementation has to use library-based TLS, rather than language/compiler-based as the latter is definitely not signal-safe while the former is deemed safe enough for reading TLS values. Because the safe version can be called very early in VM init we have to check the library-based TLS is initilalized.

I think we don't want complication as the one that David described in this supposedly simple utility object. Let's just use the unsafe version and document when it should not be used.

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

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


More information about the hotspot-dev mailing list