JDK中自带的JVM分析工具( 二 )


$ jinfo 1281# 只粘贴个别参数Java System Properties: # 系统参数java.runtime.version=1.8.0_144-b01file.encoding=UTF-8sun.java.command=com.explore.facade.FacadeApp hello,main-methodVM Flags:# 虚拟机参数-XX:InitialHeapSize=134217728 -XX:MaxHeapSize=268435456 -XX:MaxNewSize=267911168VM Arguments:# 运行时参数jvm_args: -Xms128m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256mjava_command: com.explore.facade.FacadeApp hello,main-method$ jinfo -sysprops 1281# 只输出【Java System Properties】参数$ jinfo -flags 1281# 只输出【VM Flags】参数3、jstat命令jstat:以指定的频率输出JVM的监控指标 , 下述命令输出内存占用和GC相关信息 , 每隔3秒输出一次 , 连续打印5次;由于这里只是启动一个简单的微服务 , 没有执行业务逻辑 , 所以各项指标比较平稳;
$ jstat -gcutil 1281 3000 5S0S1EOMCCSYGCYGCTFGCFGCTCGCCGCTGCT0.000.0057.9764.1692.8288.7530.02890.516--0.5440.000.0057.9764.1692.8288.7530.02890.516--0.544该命令是比较常用的 , 这里各项指标的统计逻辑 , 在tools.jar包中有jstat_options参考文档 , 相对路径sun/tools/jstat/resources/目录下;
option gcutil {column {header "^S0^" /* Survivor 0 Space - Percent Used */data (1-((sun.gc.generation.0.space.1.capacity - sun.gc.generation.0.space.1.used)/sun.gc.generation.0.space.1.capacity)) * 100}column {header "^S1^" /* Survivor 1 Space - Percent Used */data (1-((sun.gc.generation.0.space.2.capacity - sun.gc.generation.0.space.2.used)/sun.gc.generation.0.space.2.capacity)) * 100}......}4、jstack命令jstack:输出指定进程当前时刻在JVM中的线程信息 , 为了清楚的展示其效果 , 在服务启动时创建线程死锁 , 然后通过该命令就会把发生死锁的线程打印出来 , 通过输出可以发现两条互相等待的线程信息;
$ jstack 1281Found one Java-level deadlock:============================="test-thread-02":waiting for ownable synchronizer 0x00000007b00a35d0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),which is held by "test-thread-01""test-thread-01":waiting for ownable synchronizer 0x00000007b00a35a0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),which is held by "test-thread-02"Java stack information for the threads listed above:==================================================="test-thread-02":at sun.misc.Unsafe.park(Native Method)- parking to wait for<0x00000007b00a35d0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)"test-thread-01":at sun.misc.Unsafe.park(Native Method)- parking to wait for<0x00000007b00a35a0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)Found 1 deadlock.5、jmap命令jmap:可以输出指定进程的内存中对象映射信息 , 或者堆的关键信息、内存的使用统计、GC算法、配置、类的实例信息及内存占用等 , 该命令在解决JVM问题时也经常使用;
$ jmap 1281$ jmap -heap 1281Heap Configuration:MinHeapFreeRatio= 0MaxHeapFreeRatio= 100MaxHeapSize= 536870912 (512.0MB)Heap Usage:PS Young GenerationEden Space:From Space:To Space:PS Old Generation$ jmap -histo:live 1281 num#instances#bytesclass name----------------------------------------------1311:132com.explore.facade.FacadeApp$$EnhancerBySpringCGLIB$$313d9e3四、可视化工具1、jconsoleJava内置的JVM性能监控工具 , 在熟悉上述的命令行工具之后 , 对于该可视化工具的使用不会太陌生 , 在命令中可以查看到的默认参数或者应用自定义配置 , 在该工具中也可以找到 , 并且以图形化的方式呈现;
$ jconsole# 通过该命令会唤起jconsole界面

JDK中自带的JVM分析工具

经验总结扩展阅读