JVM信息查看

2

jvm系列

本文主要讲述如何查看java应用的jvm信息。

1、查看所有参数 jinfo -flags pid

Java -XX:+PrintCommandLineFlags 这个参数的作用是显示出VM初始化完毕后所有跟最初的默认值不同的参数及它们的值。 (JDK5以上支持)

-XX:+PrintFlagsFinal显示所有可设置的参数及它们的值( JDK 6 update 21开始才可以用),默认是不包括diagnostic或experimental系的。要在-XX:+PrintFlagsFinal的输出里看到这两种参数的信息,分别需要显式指定-XX:+UnlockDiagnosticVMOptions / -XX:+UnlockExperimentalVMOptions

-XX:+PrintFlagsInitial看下所有XX参数的默认值,也可以通过-XX:+PrintFlagsFinal进行对比出修改过的参数,当然通过-XX:+PrintCommandLineFlags就可以自动显示出修改过的值

jinfo -flags pid

[xixicat@cloud01 ~]$ jps 
9275 Jps
22855 start.jar
22869 XmlConfiguration
20967 Application
[xixicat@cloud01 ~]$ jinfo -flags 22869
Attaching to process ID 22869, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.21-b01
-javaagent:/opt/xixicat/apps/lib/jolokia-jvm-1.1.0-agent.jar=port=23061 -Xloggc:/var/xixicat/logs/app.gc.log.201504301631 -XX:ErrorFile=/var/xixicat/logs/app.vmerr.log.201504301631 -XX:HeapDumpPath=/var/xixicat/logs/app.heaperr.log.201504301631 -Xmx5g -Xms5g -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+PrintCommandLineFlags -XX:+PrintAdaptiveSizePolicy -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:StringTableSize=49999 -Djetty.home=/opt/xixicat/apps/server/jetty-distribution-8.1.9.v20130131 -Dapp.port=8061 -Dmedis_environment=online -Dcore.step=app -DSTOP.PORT=38061 -Djetty.port=8061 -Dcom.sun.management.jmxremote.authenticate=false -Dapp.logdir=/var/xixicat/logs -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dapp.ip=10.64.28.207 -Dapp.context -Dcom.sun.management.jmxremote.ssl=false -Djetty.context -Djava.io.tmpdir=/tmp -Djetty.host=cloud01 -Djava.net.preferIPv6Addresses=false -DSTOP.KEY=stop_app -Dcore.zookeeper=127.0.0.1:9331 -Djetty.logs=/var/xixicat/logs -Dapp.workdir=/opt/xixicat/apps/app/work -Dapp.key=app -Dfile.encoding=UTF-8 -Dapp.host=cloud01 -Duser.timezone=GMT+08 -Djetty.appkey=app -DAsyncLogger.WaitStrategy=Block -Dcom.sun.management.jmxremote.port=8199 -Djetty.home=/opt/xixicat/apps/server/jetty-distribution-8.1.9.v20130131 -Denvironment=online

2、查看可用jinfo -flag修改的Java参数

java -XX:+PrintFlagsFinal -version |grep manageable
通过选项-XX:+PrintFlagsFinal可以列出所有的JVM flag,而其中的标注为manageable 的flag则是值得我们关注的部分。这些flag可通过JDK management interface(-XX:+PrintFlagsFinal)动态修改。

-XX:+PrintGCDetails

jinfo -flag -PrintGCDetails 12278

3、jmap -heap pid 查看目前堆情况

[xixicat@cloud01 ~]$ jmap -heap 22869
Attaching to process ID 22869, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.21-b01
using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 5368709120 (5120.0MB)
   NewSize          = 1363144 (1.2999954223632812MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5452592 (5.1999969482421875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 20971520 (20.0MB)
   MaxPermSize      = 268435456 (256.0MB)
   G1HeapRegionSize = 2097152 (2.0MB)
Heap Usage:
G1 Heap:
   regions  = 2560
   capacity = 5368709120 (5120.0MB)
   used     = 3826721792 (3649.4462890625MB)
   free     = 1541987328 (1470.5537109375MB)
   71.27824783325195% used
G1 Young Generation:
Eden Space:
   regions  = 1068
   capacity = 2808086528 (2678.0MB)
   used     = 2239758336 (2136.0MB)
   free     = 568328192 (542.0MB)
   79.76101568334578% used
Survivor Space:
   regions  = 29
   capacity = 60817408 (58.0MB)
   used     = 60817408 (58.0MB)
   free     = 0 (0.0MB)
   100.0% used
G1 Old Generation:
   regions  = 1000
   capacity = 2499805184 (2384.0MB)
   used     = 1524048896 (1453.4462890625MB)
   free     = 975756288 (930.5537109375MB)
   60.96670675597735% used
Perm Generation:
   capacity = 171966464 (164.0MB)
   used     = 170752872 (162.8426284790039MB)
   free     = 1213592 (1.1573715209960938MB)
   99.29428565792921% used
48213 interned Strings occupying 5246936 bytes.

4、jmap -histo:live pid | head -7

查看对象分布

5、jcmd pid VM.flags

[xixicat@cloud01 ~]$ jcmd 15308 VM.flags
15308:
-XX:+DisableExplicitGC -XX:ErrorFile=/var/xixicat/logs/app.vmerr.log.201505071655 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/xixicat/logs/app.heaperr.log.201505071655 -XX:InitialHeapSize=5368709120 -XX:+ManagementServer -XX:MaxGCPauseMillis=100 -XX:MaxHeapSize=5368709120 -XX:MaxPermSize=268435456 -XX:+PrintAdaptiveSizePolicy -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:StringTableSize=49999 -XX:+UnlockExperimentalVMOptions -XX:+UseCompressedOops -XX:+UseG1GC 

如果觉得我的文章对你有用,请随意赞赏

你可能感兴趣的

载入中...