java 15: jcmd的常用命令

一,jcmd查看帮助

[lhdop@blog ~]$ 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 -l).
 
  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 --help print this help message
2,查看特定进程支持的命令
[lhdop@blog ~]$ jcmd 5426 help
5426:
The following commands are available:
Compiler.CodeHeap_Analytics
Compiler.codecache
Compiler.codelist
Compiler.directives_add
Compiler.directives_clear
Compiler.directives_print
Compiler.directives_remove
Compiler.queue
GC.class_histogram
GC.finalizer_info
GC.heap_dump
GC.heap_info
GC.run
GC.run_finalization
JFR.check
JFR.configure
….
3,查看特定命令的帮助:
[lhdop@blog ~]$ jcmd 5426 help VM.version
5426:
VM.version
Print JVM version information.
 
Impact: Low
 
Permission: java.util.PropertyPermission(java.vm.version, read)
 
Syntax: VM.version

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/06/01/java-15-jcmd-de-chang-yong-ming-ling/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,jcmd的常用命令

1,jcmd不加参数:查看进程:
[lhdop@blog ~]$ jcmd
5426 /data/store/back/jar/storeback-0.0.1-SNAPSHOT.jar --spring.config.location=/data/store/back/conf/application.yml
6466 jdk.jcmd/sun.tools.jcmd.JCmd
相当于jps
[lhdop@blog ~]$ jps -lm
5426 /data/store/back/jar/storeback-0.0.1-SNAPSHOT.jar --spring.config.location=/data/store/back/conf/application.yml
6523 jdk.jcmd/sun.tools.jps.Jps -lm
2,查看某个进程的jvm版本
[lhdop@blog ~]$ jcmd 5426 VM.version
5426:
Java HotSpot(TM) 64-Bit Server VM version 15+36-1562
JDK 15.0.0
3,查看jvm进程的统计信息
[lhdop@blog ~]$ jcmd 5426 VM.info
5426:
#
# JRE version: Java(TM) SE Runtime Environment (15.0+36) (build 15+36-1562)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (15+36-1562, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
 
---------------  S U M M A R Y ——————
….
4,查看jvm进程的启动参数(相当于jinfo -flags)
[lhdop@blog ~]$ jcmd 5426 VM.flags
5426:
-XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1ConcRefinementThreads=4 -XX:G1HeapRegionSize=2097152 -XX:GCDrainStackTargetSize=64 
-XX:InitialHeapSize=251658240 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=4026531840 -XX:MaxNewSize=2415919104 -XX:MinHeapDeltaBytes=2097152
-XX:MinHeapSize=8388608 -XX:NonNMethodCodeHeapSize=5832780 -XX:NonProfiledCodeHeapSize=122912730 -XX:ProfiledCodeHeapSize=122912730
-XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:SoftMaxHeapSize=4026531840 -XX:+UseCompressedClassPointers
-XX:+UseCompressedOops -XX:+UseG1GC
5,查看进程到现在运行了多长时间
[lhdop@blog ~]$ jcmd 5426 VM.uptime
5426:
103968.834 s
6,打印线程栈信息(相当于jstack命令)
[lhdop@blog ~]$ jcmd 5426 Thread.print
5426:
2022-03-24 22:00:34
Full thread dump Java HotSpot(TM) 64-Bit Server VM (15+36-1562 mixed mode, sharing):
 
Threads class SMR info:
_java_thread_list=0x00007f86440559b0, length=30, elements={
0x00007f86b819f010, 0x00007f86b81a0750, 0x00007f86b81a9f40, 0x00007f86b81ab650,
0x00007f86b81ad270, 0x00007f86b81aeaa0, 0x00007f86b81b01a0, 0x00007f86b81ed6d0,
0x00007f86b81f0cd0, 0x00007f86b8e52a90, 0x00007f86b8299ac0, 0x00007f86b8e98680,
0x00007f8628005ed0, 0x00007f86b917c580, 0x00007f86b874cae0, 0x00007f86b8dc2790,
0x00007f86b9051ed0, 0x00007f86b8028a10, 0x00007f8618004800, 0x00007f86180053e0,
0x00007f864883a9e0, 0x00007f8618006ae0, 0x00007f861800ad20, 0x00007f861800b870,
0x00007f86180033a0, 0x00007f8618007670, 0x00007f86180089e0, 0x00007f8618009d00,
0x00007f861800d110, 0x00007f8668000f60
}
 
"Reference Handler" #2 daemon prio=10 os_prio=0 cpu=4.89ms elapsed=104050.61s tid=0x00007f86b819f010 nid=0x153a waiting on condition  [0x00007f86941b5000]
   java.lang.Thread.State: RUNNABLE
        at java.lang.ref.Reference.waitForReferencePendingList(java.base@15/Native Method)
        at java.lang.ref.Reference.processPendingReferences(java.base@15/Reference.java:241)
        at java.lang.ref.Reference$ReferenceHandler.run(java.base@15/Reference.java:213)
…
7,查看系统中类的统计信息
[lhdop@blog ~]$ jcmd 5426 GC.class_histogram | more
5426:
num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:        262144        6291456  org.apache.logging.log4j.core.async.AsyncLoggerConfigDisruptor$Log4jEventWrapper
   2:         76200        5453544  [B (java.base@15)
   3:          5644        4698632  [I (java.base@15)
   4:         71864        1724736  java.lang.String (java.base@15)
   5:         11090        1682264  [Ljava.lang.Object; (java.base@15)
   6:         47725        1527200  java.util.concurrent.ConcurrentHashMap$Node (java.base@15)
   7:         12389        1477760  java.lang.Class (java.base@15)
   8:         15044        1323872  java.lang.reflect.Method (java.base@15)
   9:           534         888728  [C (java.base@15)
  10:         18022         576704  java.util.HashMap$Node (java.base@15)
  11:          5934         528008  [Ljava.util.HashMap$Node; (java.base@15)
  12:         12540         501600  java.util.LinkedHashMap$Entry (java.base@15)
  13:           435         481328  [Ljava.util.concurrent.ConcurrentHashMap$Node; (java.base@15)
  14:         25529         408464  java.lang.Object (java.base@15)
  15:          6450         361200  java.util.LinkedHashMap (java.base@15)
  16:         11596         263784  [Ljava.lang.Class; (java.base@15)
  …
 
8,查看系统Properties内容
[lhdop@blog ~]$ jcmd 5426 VM.system_properties
5426:
#Thu Mar 24 22:05:48 CST 2022
java.specification.version=15
sun.jnu.encoding=UTF-8
java.class.path=/data/store/back/jar/storeback-0.0.1-SNAPSHOT.jar
java.vm.vendor=Oracle Corporation
sun.arch.data.model=64
catalina.useNaming=false
java.vendor.url=https\://java.oracle.com/
user.timezone=Asia/Shanghai
…
9,已出堆信息到指定文件
[lhdop@blog ~]$ jcmd 5426 GC.heap_dump $PWD/heap.dump
5426:
Dumping heap to /home/lhdop/heap.dump ...
Heap dump file created [60121236 bytes in 0.251 secs]
查看生成的文件:
[lhdop@blog ~]$ ll -h heap.dump
-rw------- 1 lhdop lhdop 58M Mar 24 22:07 heap.dump
10,查看性能统计
[lhdop@blog ~]$ jcmd 5426 PerfCounter.print
5426:
java.ci.totalTime=21944894669
java.cls.loadedClasses=10481
java.cls.sharedLoadedClasses=1144
java.cls.sharedUnloadedClasses=0
java.cls.unloadedClasses=94
java.property.java.class.path="/data/store/back/jar/storeback-0.0.1-SNAPSHOT.jar"
java.property.java.home="/usr/local/soft/jdk-15"
java.property.java.library.path="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"
java.property.java.version=“15"
...

三,查看java版本:

[lhdop@blog tools]$ java --version
java 15 2020-09-15
Java(TM) SE Runtime Environment (build 15+36-1562)
Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

 

posted @ 2022-03-26 10:39  刘宏缔的架构森林  阅读(228)  评论(0编辑  收藏  举报