这些工具都在java安装目录的bin目录下。
命令行工具
jps
列出正在运行的虚拟机进程, 并显示虚拟机执行主类( Main Class, main()函数所在的类)名称以及这些进程的本地虚拟机唯一ID( LVMID, Local Virtual Machine Identifier)。
jps [ options ] [ hostid ]
示例:
jps -l
2388 D:\Develop\glassfish\bin\..\modules\admin-cli.jar
2764 com.sun.enterprise.glassfish.bootstrap.ASMain
3788 sun.tools.jps.Jps
options:
options | 说明 |
---|---|
-q | 只输出LVMID,省略主类的名称 |
-m | 输出虚拟机启动时传递给主类main()函数的参赛 |
-l | 输出主类的全名,如果进程执行的是JAR包,输出JAR路径 |
-v | 输出JVM启动时的参数 |
jstat
监视运行时状态的命令行工具。
jstat [ option vmid [interval[s|ms] [count]] ]
示例:假设每250毫秒查询一次进程2764垃圾收集状况, 一共查询20次,命令如下
jstat -gc 2764 250 20
option:
option | 说明 |
---|---|
-class | 监视类加载、卸载数量、总空间以及类装载耗费的时间 |
-gc | 监视堆状况,包括Eden区,两个Survivor区,老年代、永久代的容量, 已用空间,垃圾回收次数、回收耗时等信息 |
-gccapacity | 内容同-gc,关注各个区使用到的最大最小空间 |
-gcutil | 内容同-gc,关注已使用空间占总空间的百分比 |
-gccause | 功能同-gcutil,增加上次GC的原因 |
-gcnew | 关注新生代GC情况 |
-gcnewcapacity | 同-gccapacity,关注新生代 |
-gcold | 关注老年代 |
-gcoldcapacity | 同-gccapacity,关注老年代 |
-gcpermcapacity | 关注永久代的最大最小空间 |
-compile | 输出即时编译器编译过的方法、耗时等信息 |
-printcompilation | 输出即时编译过的方法 |
执行样例
jstat -gcutil 2764
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.00 0.00 6.20 41.42 47.20 16 0.105 3 0.472 0.577
jinfo
实时查看和调整JVM各项参数。
命令格式
jinfo [ option ] pid
option
option | comment |
---|---|
-flag | to print the value of the named VM flag |
-flag [+|-] | to enable or disable the named VM flag |
-flag = | to set the named VM flag to the given value |
-flags | to print VM flags |
-sysprops | to print Java system properties |
to print both of the above | |
-h | -help |
执行样例
jinfo -flag CMSInitiatingOccupancyFraction 1444
-XX:CMSInitiatingOccupancyFraction=85
jmap
生成堆转储快照(dump文件)。
命令格式
jmap [ option ] vmid
option
option | 说明 |
---|---|
to print same info as Solaris pmap | |
-heap | to print java heap summary |
-histo[:live] | to print histogram of java object heap; if the “live” suboption is specified, only count live objects |
-clstats | to print class loader statistics |
-finalizerinfo | to print information on objects awaiting finalization |
-dump:<dump-options> | to dump java heap in hprof binary format dump-options: live : dump only live objects; if not specified, all objects in the heap are dumped. format=b : binary format file=<file> : dump heap to <file> Example: jmap -dump:live,format=b,file=heap.bin <vmid> |
-F | force. Use with -dump:<dump-options> <vmid> or -histo to force a heap dump or histogram when <vmid> does not respond. The “live” suboption is not supported in this mode. |
-h | -help | to print this help message |
-J<flag> | to pass directly to the runtime system |
jhat
分析jmap生成的快照
比较少用,自带一个微型http服务器,生成的结果在浏览器查看。
格式
jhat <dump>
jstack
Java堆栈跟踪工具。
用于生成虚拟机当前时刻的线程快照(threaddump)。
格式
jstack [ option ] vmid
option
option | 说明 |
---|---|
-F | to force a thread dump. Use when jstack <vmid> does not respond (process is hung) |
-m | to print both java and native frames (mixed mode) |
-l | long listing. Prints additional information about locks |
-h or -help | to print this help message |
可视化工具
JHSDB
需要命令行启动
命令参考
jhsdb hsdb --pid 11180
JConsole
直接在Java目录的bin目录下,找到jconsole双击启动。
jvisualvm
直接在Java目录的bin目录下,找到jvisualvm双击启动。