java调试

java调试

简介

jvm内存布局

image-20191104143552313

工具

  • jps: 查看jvm 进程信息;
  • jstack:查看jvm栈信息;
  • jmap:查看jvm堆相关信息
  • jstat: JVM统计监测工具
  • jhat:
  • hprof:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## 查看线程
$ jps -ml
$ ps -Lfp <pid>
$ top -Hp <pid>

## jstat 垃圾回收统计
$ jstat -gc <pid>
$ jstat -gccapacity <pid>     ## 堆内存统计 
$ jstat -gcnew <pid>                ##新生代垃圾回收统计
$ jstat -gcutil <pid>              ##总结垃圾回收统计
$ jstat -class <pid>                ## 显示加载class的数量,及所占空间等信息。
$ jstat -compiler pid

## jmap
$ jmap -dump:format=b,file=dumpFileName pid
$ jmap -permstat pid                #打印进程的类加载器和类加载器加载的持久代对象信息
$ jmap -heap <pid>                    #查看进程堆内存使用情况
$ jmap -histo[:live] pid        #查看堆内存中的对象数目、大小统计直方图

## jhat 查看dump
$ jhat -J-Xmx512m -port 9998 /tmp/dump.dat

hprof

1
2
3
java -agentlib:hprof[=options] ToBeProfiledClass
java -Xrunprof[:options] ToBeProfiledClass
javac -J-agentlib:hprof[=options] ToBeProfiledClass

参考

  1. https://zhuanlan.zhihu.com/p/68572738
  2. https://segmentfault.com/a/1190000005174819
  3. https://juejin.im/post/5d1efae26fb9a07ea6489355
updatedupdated2024-05-102024-05-10