RFR: 8365317: ZGC: Setting ZYoungGCThreads lower than ZOldGCThreads may result in a crash
Erik Österlund
eosterlund at openjdk.org
Wed Aug 13 10:28:10 UTC 2025
On Tue, 12 Aug 2025 12:35:57 GMT, Joel Sikström <jsikstro at openjdk.org> wrote:
> Hello,
>
> Setting ZYoungGCThreads lower than ZOldGCThreads may result in a crash, for example using `-XX:ZYoungGCThreads=4` and `-XX:ZOldGCThreads=8`. The problem is in `select_worker_threads()` in zDirector.cpp, where the number of young threads may be set to the number of old threads in an attempt to speed up the young collection so that the old collection can begin faster in a major collection. If the number of old threads exceed the maximum number of young threads, i.e. ZYoungGCThreads, a crash may occur. See the JBS issue for details on the crash.
>
> Even though it may not be common, or reasonable in all scenarios, to set the maximum number of young threads to less than the maximum number of old threads, the combination should be possible and not result in a crash. To solve this issue, I suggest we clamp or otherwise limit the number of young threads to the maximum amount of young threads (i.e., `ZYoungGCThreads`).
>
> Testing:
> * Oracle's tier1-2, both with and without `-XX:ConcGCThreads=20 -XX:ZYoungGCThreads=2 -XX:ZOldGCThreadds=20` pass.
> * I can no longer observe the intermittent crashes in release builds after 1000 runs.
Nice catch. Looks good.
-------------
Marked as reviewed by eosterlund (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/26745#pullrequestreview-3115086496
More information about the hotspot-gc-dev
mailing list