JVM調優中經常用到的幾個命令
jcmd-查詢jvm程序資訊
jcmd命令預設是查詢jvm程序資訊,也可以執行相關的jvm命令。
幫助資訊
F:\soft\Java\jdk1.8\bin>jcmd -h
Usage: jcmd <pid | main class> <command ...|PerfCounter.print|-f file>
or: jcmd -l
or: jcmd -h
command must be a valid jcmd command for the selected jvm.
Use the command "help" to see which commands are available.
If the pid is 0, commands will be sent to all Java processes.
The main class argument will be used to match (either partially
or fully) the class used to start Java.
If no options are given, lists Java processes (same as -p).
PerfCounter.print display the counters exposed by this process
-f read and execute commands from the file
-l list JVM processes on the local machine
-h this help
使用例項 1
F:\soft\Java\jdk1.8\bin>jcmd
3068 sun.tools.jcmd.JCmd
使用示例 2
使用命令:
jcmd 9816 PerfCounter.print
可詳細列印對應java程序的有效效能計數器(performance counters)。
9816:
java.ci.totalTime=106668
java.cls .loadedClasses=639
java.cls.sharedLoadedClasses=0
java.cls.sharedUnloadedClasses=0
java.cls.unloadedClasses=0
java.property.java.class.path="boss-1.0.1.jar"
java.property.java.endorsed.dirs="F:\soft\Java\jre1.8\lib\endorsed"
java.property.java.ext.dirs="F:\soft\Java\jre1.8\lib\ext;C:\Windows\Sun\Java\lib\ext"
java.property.java.home="F:\soft\Java\jre1.8"
java.property.java.library.path="C:\ProgramData\Oracle\Java\javapath;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\soft\svn\bin;F:\soft\Java\jdk1.8\bin;E:\DTool\sdk\platform-tools;E:\DTool\sdk\tools;%MAVEN_HOME%\bin;D:\apache-maven-3.3.9\bin;D:\soft\MySQL\MySQLServer\bin;D:\as\gradle\gradle-2.14.1\bin;H:\php56\;H:\php56\ext;H:\DownLoad\apache-ant-1.10.1\bin;F:\Program Files\Git\cmd;F:\Program Files\Git\mingw64\bin;F:\Program Files\Git\usr\bin;F:\Program Files\VisualSVN Server\bin;F:\soft\python3;F:\Program Files (x86)\AllWinnerTech\PhoenixSuit\;."
java.property.java.version="1.8.0_101"
java.property.java.vm.info="mixed mode"
java.property.java.vm.name="Java HotSpot(TM) 64-Bit Server VM"
java.property.java.vm.specification.name="Java Virtual Machine Specification"
java.property.java.vm.specification.vendor="Oracle Corporation"
java.property.java.vm.specification.version="1.8"
java.property.java.vm.vendor="Oracle Corporation"
java.property.java.vm.version="25.101-b13"
java.rt.vmArgs=""
java.rt.vmFlags=""
java.threads.daemon=4
java.threads.live=11
java.threads.livePeak=11
java.threads.started=12
sun.ci.compilerThread.0.compiles=8
sun.ci.compilerThread.0.method=""
sun.ci.compilerThread.0.time=4
sun.ci.compilerThread.0.type=1
sun.ci.compilerThread.1.compiles=4
sun.ci.compilerThread.1.method=""
sun.ci.compilerThread.1.time=3
sun.ci.compilerThread.1.type=1
sun.ci.compilerThread.2.compiles=97
sun.ci.compilerThread.2.method=""
sun.ci.compilerThread.2.time=10
sun.ci.compilerThread.2.type=1
sun.ci.lastFailedMethod=""
sun.ci.lastFailedType=0
sun.ci.lastInvalidatedMethod=""
sun.ci.lastInvalidatedType=0
sun.ci.lastMethod="sun/misc/ASCIICaseInsensitiveComparator compare"
sun.ci.lastSize=264
sun.ci.lastType=1
sun.ci.nmethodCodeSize=100000
sun.ci.nmethodSize=167824
sun.ci.osrBytes=0
sun.ci.osrCompiles=0
sun.ci.osrTime=0
sun.ci.standardBytes=7514
sun.ci.standardCompiles=109
sun.ci.standardTime=106668
sun.ci.threads=3
sun.ci.totalBailouts=0
sun.ci.totalCompiles=109
sun.ci.totalInvalidates=0
sun.classloader.findClassTime=24540700
sun.classloader.findClasses=46
sun.classloader.parentDelegationTime=3007529
sun.cls.appClassBytes=137124
sun.cls.appClassLoadCount=106
sun.cls.appClassLoadTime=53848
sun.cls.appClassLoadTime.self=24776
sun.cls.classInitTime=124090
sun.cls.classInitTime.self=77927
sun.cls.classLinkedTime=74692
sun.cls.classLinkedTime.self=28333
sun.cls.classVerifyTime=46283
sun.cls.classVerifyTime.self=15996
sun.cls.defineAppClassTime=19317
sun.cls.defineAppClassTime.self=760
sun.cls.defineAppClasses=46
sun.cls.initializedClasses=500
sun.cls.isUnsyncloadClassSet=0
sun.cls.jniDefineClassNoLockCalls=0
sun.cls.jvmDefineClassNoLockCalls=46
sun.cls.jvmFindLoadedClassNoLockCalls=212
sun.cls.linkedClasses=588
sun.cls.loadInstanceClassFailRate=0
sun.cls.loadedBytes=1298848
sun.cls.lookupSysClassTime=26691
sun.cls.methodBytes=830360
sun.cls.nonSystemLoaderLockContentionRate=0
sun.cls.parseClassTime=90729
sun.cls.parseClassTime.self=77100
sun.cls.sharedClassLoadTime=25
sun.cls.sharedLoadedBytes=0
sun.cls.sharedUnloadedBytes=0
sun.cls.sysClassBytes=2114821
sun.cls.sysClassLoadTime=122868
sun.cls.systemLoaderLockContentionRate=0
sun.cls.time=265053
sun.cls.unloadedBytes=0
sun.cls.unsafeDefineClassCalls=0
sun.cls.verifiedClasses=559
sun.gc.cause="No GC"
sun.gc.collector.0.invocations=0
sun.gc.collector.0.lastEntryTime=0
sun.gc.collector.0.lastExitTime=0
sun.gc.collector.0.name="PSScavenge"
sun.gc.collector.0.time=0
sun.gc.collector.1.invocations=0
sun.gc.collector.1.lastEntryTime=0
sun.gc.collector.1.lastExitTime=0
sun.gc.collector.1.name="PSParallelCompact"
sun.gc.collector.1.time=0
sun.gc.compressedclassspace.capacity=393216
sun.gc.compressedclassspace.maxCapacity=1073741824
sun.gc.compressedclassspace.minCapacity=0
sun.gc.compressedclassspace.used=77664
sun.gc.generation.0.capacity=44564480
sun.gc.generation.0.maxCapacity=706740224
sun.gc.generation.0.minCapacity=44564480
sun.gc.generation.0.name="new"
sun.gc.generation.0.space.0.capacity=34078720
sun.gc.generation.0.space.0.initCapacity=0
sun.gc.generation.0.space.0.maxCapacity=705691648
sun.gc.generation.0.space.0.name="eden"
sun.gc.generation.0.space.0.used=6151536
sun.gc.generation.0.space.1.capacity=5242880
sun.gc.generation.0.space.1.initCapacity=0
sun.gc.generation.0.space.1.maxCapacity=235405312
sun.gc.generation.0.space.1.name="s0"
sun.gc.generation.0.space.1.used=0
sun.gc.generation.0.space.2.capacity=5242880
sun.gc.generation.0.space.2.initCapacity=0
sun.gc.generation.0.space.2.maxCapacity=235405312
sun.gc.generation.0.space.2.name="s1"
sun.gc.generation.0.space.2.used=0
sun.gc.generation.0.spaces=3
sun.gc.generation.1.capacity=89653248
sun.gc.generation.1.maxCapacity=1413480448
sun.gc.generation.1.minCapacity=89653248
sun.gc.generation.1.name="old"
sun.gc.generation.1.space.0.capacity=89653248
sun.gc.generation.1.space.0.initCapacity=89653248
sun.gc.generation.1.space.0.maxCapacity=1413480448
sun.gc.generation.1.space.0.name="old"
sun.gc.generation.1.space.0.used=0
sun.gc.generation.1.spaces=1
sun.gc.lastCause="No GC"
sun.gc.metaspace.capacity=4587520
sun.gc.metaspace.maxCapacity=1082130432
sun.gc.metaspace.minCapacity=0
sun.gc.metaspace.used=764080
sun.gc.policy.avgBaseFootprint=0
sun.gc.policy.avgMajorIntervalTime=0
sun.gc.policy.avgMajorPauseTime=0
sun.gc.policy.avgMinorIntervalTime=0
sun.gc.policy.avgMinorPauseTime=0
sun.gc.policy.avgOldLive=0
sun.gc.policy.avgPretenuredPaddedAvg=0
sun.gc.policy.avgPromotedAvg=34078720
sun.gc.policy.avgPromotedDev=0
sun.gc.policy.avgPromotedPaddedAvg=34078720
sun.gc.policy.avgSurvivedAvg=5242880
sun.gc.policy.avgSurvivedDev=0
sun.gc.policy.avgSurvivedPaddedAvg=5242880
sun.gc.policy.avgYoungLive=0
sun.gc.policy.boundaryMoved=0
sun.gc.policy.changeOldGenForMajPauses=0
sun.gc.policy.changeOldGenForMinPauses=0
sun.gc.policy.changeYoungGenForMajPauses=0
sun.gc.policy.changeYoungGenForMinPauses=0
sun.gc.policy.collectors=2
sun.gc.policy.decideAtFullGc=0
sun.gc.policy.decreaseForFootprint=0
sun.gc.policy.decrementTenuringThresholdForGcCost=0
sun.gc.policy.decrementTenuringThresholdForSurvivorLimit=0
sun.gc.policy.desiredSurvivorSize=0
sun.gc.policy.edenSize=34078720
sun.gc.policy.freeSpace=68157440
sun.gc.policy.fullFollowsScavenge=0
sun.gc.policy.gcTimeLimitExceeded=0
sun.gc.policy.generations=3
sun.gc.policy.increaseOldGenForThroughput=0
sun.gc.policy.increaseYoungGenForThroughput=0
sun.gc.policy.incrementTenuringThresholdForGcCost=0
sun.gc.policy.liveAtLastFullGc=34078720
sun.gc.policy.liveSpace=0
sun.gc.policy.majorCollectionSlope=0
sun.gc.policy.majorGcCost=0
sun.gc.policy.majorPauseOldSlope=0
sun.gc.policy.majorPauseYoungSlope=0
sun.gc.policy.maxTenuringThreshold=15
sun.gc.policy.minorCollectionSlope=0
sun.gc.policy.minorGcCost=0
sun.gc.policy.minorPauseOldSlope=0
sun.gc.policy.minorPauseTime=0
sun.gc.policy.minorPauseYoungSlope=0
sun.gc.policy.mutatorCost=1
sun.gc.policy.name="ParScav:MSC"
sun.gc.policy.oldCapacity=134217728
sun.gc.policy.oldEdenSize=34078720
sun.gc.policy.oldPromoSize=34078720
sun.gc.policy.promoSize=34078720
sun.gc.policy.promoted=0
sun.gc.policy.scavengeSkipped=0
sun.gc.policy.survived=0
sun.gc.policy.survivorOverflowed=0
sun.gc.policy.tenuringThreshold=15
sun.gc.policy.youngCapacity=39321600
sun.gc.tlab.alloc=0
sun.gc.tlab.allocThreads=0
sun.gc.tlab.fastWaste=0
sun.gc.tlab.fills=0
sun.gc.tlab.gcWaste=0
sun.gc.tlab.maxFastWaste=0
sun.gc.tlab.maxFills=0
sun.gc.tlab.maxGcWaste=0
sun.gc.tlab.maxSlowAlloc=0
sun.gc.tlab.maxSlowWaste=0
sun.gc.tlab.slowAlloc=0
sun.gc.tlab.slowWaste=0
sun.os.hrt.frequency=3117841
sun.os.hrt.ticks=112459180
sun.perfdata.majorVersion=2
sun.perfdata.minorVersion=0
sun.perfdata.overflow=0
sun.perfdata.size=65536
sun.perfdata.timestamp=201939
sun.perfdata.used=17616
sun.property.sun.boot.class.path="F:\soft\Java\jre1.8\lib\resources.jar;F:\soft\Java\jre1.8\lib\rt.jar;F:\soft\Java\jre1.8\lib\sunrsasign.jar;F:\soft\Java\jre1.8\lib\jsse.jar;F:\soft\Java\jre1.8\lib\jce.jar;F:\soft\Java\jre1.8\lib\charsets.jar;F:\soft\Java\jre1.8\lib\jfr.jar;F:\soft\Java\jre1.8\classes"
sun.property.sun.boot.library.path="F:\soft\Java\jre1.8\bin"
sun.rt._sync_ContendedLockAttempts=12
sun.rt._sync_Deflations=46
sun.rt._sync_EmptyNotifications=0
sun.rt._sync_FailedSpins=0
sun.rt._sync_FutileWakeups=2
sun.rt._sync_Inflations=50
sun.rt._sync_MonExtant=384
sun.rt._sync_MonInCirculation=0
sun.rt._sync_MonScavenged=0
sun.rt._sync_Notifications=25
sun.rt._sync_Parks=32
sun.rt._sync_PrivateA=0
sun.rt._sync_PrivateB=0
sun.rt._sync_SlowEnter=0
sun.rt._sync_SlowExit=0
sun.rt._sync_SlowNotify=0
sun.rt._sync_SlowNotifyAll=0
sun.rt._sync_SuccessfulSpins=0
sun.rt.applicationTime=12630762
sun.rt.createVmBeginTime=1505290045108
sun.rt.createVmEndTime=1505290045168
sun.rt.internalVersion="Java HotSpot(TM) 64-Bit Server VM (25.101-b13) for windows-amd64 JRE (1.8.0_101-b13), built on Jun 22 2016 01:21:29 by "java_re" with MS VC++ 10.0 (VS2010)"
sun.rt.interruptedBeforeIO=0
sun.rt.interruptedDuringIO=0
sun.rt.javaCommand="boss-1.0.1.jar 2 127.0.0.1 80"
sun.rt.jvmCapabilities="1100000000000000000000000000000000000000000000000000000000000000"
sun.rt.jvmVersion=426049549
sun.rt.safepointSyncTime=238
sun.rt.safepointTime=761
sun.rt.safepoints=3
sun.rt.threadInterruptSignaled=0
sun.rt.vmInitDoneTime=1505290045155
sun.threads.vmOperationTime=184
sun.urlClassLoader.readClassBytesTime=6458313
sun.zip.zipFile.openTime=3587098
sun.zip.zipFiles=2
診斷命令
診斷命令的幫助資訊
D:\>jcmd 9816 help
9816:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
For more information about a specific command use 'help <command>'.
其中9816是某個jvm程序的pid。
具體診斷命令的幫助
如下是GC.run診斷命令的幫助資訊。
D:\>jcmd 9816 help GC.run
9816:
GC.run
Call java.lang.System.gc().
Impact: Medium: Depends on Java heap size and content.
Syntax: GC.run
診斷命令的應用
GC.run診斷命令
診斷前:
D:\>jstat -gcutil 9816 500 7
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
0.00 0.00 24.05 0.00 16.66 19.75 0 0.000 0 0.000 0.000
進行診斷操作:
D:\>jcmd 9816 GC.run
9816:
Command executed successfully
診斷後:
D:\>jstat -gcutil 9816 500 7
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
0.00 0.00 0.00 1.21 79.67 87.24 1 0.001 1 0.004 0.006
在診斷前後,請注意FGC(Full GC)的變化。
VM.flags診斷命令
此命令只是顯示JVM的引數資訊。
D:\>jcmd 9816 VM.flags
9816:
-XX:CICompilerCount=3 -XX:InitialHeapSize=134217728 -XX:MaxHeapSize=2120220672 -XX:MaxNewSize=706740224 -XX:MinHeapDelta
Bytes=524288 -XX:NewSize=44564480 -XX:OldSize=89653248 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFa
stUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
還有更多有用的診斷命令,請自己查驗。
## jinfo-檢視系統資訊和JVM資訊
### 幫助資訊
主要的引數是-flags列印JVM的資訊和-sysprops列印系統的資訊。
F:\soft\Java\jdk1.8\bin>jinfo
Usage:
jinfo [option]
(to connect to running process)
jinfo [option]
### 使用例項
F:\soft\Java\jdk1.8\bin>jinfo 5952
Attaching to process ID 5952, please wait…
Debugger attached successfully.
Server compiler detected.
JVM version is 25.101-b13
Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.101-b13
sun.boot.library.path = F:\soft\Java\jre1.8\bin
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = ;
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = Service Pack 1
sun.java.launcher = SUN_STANDARD
user.script =
user.country = CN
user.dir = D:\web_work\boss\target
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_101-b13
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = F:\soft\Java\jre1.8\lib\endorsed
line.separator =
java.io.tmpdir = C:\Users\MICHAE~1\AppData\Local\Temp\
java.vm.specification.vendor = Oracle Corporation
user.variant =
os.name = Windows 7
sun.jnu.encoding = GBK
java.library.path = C:\ProgramData\Oracle\Java\javapath;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Progra
mData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell
\v1.0\;D:\soft\svn\bin;F:\soft\Java\jdk1.8\bin;E:\DTool\sdk\platform-tools;E:\DTool\sdk\tools;%MAVEN_HOME%\bin;D:\apache
-maven-3.3.9\bin;D:\soft\MySQL\MySQLServer\bin;D:\as\gradle\gradle-2.14.1\bin;H:\php56\;H:\php56\ext;H:\DownLoad\apache-
ant-1.10.1\bin;F:\Program Files\Git\cmd;F:\Program Files\Git\mingw64\bin;F:\Program Files\Git\usr\bin;F:\Program Files\V
isualSVN Server\bin;F:\soft\python3;F:\Program Files (x86)\AllWinnerTech\PhoenixSuit\;.
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 6.1
user.home = C:\Users\MichaelKoo
user.timezone =
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = GBK
java.specification.version = 1.8
user.name = MichaelKoo
java.class.path = boss-1.0.1.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = boss-1.0.1.jar 2 124.42.243.67 8010
java.home = F:\soft\Java\jre1.8
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode
java.version = 1.8.0_101
java.ext.dirs = F:\soft\Java\jre1.8\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path = F:\soft\Java\jre1.8\lib\resources.jar;F:\soft\Java\jre1.8\lib\rt.jar;F:\soft\Java\jre1.8\lib\sunrs
asign.jar;F:\soft\Java\jre1.8\lib\jsse.jar;F:\soft\Java\jre1.8\lib\jce.jar;F:\