jvm系列java
垃圾回收基礎算法
JVM的編譯策略shell
GC的三大基礎算法apache
GC的三大高級算法segmentfault
GC策略的評價指標數據結構
JVM信息查看app
GC通用日誌解讀jvm
jvm的card table數據結構async
Java類初始化順序.net
本文主要講述如何查看java應用的jvm信息。
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
java -XX:+PrintFlagsFinal -version |grep manageable
經過選項-XX:+PrintFlagsFinal能夠列出全部的JVM flag,而其中的標註爲manageable 的flag則是值得咱們關注的部分。這些flag可經過JDK management interface(-XX:+PrintFlagsFinal)動態修改。
-XX:+PrintGCDetails
jinfo -flag -PrintGCDetails 12278
[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.
查看對象分佈
[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