本文主要是介绍JAVA1.8开发工具使用系列 故障排除之jcmd,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
常用指令:
#打印jvm进程,查看pid
jcmd -l#dump快照
jcmd pid GC.heap_dump fillpath.....hprof#查看java系统属性
jcmd pid VM.system_properties#查看jvm属性
jcmd pid VM.flags#查看jvm启动指定属性
jcmd pid VM.command_line#强制调用已经失去引用的对象的finalize方法
#system.runFinalization()
jcmd pid GC.run_finalization#告诉垃圾收集器打算进行垃圾收集,而垃圾收集器进不进行收集是不确定的
#System.gc()
jcmd pid GC.run#查看jdk属性
jcmd pid PerfCounter.print#查看jvm版本
jcmd pid VM.version#查看系统中类统计信息
jcmd pid GC.class_histogram#查看线程堆栈信息。
jcmd pid Thread.print
jcmd -h
Usage: jcmd <pid | main class> <command ...|PerfCounter.print|-f file>or: jcmd -lor: jcmd -hcommand 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 partiallyor 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
用法概览:
jcmd [-l|-h|-help]jcmd pid|main-class PerfCounter.printjcmd pid|main-class -f filenamejcmd pid|main-class command[ arguments]
1 如果jcmd不带参数或使用该-l选项运行,它将打印运行Java进程标识符的列表,其中包含用于启动进程的主类和命令行参数。jcmd使用-h或-help选项运行会打印工具的帮助消息。eg:
C:\Users\top>jcmd
1492 org.jetbrains.jps.cmdline.Launcher D:/ideaIU-2017/lib/jps-builders-6.jar;D:/ideaIU-2017/lib/httpcore-4.4.5.jar;D:/ideaIU-2017/lib/slf4j-api-1.7.10.jar;D:/ideaIU-2017/lib/netty-all-4.1.13.Final.jar;D:/ideaIU-2017/lib/jgoodies-forms.jar;D:/ideaIU-2017/lib/resources_en.jar;D:/ideaIU-2017/lib/forms_rt.jar;D:/ideaIU-2017/lib/httpclient-4.5.2.jar;D:/ideaIU-2017/lib/javac2.jar;D:/ideaIU-2017/lib/idea_rt.jar;D:/ideaIU-2017/lib/commons-logging-1.2.jar;D:/ideaIU-2017/lib/aether-dependency-resolver.jar;D:/ideaIU-2017/lib/asm-all.jar;D:/ideaIU-2017/lib/protobuf-java-2.5.0.jar;D:/ideaIU-2017/lib/jps-builders.jar;D:/ideaIU-2017/lib/jna.jar;D:/ideaIU-2017/lib/commons-codec-1.9.jar;D:/ideaIU-2017/lib/guava-21.0.jar;D:/ideaIU-2017/lib/snappy-in-java-0.5.1.jar;D:/ideaIU-2017/lib/jdom.jar;D:/ideaIU-2017/lib/nanoxml-2.2.3.jar;D:/ideaIU-2017/lib/log4j.jar;D:/ideaIU-2017/lib/openapi.jar;D:/ideaIU-2017/lib/jna-platform.jar;D:/ideaIU-2017/lib/aether-1.1.0-all.jar;D:/ideaIU-2017/lib/maven-aether-provider-3.3.9-all.jar;D:/ideaIU-2017/
15492 com.jianghua.warehousemanager.WarehouseManagerApplication
820
2152 sun.tools.jcmd.JCmd
12412 org.jetbrains.idea.maven.server.RemoteMavenServer
2 如果将进程标识符(pid)或主类(main-class)指定为第一个参数,jcmd则将诊断命令请求发送到具有指定标识符的Java进程,或发送到具有指定主类的名称的所有Java进程。您还可以通过指定0进程标识符将诊断命令请求发送到所有可用的Java进程。使用以下其中一项作为诊断命令请求:
2.1 Perfcounter.print
打印指定Java进程可用的性能计数器。性能计数器列表可能因Java进程而异。
jcmd 15492 PerfCounter.print
15492:
java.ci.totalTime=6515941
java.cls.loadedClasses=8250
java.cls.sharedLoadedClasses=0
java.cls.sharedUnloadedClasses=0
java.cls.unloadedClasses=2
java.property.java.class.path="C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.j"
java.property.java.endorsed.dirs="C:\Program Files\Java\jdk1.8.0_25\jre\lib\endorsed"
java.property.java.ext.dirs="C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"
java.property.java.home="C:\Program Files\Java\jdk1.8.0_25\jre"
java.property.java.library.path="C:\Program Files\Java\jdk1.8.0_25\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:\Program Files (x86)\NetSarang\Xshell 6\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\apache-maven-3.5.0\bin;D:\Program Files\erl9.3\bin;D:\Program Files\RabbitMQ Server\rabbitmq_server-3."
java.property.java.version="1.8.0_25"
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.25-b02"
java.rt.vmArgs="-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50399,suspend=y,server=n -XX:TieredStopAtLevel=1 -Xverify:none -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=50397 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\ideaIU-2017\lib\rt\debugger-agent.jar=C:\Users\top\AppData\Local\Temp\capture4143.props -Dfile.encoding=UTF-8"
java.rt.vmFlags=""
java.threads.daemon=37
java.threads.live=39
java.threads.livePeak=40
java.threads.started=72
sun.ci.compilerThread.0.compiles=0
sun.ci.compilerThread.0.method=""
sun.ci.compilerThread.0.time=0
sun.ci.compilerThread.0.type=0
sun.ci.compilerThread.1.compiles=0
sun.ci.compilerThread.1.method=""
sun.ci.compilerThread.1.time=0
sun.ci.compilerThread.1.type=0
sun.ci.compilerThread.2.compiles=0
sun.ci.compilerThread.2.method=""
sun.ci.compilerThread.2.time=0
sun.ci.compilerThread.2.type=0
sun.ci.compilerThread.3.compiles=4372
sun.ci.compilerThread.3.method=""
sun.ci.compilerThread.3.time=1762
sun.ci.compilerThread.3.type=1
sun.ci.lastFailedMethod="org/springframework/core/annotation/AnnotationUtils findAnnotation"
sun.ci.lastFailedType=1
sun.ci.lastInvalidatedMethod=""
sun.ci.lastInvalidatedType=0
sun.ci.lastMethod="org/apache/catalina/core/StandardContext getInstanceManager"
sun.ci.lastSize=5
sun.ci.lastType=1
sun.ci.nmethodCodeSize=2751264
sun.ci.nmethodSize=6365464
sun.ci.osrBytes=6195
sun.ci.osrCompiles=12
sun.ci.osrTime=60514
sun.ci.standardBytes=482113
sun.ci.standardCompiles=4358
sun.ci.standardTime=6455427
sun.ci.threads=4
sun.ci.totalBailouts=2
sun.ci.totalCompiles=4370
sun.ci.totalInvalidates=0
sun.classloader.findClassTime=4684268619
sun.classloader.findClasses=4404
sun.classloader.parentDelegationTime=2558026392
sun.cls.appClassBytes=20963668
sun.cls.appClassLoadCount=5878
sun.cls.appClassLoadTime=15800558
sun.cls.appClassLoadTime.self=6741645
sun.cls.classInitTime=14494541
sun.cls.classInitTime.self=9992143
sun.cls.classLinkedTime=1315425
sun.cls.classLinkedTime.self=1203893
sun.cls.classVerifyTime=108684
sun.cls.classVerifyTime.self=105932
sun.cls.defineAppClassTime=4941866
sun.cls.defineAppClassTime.self=148319
sun.cls.defineAppClasses=4769
sun.cls.initializedClasses=6302
sun.cls.isUnsyncloadClassSet=0
sun.cls.jniDefineClassNoLockCalls=74
sun.cls.jvmDefineClassNoLockCalls=4531
sun.cls.jvmFindLoadedClassNoLockCalls=15358
sun.cls.linkedClasses=7201
sun.cls.loadInstanceClassFailRate=0
sun.cls.loadedBytes=16110752
sun.cls.lookupSysClassTime=1533991
sun.cls.methodBytes=7767220
sun.cls.nonSystemLoaderLockContentionRate=1
sun.cls.parseClassTime=6257303
sun.cls.parseClassTime.self=3994972
sun.cls.sharedClassLoadTime=3318
sun.cls.sharedLoadedBytes=0
sun.cls.sharedUnloadedBytes=0
sun.cls.sysClassBytes=11492811
sun.cls.sysClassLoadTime=3694831
sun.cls.systemLoaderLockContentionRate=0
sun.cls.time=26219864
sun.cls.unloadedBytes=1968
sun.cls.unsafeDefineClassCalls=708
sun.cls.verifiedClasses=7186
sun.gc.cause="No GC"
sun.gc.collector.0.invocations=10
sun.gc.collector.0.lastEntryTime=2797453066
sun.gc.collector.0.lastExitTime=2797482350
sun.gc.collector.0.name="PSScavenge"
sun.gc.collector.0.time=335581
sun.gc.collector.1.invocations=2
sun.gc.collector.1.lastEntryTime=23809106
sun.gc.collector.1.lastExitTime=24027103
sun.gc.collector.1.name="PSParallelCompact"
sun.gc.collector.1.time=376083
sun.gc.compressedclassspace.capacity=6160384
sun.gc.compressedclassspace.maxCapacity=1073741824
sun.gc.compressedclassspace.minCapacity=0
sun.gc.compressedclassspace.used=5794936
sun.gc.generation.0.capacity=254803968
sun.gc.generation.0.maxCapacity=1428160512
sun.gc.generation.0.minCapacity=89128960
sun.gc.generation.0.name="new"
sun.gc.generation.0.space.0.capacity=220725248
sun.gc.generation.0.space.0.initCapacity=0
sun.gc.generation.0.space.0.maxCapacity=1427111936
sun.gc.generation.0.space.0.name="eden"
sun.gc.generation.0.space.0.used=62846632
sun.gc.generation.0.space.1.capacity=7340032
sun.gc.generation.0.space.1.initCapacity=0
sun.gc.generation.0.space.1.maxCapacity=476053504
sun.gc.generation.0.space.1.name="s0"
sun.gc.generation.0.space.1.used=6900808
sun.gc.generation.0.space.2.capacity=16252928
sun.gc.generation.0.space.2.initCapacity=0
sun.gc.generation.0.space.2.maxCapacity=476053504
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=164102144
sun.gc.generation.1.maxCapacity=2856321024
sun.gc.generation.1.minCapacity=179306496
sun.gc.generation.1.name="old"
sun.gc.generation.1.space.0.capacity=164102144
sun.gc.generation.1.space.0.initCapacity=179306496
sun.gc.generation.1.space.0.maxCapacity=2856321024
sun.gc.generation.1.space.0.name="old"
sun.gc.generation.1.space.0.used=19273200
sun.gc.generation.1.spaces=1
sun.gc.lastCause="Allocation Failure"
sun.gc.metaspace.capacity=47054848
sun.gc.metaspace.maxCapacity=1115684864
sun.gc.metaspace.minCapacity=0
sun.gc.metaspace.used=45027024
sun.gc.policy.avgBaseFootprint=268435456
sun.gc.policy.avgMajorIntervalTime=4718
sun.gc.policy.avgMajorPauseTime=73
sun.gc.policy.avgMinorIntervalTime=217260
sun.gc.policy.avgMinorPauseTime=12
sun.gc.policy.avgOldLive=13402272
sun.gc.policy.avgPretenuredPaddedAvg=0
sun.gc.policy.avgPromotedAvg=486228
sun.gc.policy.avgPromotedDev=708313
sun.gc.policy.avgPromotedPaddedAvg=2611169
sun.gc.policy.avgSurvivedAvg=9417064
sun.gc.policy.avgSurvivedDev=2213599
sun.gc.policy.avgSurvivedPaddedAvg=16057863
sun.gc.policy.avgYoungLive=7444708
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=6
sun.gc.policy.decrementTenuringThresholdForGcCost=0
sun.gc.policy.decrementTenuringThresholdForSurvivorLimit=0
sun.gc.policy.desiredSurvivorSize=16252928
sun.gc.policy.edenSize=220725248
sun.gc.policy.freeSpace=362283008
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=1
sun.gc.policy.liveAtLastFullGc=19248624
sun.gc.policy.liveSpace=289282432
sun.gc.policy.majorCollectionSlope=0
sun.gc.policy.majorGcCost=1
sun.gc.policy.majorPauseOldSlope=976
sun.gc.policy.majorPauseYoungSlope=327
sun.gc.policy.maxTenuringThreshold=15
sun.gc.policy.minorCollectionSlope=0
sun.gc.policy.minorGcCost=0
sun.gc.policy.minorPauseOldSlope=-1
sun.gc.policy.minorPauseTime=11
sun.gc.policy.minorPauseYoungSlope=-2
sun.gc.policy.mutatorCost=97
sun.gc.policy.name="ParScav:MSC"
sun.gc.policy.oldCapacity=164102144
sun.gc.policy.oldEdenSize=227540992
sun.gc.policy.oldPromoSize=141557760
sun.gc.policy.promoSize=141557760
sun.gc.policy.promoted=0
sun.gc.policy.scavengeSkipped=0
sun.gc.policy.survived=6900808
sun.gc.policy.survivorOverflowed=0
sun.gc.policy.tenuringThreshold=9
sun.gc.policy.youngCapacity=243793920
sun.gc.tlab.alloc=29317099
sun.gc.tlab.allocThreads=8
sun.gc.tlab.fastWaste=912
sun.gc.tlab.fills=92
sun.gc.tlab.gcWaste=456661
sun.gc.tlab.maxFastWaste=912
sun.gc.tlab.maxFills=85
sun.gc.tlab.maxGcWaste=284393
sun.gc.tlab.maxSlowAlloc=0
sun.gc.tlab.maxSlowWaste=36
sun.gc.tlab.slowAlloc=0
sun.gc.tlab.slowWaste=36
sun.management.JMXConnectorServer.0.authenticate="false"
sun.management.JMXConnectorServer.0.remoteAddress="service:jmx:rmi:///jndi/rmi://DESKTOP-TBLF8C4:50397/jmxrmi"
sun.management.JMXConnectorServer.0.ssl="false"
sun.management.JMXConnectorServer.0.sslNeedClientAuth="false"
sun.management.JMXConnectorServer.0.sslRegistry="false"
sun.management.JMXConnectorServer.address="service:jmx:rmi://127.0.0.1/stub/rO0ABXNyAC5qYXZheC5tYW5hZ2VtZW50LnJlbW90ZS5ybWkuUk1JU2VydmVySW1wbF9TdHViAAAAAAAAAAICAAB4cgAaamF2YS5ybWkuc2VydmVyLlJlbW90ZVN0dWLp/tzJi+FlGgIAAHhyABxqYXZhLnJtaS5zZXJ2ZXIuUmVtb3RlT2JqZWN002G0kQxhMx4DAAB4cHc0AAtVbmljYXN0UmVmMgAACWxvY2FsaG9zdAAAxOda9ANebVV/At4nzLYAAAFr9iY+7YACAHg="
sun.os.hrt.frequency=2531253
sun.os.hrt.ticks=3072442931
sun.perfdata.majorVersion=2
sun.perfdata.minorVersion=0
sun.perfdata.overflow=0
sun.perfdata.size=65536
sun.perfdata.timestamp=8393038
sun.perfdata.used=21072
sun.property.sun.boot.class.path="C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\classes;D:\ideaIU-2017\lib\rt\debugger-agent-storage.jar"
sun.property.sun.boot.library.path="C:\Program Files\Java\jdk1.8.0_25\jre\bin"
sun.rt._sync_ContendedLockAttempts=564
sun.rt._sync_Deflations=9910
sun.rt._sync_EmptyNotifications=0
sun.rt._sync_FailedSpins=0
sun.rt._sync_FutileWakeups=42
sun.rt._sync_Inflations=9913
sun.rt._sync_MonExtant=1536
sun.rt._sync_MonInCirculation=0
sun.rt._sync_MonScavenged=0
sun.rt._sync_Notifications=701
sun.rt._sync_Parks=1070
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=2795748137
sun.rt.createVmBeginTime=1563202828476
sun.rt.createVmEndTime=1563202831792
sun.rt.internalVersion="Java HotSpot(TM) 64-Bit Server VM (25.25-b02) for windows-amd64 JRE (1.8.0_25-b18), built on Oct 7 2014 14:25:37 by "java_re" with MS VC++ 10.0 (VS2010)"
sun.rt.interruptedBeforeIO=0
sun.rt.interruptedDuringIO=0
sun.rt.javaCommand="com.jianghua.warehousemanager.WarehouseManagerApplication"
sun.rt.jvmCapabilities="1100000000000000000000000000000000000000000000000000000000000000"
sun.rt.jvmVersion=421068802
sun.rt.safepointSyncTime=31898
sun.rt.safepointTime=819771
sun.rt.safepoints=162
sun.rt.threadInterruptSignaled=0
sun.rt.vmInitDoneTime=1563202828655
sun.threads.vmOperationTime=751616
sun.urlClassLoader.readClassBytesTime=1021008580
sun.zip.zipFile.openTime=66474979
sun.zip.zipFiles=353
2.2 -f 文件名
从中读取诊断命令并将其发送到指定Java进程的文件的名称。仅与-f选项一起使用。文件中的每个命令都必须写在一行上。以数字符号(#)开头的行将被忽略。读取所有行或读取包含stop关键字的行时,文件的处理结束。
2.3 命令 [ 参数 ]
要发送到指定Java进程的命令。可以通过将help命令发送到此过程来获取给定进程的可用诊断命令列表。每个诊断命令都有自己的参数集。要查看命令的描述,语法和可用参数列表,请使用命令的名称作为命令的参数help。
注意:如果任何参数包含空格,则必须用单引号或双引号('或")括起它们。此外,必须使用反斜杠(\)转义单引号或双引号,以防止操作系统shell处理引号。或者,您可以使用单引号括起这些参数,然后使用双引号(或使用双引号,然后使用单引号)。
常用命令:
###system.runFinalization()
jcmd pid GC.run_finalization###System.gc()
jcmd pid GC.run
官方地址
这篇关于JAVA1.8开发工具使用系列 故障排除之jcmd的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!