首页 » 语言&开发 » Java » JDK命令行工具相关整理(2)

JDK命令行工具相关整理(2)

 

接上一篇blog。

jinfo

用于查询当前运行这的JVM属性和参数的值。

常用的参数为:

参数名解释
-flag显示未被显示指定的参数的系统默认值
-flag [+|-]name或-flag name=value修改部分参数
-sysprops打印虚拟机进程的System.getProperties()

命令格式:jinfo [option] pid


[root@localhost ~]# jinfo 5632 Attaching to process ID 5632, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.79-b02 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 24.79-b02 sun.boot.library.path = /opt/java/jdk1.7.0_79/jre/lib/amd64 java.vendor.url = http://java.oracle.com/ java.vm.vendor = Oracle Corporation path.separator = : storm.home = /opt/storm/apache-storm-0.9.6 file.encoding.pkg = sun.io java.vm.name = Java HotSpot(TM) 64-Bit Server VM sun.os.patch.level = unknown sun.java.launcher = SUN_STANDARD user.country = CN user.dir = /opt/zookeeper/zookeeper-3.4.8/bin java.vm.specification.name = Java Virtual Machine Specification java.runtime.version = 1.7.0_79-b15 java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment os.arch = amd64 java.endorsed.dirs = /opt/java/jdk1.7.0_79/jre/lib/endorsed line.separator = java.io.tmpdir = /tmp java.vm.specification.vendor = Oracle Corporation os.name = Linux sun.jnu.encoding = UTF-8 java.library.path = /usr/local/lib:/opt/local/lib:/usr/lib java.specification.name = Java Platform API Specification java.class.version = 51.0 storm.log.dir = /opt/storm/apache-storm-0.9.6/logs sun.management.compiler = HotSpot 64-Bit Tiered Compilers os.version = 3.10.0-229.el7.x86_64 user.home = /root user.timezone = Asia/Shanghai java.awt.printerjob = sun.print.PSPrinterJob file.encoding = UTF-8 java.specification.version = 1.7 user.name = root java.class.path = 略 java.vm.specification.version = 1.7 sun.arch.data.model = 64 sun.java.command = backtype.storm.daemon.nimbus java.home = /opt/java/jdk1.7.0_79/jre user.language = zh java.specification.vendor = Oracle Corporation storm.options = awt.toolkit = sun.awt.X11.XToolkit java.vm.info = mixed mode java.version = 1.7.0_79 java.ext.dirs = /opt/java/jdk1.7.0_79/jre/lib/ext:/usr/java/packages/lib/ext sun.boot.class.path = /opt/java/jdk1.7.0_79/jre/lib/resources.jar:/opt/java/jdk1.7.0_79/jre/lib/rt.jar:/opt/java/jdk1.7.0_79/jre/lib/sunrsasign.jar:/opt/java/jdk1.7.0_79/jre/lib/jsse.jar:/opt/java/jdk1.7.0_79/jre/lib/jce.jar:/opt/java/jdk1.7.0_79/jre/lib/charsets.jar:/opt/java/jdk1.7.0_79/jre/lib/jfr.jar:/opt/java/jdk1.7.0_79/jre/classes logfile.name = nimbus.log logback.configurationFile = /opt/storm/apache-storm-0.9.6/logback/cluster.xml java.vendor = Oracle Corporation file.separator = / java.vendor.url.bug = http://bugreport.sun.com/bugreport/ sun.io.unicode.encoding = UnicodeLittle sun.cpu.endian = little storm.conf.file = sun.cpu.isalist = VM Flags:

jmap

用于显示当前Java堆和永久代的详细信息(如当前使用的收集器,当前的空间使用率等)

常用的参数为:

参数名解释
-dump生成java堆转储快照
-heap显示java堆详细信息(只在Linux/Solaris下有效)
-F当虚拟机进程对-dump选项没有响应时,可使用这个选项强制生成dump快照(只在Linux/Solaris下有效)
-finalizerinfo显示在F-Queue中等待Finalizer线程执行finalize方法的对象(只在Linux/Solaris下有效)
-histo显示堆中对象统计信息
-permstat以ClassLoader为统计口径显示永久代内存状态(只在Linux/Solaris下有效)

命令格式:jmap [option] vmid


[root@localhost sahinn]# jmap -histo 5632 > /tmp/jmsp_5632.log

查看堆详细信息:jmap -heap 5632

生成dump文件: jmap -dump:file=./5632.dump 5632

查看当前堆中对象统计信息:sudo jmap -histo 5632:该命令显示3列,分别为对象数量,对象大小,对象名称,通过该命令可以查看是否内存中有大对象;

jhat

用于分析使用jmap生成的dump文件,是JDK自带的工具,

使用方法为: jhat -J -Xmx512m [file]

推荐使用带图形界面的软件分析,比如mat

jstack

用于生成当前JVM的所有线程快照,线程快照是虚拟机每一条线程正在执行的方法,目的是定位线程出现长时间停顿的原因。

打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,或者生成程序奔溃时的堆栈信息。

参数名解释
-F当正常输出的请求不被响应时,强制输出线程堆栈
-l除堆栈外,显示关于锁的附加信息
-m如果调用到本地方法的话,可以显示C/C++的堆栈

命令格式:jstack [option] vmid

dump 文件里,值得关注的线程状态有:
 死锁,Deadlock(重点关注)

 执行中,Runnable  

 等待资源,Waiting on condition(重点关注)

 等待获取监视器,Waiting on monitor entry(重点关注)

 暂停,Suspended

 对象等待中,Object.wait() 或 TIMED_WAITING

 阻塞,Blocked(重点关注) 

 停止,Parked

一般导出到文件里面进行分析。


[root@localhost sahinn]# jstack 5632 > /tmp/jstack_5632.log


原文链接:JDK命令行工具相关整理(2),转载请注明来源!

0