On Tue, 20 Oct 2026 09:47:11 GMT, Fredrik Bredberg <[email protected]> 
wrote:

>> This PR reduces the Thread-SMR (Safe Memory Reclamation) related cost of 
>> starting and exiting threads.
>> 
>> Both starting and exiting a thread create a new `ThreadsList` and retire the 
>> old one. Previously, we used to scan the hazard pointers of all threads when 
>> a `ThreadsList` was retired. This made the execution cost increasingly 
>> higher as more threads were started.
>> 
>> This PR tackles the problem in three ways:
>> 
>> 1. By not scanning hazard pointers every time a new thread is started. 
>> Instead, we defer the scanning until either 16 `ThreadsLists` have been 
>> retired or the retired lists occupy at least 4 MB of memory.
>> 2. We use the scan that is performed when removing a thread to also 
>> determine if it's safe to delete the thread, and thereby we potentially 
>> avoid a costly re-scan in `wait_until_not_protected()`.
>> 3. By checking if there is no retired `ThreadsList` that can protect the 
>> thread, `wait_until_not_protected()` can also avoid a re-scan.
>> 
>> I've run the ThreadStart reproducer that is attached to 
>> [JDK-8307970](https://bugs.openjdk.org/browse/JDK-8307970). Depending on the 
>> number of idle threads, the changes in this PR show that threads start up to 
>> ~63% faster (or in other words, a ~39% reduction in time to start a thread).
>> 
>> To go further than this likely requires a major rewrite of the Thread-SMR 
>> system, which would not be a walk in the park.
>> 
>> Passes tier1-3 tests.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Fredrik Bredberg has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains seven additional 
> commits since the last revision:
> 
>  - Update for David
>  - Merge branch 'master' into 8307970_thraedstart_is_slow
>  - Update for Patricio
>  - Added reproducer ThreadStartWithIdleThreads.java
>  - Merge branch 'master' into 8307970_thraedstart_is_slow
>  - Updated comments for David and Daniel
>  - 8307970: Thread.start is slow with large number of threads

Thumbs up.

src/hotspot/share/runtime/threadSMR.cpp line 943:

> 941:     // The bootstrap list cannot be freed and is empty so
> 942:     // it does not need to be scanned. Nothing to do here.
> 943:     log_debug(thread, smr)("tid=%zu: ThreadsSMRSupport::free_list: 
> bootstrap ThreadsList=" INTPTR_FORMAT " is no longer in use.", 
> os::current_thread_id(), p2i(threads));

Not your issue, but I don't understand this debug mesg.

If we are passed a `threads` value that matches the bootstrap list,
then we have no work to do because we are early in the VM's life.
So what does "is no longer in use" mean?

src/hotspot/share/runtime/threadSMR.cpp line 957:

> 955: 
> 956:   // We can defer a reclamation attempt if free_list() was called when 
> adding
> 957:   // a thread (i.e. thread_to_delete == nullptr). This amortizes the 
> cost of

nit: s/i.e./i.e.,/

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

Marked as reviewed by dcubed (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/33166#pullrequestreview-5472281295
PR Review Comment: https://git.openjdk.org/jdk/pull/33166#discussion_r4231929602
PR Review Comment: https://git.openjdk.org/jdk/pull/33166#discussion_r4231952959

Reply via email to