RFR: 8356173: Remove ThreadCritical [v4]

Thomas Stuefe stuefe at openjdk.org
Tue May 13 13:05:54 UTC 2025


On Mon, 12 May 2025 23:11:21 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Remove recursive detection that doesn't work.
>
> Changes requested by kbarrett (Reviewer).

@kimbarrett @coleenp I proposed to use simple global initialization because it makes the code independent from initialization order worries in this sort of very low level very early invoked code. That was the main benefit I had in mind. It is not an immediate concern (we have NMT preinit to deal with early VM time) but every avoided dependency is good.

The problem with global initialization was on POSIX that pthread_mutex_init() crashes when used at lib loading time on MacOs. The fix for this is to use a static PTHREAD_MUTEX_... initializer, which is also simpler.

On Windows, one initializes CriticalSections with InitializeCriticalSection(), but that can happen at initialization time in a constructor of a global object. I have done this combination (InitializeCriticalSection on windows, pthread_mutex_t with static initializer on Posix) a lot in many projects, it just works and is simple.

I am fine with whatever Coleen decides. I don't want to bikeshed this to death, just explain my reasoning.

P.S. Windows critical sections don't offer recursion checks.

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

PR Comment: https://git.openjdk.org/jdk/pull/25072#issuecomment-2876436635


More information about the hotspot-dev mailing list