枯燥的JVM - 常用命令行

jps(Java Virtual Machine Process Status Tool)
查看当前java进程

[root@fy register]# jps -l
25093 app.jar // 进程id 工程文件
25146 sun.tools.jps.Jps

jinfo
查看指定的jvm进程所有的属性设置和配置参数

[root@fy register]# jinfo 25093
Attaching to process ID 25093, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.232-b09
Java System Properties:

java.runtime.name = OpenJDK Runtime Environment
java.vm.version = 25.232-b09
sun.boot.library.path = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/amd64
java.protocol.handler.pkgs = org.springframework.boot.loader
server.tomcat.accesslog.enabled = false
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = OpenJDK 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
nacos.mode = stand alone
user.dir = /apps/register
java.vm.specification.name = Java Virtual Machine Specification
PID = 25093
java.runtime.version = 1.8.0_232-b09
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/endorsed
line.separator = 

java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
nacos.local.ip = 172.16.0.2
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
sun.nio.ch.bugLevel = 
java.class.version = 52.0
java.specification.name = Java Platform API Specification
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-1062.4.3.el7.x86_64
user.home = /root
user.timezone = Asia/Shanghai
catalina.useNaming = false
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
logging.config = classpath:META-INF/logback/nacos.xml
server.tomcat.basedir = logs
catalina.home = /apps/register/logs
user.name = root
java.class.path = app.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = app.jar
java.home = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_232
java.ext.dirs = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
catalina.base = /apps/register/logs
nacos.standalone = true
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
nacos.function.mode = All
sun.cpu.isalist = 

VM Flags:
Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=62914560 -XX:MaxHeapSize=994050048 -XX:MaxNewSize=331350016 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=20971520 -XX:OldSize=41943040 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
Command line:

jmap
查看某个pid进程对应的应用程序内存占用情况

[root@fy register]# jmap -heap 25093
Attaching to process ID 25093, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.232-b09

using thread-local object allocation.
Parallel GC with 2 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 0 #最小堆使用比例
   MaxHeapFreeRatio         = 100 #最大堆可用比例
   MaxHeapSize              = 994050048 (948.0MB) #最大堆空间大小

   NewSize                  = 20971520 (20.0MB) #新生代分配大小
   MaxNewSize               = 331350016 (316.0MB) #最大新生代分配大小
   OldSize                  = 41943040 (40.0MB) #老年代大小
   NewRatio                 = 2 #新生代比例
   SurvivorRatio            = 8 #新生代与suvivor的比例
   MetaspaceSize            = 21807104 (20.796875MB) #元空间大小
   CompressedClassSpaceSize = 1073741824 (1024.0MB) #压缩类空间大小
   MaxMetaspaceSize         = 17592186044415 MB #最大元空间大小
   G1HeapRegionSize         = 0 (0.0MB) #G1堆分区大小

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 316669952 (302.0MB) #伊甸区容量
   used     = 83726680 (79.84798431396484MB)
   free     = 232943272 (222.15201568603516MB)
   26.439729905286374% used 使用比例
From Space:
   capacity = 7340032 (7.0MB)
   used     = 0 (0.0MB)
   free     = 7340032 (7.0MB)
   0.0% used
To Space:
   capacity = 7340032 (7.0MB)
   used     = 0 (0.0MB)
   free     = 7340032 (7.0MB)
   0.0% used
PS Old Generation
   capacity = 81788928 (78.0MB)
   used     = 28656864 (27.329315185546875MB)
   free     = 53132064 (50.670684814453125MB)
   35.03758357121394% used

24590 interned Strings occupying 2612744 bytes.

使用 dump命令分析 java 内存占用情况
jmap -dump: format = b, file = tmp.dump [pid]

jstack
查看进程所包含所有线程的Java堆栈信息

[root@fy register]# jstack 25093
2020-07-30 14:04:37
Full thread dump OpenJDK 64-Bit Server VM (25.232-b09 mixed mode):

"Attach Listener" #101 daemon prio=9 os_prio=0 tid=0x00007ff24c004800 nid=0x69c7 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"MySQL Statement Cancellation Timer" #100 daemon prio=5 os_prio=0 tid=0x00007ff224005800 nid=0x6296 in Object.wait() [0x00007ff21cab9000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.util.TimerThread.mainLoop(Timer.java:552)
    - locked <0x00000000ee4695c8> (a java.util.TaskQueue)
    at java.util.TimerThread.run(Timer.java:505)
...

"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007ff274166800 nid=0x620b in Object.wait() [0x00007ff25cd84000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000000c4cdb548> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
    - locked <0x00000000c4cdb548> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007ff274162000 nid=0x620a in Object.wait() [0x00007ff25ce85000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000000c4cdb588> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:502)
    at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
    - locked <0x00000000c4cdb588> (a java.lang.ref.Reference$Lock)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"VM Thread" os_prio=0 tid=0x00007ff274158000 nid=0x6209 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007ff27405e000 nid=0x6207 runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007ff274060000 nid=0x6208 runnable 

"VM Periodic Task Thread" os_prio=0 tid=0x00007ff2741a7000 nid=0x6210 waiting on condition 

JNI global references: 1659

[root@fy register]# jstack 25093 |grep 'java.lang.Thread.State' | wc -l
82 #统计线程数

jstat(Java Virtual Machine statistics monitoring tool)
可以实时监测系统资源占用与jvm运行情况

类加载统计

[root@fy register]# jstat -class 25093
Loaded  Bytes  Unloaded  Bytes     Time   
 11088 20216.7        0     0.0       5.90

解析:
Loaded: 加载class的数量
Bytes:所占用空间大小
Unloaded:未加载数量
Bytes:未加载占用空间
Time:时间

编译统计

[root@fy register]# jstat -compiler 25093
Compiled Failed Invalid   Time   FailedType FailedMethod
    8803      0       0    14.35          0   

解析:
Compiled:编译数量。
Failed:失败数量
Invalid:不可用数量
Time:时间
FailedType:失败类型
FailedMethod:失败的方法

垃圾回收统计

[root@fy register]# jstat -gc 25093
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
7168.0 7168.0  0.0    0.0   309248.0 135743.8  79872.0    27985.2   59160.0 56296.1 7344.0 6849.0     17    0.131   3      0.263    0.394

解析:
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间

你可能感兴趣的:(枯燥的JVM - 常用命令行)