RFR: 8329109: Threads::print_on() tries to print CPU time for terminated GC threads

Albert Mingkun Yang ayang at openjdk.org
Thu Mar 28 13:17:31 UTC 2024


On Wed, 27 Mar 2024 16:09:46 GMT, Richard Reingruber <rrich at openjdk.org> wrote:

> Make use of `Threads::threads_do()` if at a safepoint to print the threads.
> `Threads::threads_do()` uses thread list iterators that don't visit terminated threads.
> If a non-java thread is about to terminate, it waits for in progress iterations (see [NonJavaThread::remove_from_the_list](https://github.com/openjdk/jdk/blob/47f33a59eaaffc74881fcc9e29d13ff9b2538c2a/src/hotspot/share/runtime/nonJavaThread.cpp#L97-L102)).
> 
> Only debug code calls `Threads::print_on()` outside a safepoint if I'm not mistaken so this solution should work in the relevant cases (jcmd, SIGQUIT, ...).
> 
> Testing:
> 
> The output of a minimal example with G1 is almost identical. The order of `NonJavaThreads` can differ.
> 
> More tests (besides GHA) are pending.

It's `Universe::heap()->gc_threads_do` that may contain terminated threads, not any other kinds of`NonJavaThreads`, right?

If so, can the fix be placed in `gc_threads_do`, where every collector ensures only active gc threads are visited.

(I see that David made a similar remark in the bug report.)

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

PR Comment: https://git.openjdk.org/jdk/pull/18518#issuecomment-2025160464


More information about the hotspot-gc-dev mailing list