RFR: 8356870: HotSpotDiagnosticMXBean.dumpThreads and jcmd Thread.dump_to_file updates

Shaojin Wen swen at openjdk.org
Sat May 24 09:39:52 UTC 2025


On Sat, 24 May 2025 06:57:56 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> Updates the thread dump generated by HotSpotDiagnosticMXBean.dumpThreads and jcmd Thread.dump_to_file to include thread state and lock information. Also update the HotSpotDiagnosticMXBean.dumpThreads API description to link to a description of the JSON format dump as that format is intended to be parseable/read by tools.
> 
> This PR is dependent on [pull/25425](https://github.com/openjdk/jdk/pull/25425). As noted in that PR, the changes accumulated in the loom repo, and have been split up to make it easier to review.
> 
> The changes include some re-implementation of ThreadDumper. This is because it used PrintStream and didn't fail if there was an I/O error, e.g. file system full. Furthermore, the indentation to pretty print the json was fragile and hard to maintain so this is changed to use a supporting writer class to do this.
> 
> Test coverage is significantly expanded, including updating the test library that is used by several tests to parse the thread dump.
> 
> Testing: tier1-6

src/java.base/share/classes/jdk/internal/vm/ThreadDumper.java line 56:

> 54:  * thread dump to a file or byte array in plain text or JSON format.
> 55:  */
> 56: public class ThreadDumper {

Suggestion:

public final class ThreadDumper {

src/java.base/share/classes/jdk/internal/vm/ThreadDumper.java line 375:

> 373:      * This class is not intended to be a fully featured JSON writer.
> 374:      */
> 375:     private static class JsonWriter {

Suggestion:

    private static final class JsonWriter {
        private static final class Node {

src/java.base/share/classes/jdk/internal/vm/ThreadSnapshot.java line 33:

> 31:  * Represents a snapshot of information about a Thread.
> 32:  */
> 33: class ThreadSnapshot {

Suggestion:

final class ThreadSnapshot {

src/java.base/share/classes/jdk/internal/vm/ThreadSnapshot.java line 182:

> 180:      */
> 181:     private class ThreadLock {
> 182:         private static final OwnedLockType[] lockTypeValues = OwnedLockType.values(); // cache

Suggestion:

        @Stable
        private static final OwnedLockType[] lockTypeValues = OwnedLockType.values();

test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpThreadsWithEliminatedLock.java line 83:

> 81:                 sb.append(System.currentTimeMillis());
> 82:                 String s = sb.toString();
> 83:                 ref.set(s);

Suggestion:

                ref.set(
                        new StringBuffer()
                                .append(System.currentTimeMillis())
                                .toString());

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25429#discussion_r2105771285
PR Review Comment: https://git.openjdk.org/jdk/pull/25429#discussion_r2105771656
PR Review Comment: https://git.openjdk.org/jdk/pull/25429#discussion_r2105770924
PR Review Comment: https://git.openjdk.org/jdk/pull/25429#discussion_r2105771148
PR Review Comment: https://git.openjdk.org/jdk/pull/25429#discussion_r2105771949


More information about the serviceability-dev mailing list