LinuxCommandLibrary

jhsdb

Debug Java processes and core dumps

TLDR

Print stack and locks information of a Java process

$ jhsdb jstack --pid [pid]
copy

Open a core dump in interactive debug mode
$ jhsdb clhsdb --core [path/to/core_dump] --exe [path/to/jdk_or_bin_or_java]
copy

Start a remote debug server
$ jhsdb debugd --pid [pid] --serverid [optional_unique_id]
copy

Connect to a process in interactive debug mode
$ jhsdb clhsdb --pid [pid]
copy

SYNOPSIS

jhsdb [-V] [-d <path>] [-X] <tool> [<tool-options>]

PARAMETERS

-V
    Print version information and exit.


-d <path>
    Path to JDK/JRE containing libjvm.so for SA (default: runtime JRE).


-X
    Execute without confirmation prompts before exit.


clhsdb
    Interactive command-line HotSpot debugger with commands like 'threads', 'heap'.


jmap
    Heap viewer/dumper: --heap, --histo, --core <file>, --pid <pid>.


jstack
    Thread dump generator: --pid <pid>, --core <file> --exe <jvm>.


jcmd
    Diagnostic commands via SA (limited subset).


DESCRIPTION

jhsdb launches the Serviceability Agent (SA) for debugging HotSpot JVMs. It supports analysis of live processes or core dumps, providing access to heap, threads, stacks, and internals without a full debugger.

Ideal for production diagnostics like memory leaks or deadlocks, SA bypasses JVM attachment restrictions. Traditional tools like jmap and jstack invoke jhsdb internally in JDK 8+.

Key uses: generate heap dumps (jhsdb jmap --heap --pid <pid>), thread stacks (jhsdb jstack --pid <pid>), or interactive debugging (jhsdb clhsdb). For cores: jhsdb jmap --core <core> --exe <jvm>.

Requires matching JDK libs; works on Linux, Windows, macOS. Enables commands like 'threads', 'histogram', 'inspect' in clhsdb mode. Enhances Java observability beyond jcmd.

CAVEATS

Needs exact JVM binary/libjvm match for cores; full debug JDK recommended. Core dumps must capture JVM libs (use gcore). Incompatible with some compressed GCs without adjustments. Not for OpenJ9/other JVMs.

CORE DUMP EXAMPLE

jhsdb clhsdb <core-file> <jvm-executable>
Launches interactive debugger on core.

LIVE HEAP SUMMARY

jhsdb jmap --heap --pid <pid>
Prints non-interactive heap overview.

HISTORY

Introduced in OpenJDK/JDK 8 (2014) to unify SA access, evolving from JDK 5's debug agent. Standardized core/live JVM analysis amid rising cloud diagnostics needs.

SEE ALSO

jcmd(1), jmap(1), jstack(1), jhat(1), gdb(1)

Copied to clipboard