JDK 9 引入了 jhsdb 工具,取代原先的 sa-jdi.jar(Serviceability Agent )工具 ,用于对 JVM 的调试分析。

由于 Serviceability Agent 在使用的时候会先 attach 进程,然后暂停进程进行 snapshot,最后 deattach 进程(进程恢复运行),所以在使用 HSDB 时要注意。

> jhsdb -h
    clhsdb       	command line debugger
    debugd       	debug server
    hsdb         	ui debugger
    jstack --help	to get more information
    jmap   --help	to get more information
    jinfo  --help	to get more information
    jsnap  --help	to get more information

其中 clhsdb、hsdb 为之前 sa-jdi.jar 提供的 HDSB、CLHSDB 功能。

jstack

jhsdb jstack 提供原先 jstack 的功能,并进行了增强,用于分析 JVM 程序进程状态信息。

> jhsdb jstack
    --locks	  to print java.util.concurrent locks
    --mixed	  to print both java and native frames (mixed mode)
    --exe	    executable image name
    --core	  path to coredump
    --pid	    pid of process to attach

示例:

# 获取进行中的锁信息
jhsdb jstack --locks --pid 54521

jmap

jhsdb map 支持原先 jmap 的功能,用于分析 JVM 程序内存信息。

> jhsdb jmap --help
    <no option>	  to print same info as Solaris pmap
    --heap	      to print java heap summary
    --binaryheap	to dump java heap in hprof binary format
    --dumpfile	  name of the dump file
    --histo	      to print histogram of java object heap
    --clstats	    to print class loader statistics
    --finalizerinfo	  to print information on objects awaiting finalization
    --exe	executable  image name
    --core	      path to coredump
    --pid	        pid of process to attach

示例:

# 获取 heap 概要信息
jhsdb jmap --heap --pid 54521