生成快照C:\Users\hylexus>jmap -dump:live,format=b,file=t.bin 67008Dumping heap to C:\Users\hylexus\t.bin ...Heap dump file createdC:\Users\hylexus># 分析快照C:\Users\hylexus>jhat t.binReading from t.bin...Dump file created Mon Dec 19 22:43:48 CST 2016Snapshot read, resolving...Resolving 1861041 objects...Chasing references, expect 372 dots....................................................................................................................................................................................................................................................................................................................................................................................Eliminating duplicate references....................................................................................................................................................................................................................................................................................................................................................................................Snapshot resolved.Started HTTP server on port 7000Server is ready.
此时在浏览器里访问 127.0.0.1:7000就能看到分析结果:
2.6 jstack
jstack(Stack Trace for Java)可以生成虚拟机当前时刻的线程快照。
一般称为threaddump或者javacore文件。即每一条线程正在执行的方法堆栈的集合。
语法
C:\Users\hylexus>jstack -helpUsage: jstack [-l] (to connect to running process) jstack -F [-m] [-l] (to connect to a hung process) jstack [-m] [-l] (to connect to a core file) jstack [-m] [-l] [server_id@] (to connect to a remote debug server)Options: -F 当JVM不响应该请求时强制进行线程dump -m 显示java方法也可以是本地方法的堆栈信息 -l 显示有关锁的附加信息