jps -l -- 输出主类的全名,如果进程执行的是jar包,输出jar包路径
jps -v -- 显示虚拟机进程启动时的参数
-Xms100m --jvm启动分配内存100MB
-Xmx900m --jvm最大可用内存
-Xss256k --设置每个线程的分配内存
-XX:+UseConcMarkSweepGC --设置老年代并发收集
-XX:CMSFullGCsBeforeCompaction=5 --5次并发收集后对内存进行压缩整理
-XX:+UseCMSCompactAtFullCollection --打开对老年代的压缩,消除碎片
-XX:+PrintGC --打印GC信息
-XX:+PrintGCDetails --打印GC信息
-XX:+PrintGCTimeStamps --打印GC信息
-Xloggc:/tmp/jvm.log --虚拟机日志文件路径
-XX:+HeapDumpOnOutOfMemoryError --当JVM发生OOM时生成DUMP文件
-Dcom.sun.management.jmxremote --启用远程JMX访问
-Dcom.sun.management.jmxremote.port=4445 --远程JMX访问端口
-Dcom.sun.management.jmxremote.ssl=false --关闭远程JMX连接SSL加密
-Dcom.sun.management.jmxremote.authenticate=false --关闭远程JMX用户认证
-XX:HeapDumpPath=/tmp/heapdump.hprof --OOM时生成DUMP文件路径
jstat [option] [vmid] [ interval time(ms) [count] ]
jstat -gcutil [vmid] -- 监视虚拟机各内存区域使用比例和分代GC的信息
S0 新生代第一个Survivor区内存使用百分比
S1 新生代第二个Survivor区内存使用百分比
E 新生代Eden区内存使用百分比
O 老年代内存使用百分比
M 方法区内存使用百分比
CCS 压缩类空间内存使用百分比
YGC 新生代GC次数
YGCT 新生代GC时间
FGC 老年代GC次数
FGCT 老年代GC时间
GCT GC花费总时间
jstat -gc [vmid] -- 监视虚拟机内存区域大小及使用情况
S0C 第一个Survivor区内存空间大小(单位:字节)
S1C 第二个Survivor区内存空间大小(单位:字节)
S0U 第一个Survivor区内存被使用大小(单位:字节)
S1U 第二个Survivoe区内存被使用大小(单位:字节)
EC Eden区内存空间大小(单位:字节)
EU Eden区内存被使用大小(单位:字节)
OC 老年代内存空间大小(单位:字节)
OU 老年代内存被使用大小(单位:字节)
MC 方法区空间大小(单位:字节)
MU 方法区内存被使用大小(单位:字节)
CCSC 压缩类内存空间大小(单位:字节)
CCSU 压缩类内存被使用大小(单位:字节)
YGC 新生代GC次数
YGCT 新生代GC耗时(单位:秒)
FGC 老年代GC次数
FGCT 老年代GC耗时(单位:秒)
GCT GC总耗时
依据图数据分析:
新生代GC平均耗时 = YGCT / YGC = 0.040s
老年代GC平均耗时 = FGCT / FGC = 0.135s
jstat -gccapacity [vmid] -- 监视虚拟机内存区域大小及使用情况
部分参数参考上面
NGCMN 新生代内存空间大小最小值(单位:字节)
NGCMX 新生代内存空间最大值(单位:字节)
NGC 当前新生代内存空间大小值(单位:字节)
OGCMN 老年代内存空间大小最小值(单位:字节)
OGCMX 老年代内存空间最大值(单位:字节)
OGC 当前老年代内存空间大小值(单位:字节)
MCMN 方法区内存空间大小最小值(单位:字节)
MCMX 方法区内存空间最大值(单位:字节)
MC 当前方法区内存空间大小值(单位:字节)
CCSMN 压缩类内存空间最小值(单位:字节)
CCSMX 压缩类内存空间最大值(单位:字节)
CCSC 当前压缩类内存空间大小值(单位:字节)
YGC 新生代GC次数
FGC 老年代GC次数
依图数据分析
NGCMN:OGCMN = 43520:87552 = 1:2
NGCMX:OGCMX = 349184:699392 = 1:2
NGCMX + OGCMX = 349184 + 699392 = 1048576 = CCSMX
jstat -gccause [vmid] -- 显示上一次gc原因
部分参数参考上面
LGCC 上次GC的原因
GCC 当前GC的原因
jstat -gcnew [vmid] -- 监视新生代内存使用及其GC情况
部分参数解释参考上面
TT 新生代对象存活阈值
MTT 新生代对象最大存活阈值
DSS 当Eden区满时,期望在S0里面使用的内存大小
TT这个值是动态的,hotspot会遍历所有age的table,并对每个age的个数进行统计,当某个age的所有对象占的内存空间大小超过了survivor space的一半时,取这个age大小,最后取这个age和MTT(MaxTenuringThreshold)中更小的一个值作为新的存活周期阈值(TT)。
jstate -gcnewcapacity [vmid] --监视新生代内存统计及其GC情况
NGCMN 新生代内存空间大小最小值(单位:字节)
NGCMX 新生代内存空间最大值(单位:字节)
NGC 当前新生代内存空间大小值(单位:字节)
S0CMX 第一个Survivor区内存空间最大值(单位:字节)
S0C 第一个Survivor区当前内存使用大小(单位:字节)
S1CMX 第二个Survivor区内存空间最大值(单位:字节)
S1C 第二个Survivor区当前内存使用大小(单位:字节)
ECMX Eden区内存空间最大值(单位:字节)
EC Eden区当前内存使用大小(单位:字节)
YGC 新生代GC次数
FGC 老年代GC次数
依据图数据分析
S0CMX:S1CMX:ECMX = 116224:116224:348160 = 1:1:3
jstate -gcold [vmid] --监视老年代内存使用及其GC情况
参数解释参考上面
jstate -gcoldcapacity [vmid] --监视老年代内存统计及其GC情况
参数解释参考上面
jstate -gcmetacapacity [vmid] --监视方法区内存统计及其GC情况
参数解释参考上面
jstat -class [vmid] -- 监视类装载、卸载数量及其耗费的时间
Loaded 加载class的数量
Bytes 加载的class占用空间大小
Unloaded 卸载class的数量
Bytes 卸载的class占用空间大小
Time 加载、卸载花费时间
jstat -compiler [vmid] -- 输出JIT编译器编译过的方法、耗时等信息
Compiled 编译的数量
Failed 编译失败数量
Invalid 编译的不可用数量
Time 编译的花费时间
FailedType 编译失败类型
FailedMethod 编译失败的方法
jstat -printcompilation [vmid] -- 输出已经被JIT编译的方法
Compiled 当前编译的数量
Size 当前编译的字节码数量
Type 最近编译方法的编译类型。
Method 最近编译方法名
jinfo [vmid] -- 查看虚拟机各项参数
[root@kj-oms-7499ff488f-dvj6m log]# jinfo 33
Attaching to process ID 33, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14
Java System Properties:
com.sun.management.jmxremote.authenticate = false
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.92-b14
sun.boot.library.path = /usr/local/java/jdk1.8.0_92/jre/lib/amd64
java.protocol.handler.pkgs = null|org.springframework.boot.loader
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
java.rmi.server.randomIDs = true
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
user.dir = /
java.vm.specification.name = Java Virtual Machine Specification
com.sun.management.jmxremote.port = 4445
PID = 33
java.runtime.version = 1.8.0_92-b14
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/java/jdk1.8.0_92/jre/lib/endorsed
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-862.el7.x86_64
user.home = /root
user.timezone = GMT+08:00
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = root
java.class.path = /data/appdeploy/kj-oms-2019022800000174-1.2.jar
com.sun.management.jmxremote =
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = /data/appdeploy/kj-oms-2019022800000174-1.2.jar
java.home = /usr/local/java/jdk1.8.0_92/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
com.sun.management.jmxremote.ssl = false
java.vm.info = mixed mode
java.version = 1.8.0_92
java.ext.dirs = /usr/local/java/jdk1.8.0_92/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/local/java/jdk1.8.0_92/jre/lib/resources.jar:/usr/local/java/jdk1.8.0_92/jre/lib/rt.jar:/usr/local/java/jdk1.8.0_92/jre/lib/sunrsasign.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jsse.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jce.jar:/usr/local/java/jdk1.8.0_92/jre/lib/charsets.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jfr.jar:/usr/local/java/jdk1.8.0_92/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.font.fontmanager = sun.awt.X11FontManager
sun.cpu.endian = little
sun.cpu.isalist =
VM Flags:
Non-default VM flags: -XX:CICompilerCount=4 -XX:CMSFullGCsBeforeCompaction=5
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null
-XX:InitialHeapSize=104857600 -XX:+ManagementServer -XX:MaxHeapSize=943718400
-XX:MaxNewSize=314572800 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608
-XX:NewSize=34930688 -XX:OldPLABSize=16 -XX:OldSize=69926912 -XX:+PrintGC
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:ThreadStackSize=256 -XX:+UseCMSCompactAtFullCollection -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastUnorderedTimeStamps -XX:+UseParNewGC
Command line: -Xms100m -Xmx900m -Xss256k -XX:+UseConcMarkSweepGC
-XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection -XX:+PrintGC
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/tmp/jvm.log
-XX:+HeapDumpOnOutOfMemoryError
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=4445
-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
-XX:HeapDumpPath=/tmp/heapdump.hprof
jinfo -sysprops [vmid] -- System.getProperties()
[root@kj-oms-7499ff488f-dvj6m log]# jinfo -sysprops 33
Attaching to process ID 33, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14
com.sun.management.jmxremote.authenticate = false
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.92-b14
sun.boot.library.path = /usr/local/java/jdk1.8.0_92/jre/lib/amd64
java.protocol.handler.pkgs = null|org.springframework.boot.loader
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
java.rmi.server.randomIDs = true
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
user.dir = /
java.vm.specification.name = Java Virtual Machine Specification
com.sun.management.jmxremote.port = 4445
PID = 33
java.runtime.version = 1.8.0_92-b14
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/java/jdk1.8.0_92/jre/lib/endorsed
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-862.el7.x86_64
user.home = /root
user.timezone = GMT+08:00
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = root
java.class.path = /data/appdeploy/kj-oms-2019022800000174-1.2.jar
com.sun.management.jmxremote =
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = /data/appdeploy/kj-oms-2019022800000174-1.2.jar
java.home = /usr/local/java/jdk1.8.0_92/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
com.sun.management.jmxremote.ssl = false
java.vm.info = mixed mode
java.version = 1.8.0_92
java.ext.dirs = /usr/local/java/jdk1.8.0_92/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/local/java/jdk1.8.0_92/jre/lib/resources.jar:/usr/local/java/jdk1.8.0_92/jre/lib/rt.jar:/usr/local/java/jdk1.8.0_92/jre/lib/sunrsasign.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jsse.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jce.jar:/usr/local/java/jdk1.8.0_92/jre/lib/charsets.jar:/usr/local/java/jdk1.8.0_92/jre/lib/jfr.jar:/usr/local/java/jdk1.8.0_92/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.font.fontmanager = sun.awt.X11FontManager
sun.cpu.endian = little
sun.cpu.isalist =
jmap -heap [vmid] -- 显示堆详细信息
[root@kj-oms-7499ff488f-dvj6m log]# jmap -heap 33
Attaching to process ID 33, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Heap Configuration:
MinHeapFreeRatio = 40 --JVM堆最小空闲比率
MaxHeapFreeRatio = 70 --JVM堆最大空闲比率
MaxHeapSize = 943718400 (900.0MB) --JVM堆的最大大小
NewSize = 34930688 (33.3125MB) --JVM堆新生代的初始大小
MaxNewSize = 314572800 (300.0MB) --JVM堆新生代的最大大小
OldSize = 69926912 (66.6875MB) --JVM堆老年代的初始大小
NewRatio = 2 --JVM堆新生代与老年代比率
SurvivorRatio = 8 --JVM堆新生代Eden区与Survivor区比值
MetaspaceSize = 21807104 (20.796875MB) --JVM元空间大小
CompressedClassSpaceSize = 1073741824 (1024.0MB) --JVM压缩类空间大小
MaxMetaspaceSize = 17592186044415 MB --JVM元空间最大大小
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 69271552 (66.0625MB)
used = 36902808 (35.193260192871094MB)
free = 32368744 (30.869239807128906MB)
53.272673896493615% used
Eden Space:
capacity = 61603840 (58.75MB)
used = 36668488 (34.96979522705078MB)
free = 24935352 (23.78020477294922MB)
59.523055705618354% used
From Space:
capacity = 7667712 (7.3125MB)
used = 234320 (0.2234649658203125MB)
free = 7433392 (7.0890350341796875MB)
3.055931156517094% used
To Space:
capacity = 7667712 (7.3125MB)
used = 0 (0.0MB)
free = 7667712 (7.3125MB)
0.0% used
concurrent mark-sweep generation:
capacity = 153612288 (146.49609375MB)
used = 89159080 (85.02872467041016MB)
free = 64453208 (61.467369079589844MB)
58.041632711049786% used
41452 interned Strings occupying 4486584 bytes.
jmap -dump:format=b,file=1 [vmid] -- 生成java堆转储快照
[root@kj-oms-7499ff488f-dvj6m tmp]# jmap -dump:format=b,file=1 33
Dumping heap to /tmp/1 ...
Heap dump file created
生成堆dump文件,并命名1,上面指令日志有dump文件生成路径
jmap -finalizerinfo [vmid] -- 显示在F-Queue中等待Finalizer线程执行fianlize方法的对象
[root@kj-oms-7499ff488f-dvj6m log]# jmap -finalizerinfo 33
Attaching to process ID 33, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14
Number of objects pending for finalization: 0
jmap -histo [vmid] -- 显示堆中对象的统计信息(类、实例信息、合计容量)
[root@kj-oms-7499ff488f-dvj6m log]# jmap -histo 33
num #instances #bytes class name
----------------------------------------------
1: 10993 48077200 [I
2: 207578 26727952 [C
3: 17248 8897528 [B
4: 196573 4717752 java.lang.String
5: 143355 4587360 java.util.HashMap$Node
6: 41118 3618384 java.lang.reflect.Method
7: 25659 2918776 [Ljava.util.HashMap$Node;
8: 75700 2422400 java.util.concurrent.ConcurrentHashMap$Node
9: 18829 2101368 java.lang.Class
10: 34737 2097528 [Ljava.lang.Object;
11: 46743 1869720 java.util.LinkedHashMap$Entry
12: 28728 1838592 com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty
13: 46986 1503552 java.util.Hashtable$Entry
14: 26140 1463840 java.util.LinkedHashMap
15: 32885 1052320 java.lang.ref.WeakReference
16: 3309 897480 [Ljava.util.concurrent.ConcurrentHashMap$Node;
17: 19782 791280 java.lang.ref.SoftReference
18: 15030 721440 java.util.HashMap
19: 28040 672960 java.util.ArrayList
20: 9804 627456 com.mysql.jdbc.ConnectionPropertiesImpl$StringConnectionProperty
21: 28768 619616 [Ljava.lang.Class;
22: 35490 567840 java.lang.Object
23: 33368 533888 java.lang.Integer
24: 21027 504648 java.beans.MethodRef
25: 19293 498704 [Ljava.lang.String;
26: 1658 484400 [Ljava.util.Hashtable$Entry;
27: 6612 423168 com.mysql.jdbc.ConnectionPropertiesImpl$IntegerConnectionProperty
28: 7415 415240 java.beans.MethodDescriptor
29: 5734 412848 java.lang.reflect.Field
30: 16499 395976 org.springframework.core.MethodClassKey
31: 4578 366240 java.lang.reflect.Constructor
32: 3760 360960 org.springframework.beans.GenericTypeAwarePropertyDescriptor
33: 881 331256 java.lang.Thread
34: 4290 308880 com.alibaba.dubbo.common.URL
35: 9284 297088 java.util.LinkedList
36: 228 279072 com.mysql.jdbc.JDBC4Connection
37: 4208 269312 java.util.concurrent.ConcurrentHashMap
38: 4437 248472 org.codehaus.groovy.runtime.metaclass.MetaMethodIndex$Entry
39: 3188 229536 org.springframework.core.annotation.AnnotationAttributes
40: 3042 219024 java.beans.PropertyDescriptor
41: 2889 184896 org.springframework.core.MethodParameter
42: 10742 171872 java.util.LinkedHashSet
43: 5308 169856 java.util.Collections$UnmodifiableMap
44: 6362 152688 java.util.LinkedList$Node
45: 4659 149088 java.util.concurrent.locks.ReentrantLock$NonfairSync
46: 8878 142048 java.util.LinkedHashMap$LinkedKeySet
47: 1748 140608 [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;
48: 837 127224 org.springframework.beans.factory.support.RootBeanDefinition
49: 2489 119472 org.springframework.beans.PropertyValue
50: 2921 116840 com.fasterxml.jackson.databind.introspect.AnnotatedMethod
以上只复制了一小部分
jhat filename -- 分析dump文件
[root@kj-oms-7499ff488f-dvj6m tmp]# jhat 1
Reading from 1...
Dump file created Sat Apr 13 00:09:19 GMT+08:00 2019
Snapshot read, resolving...
Resolving 1569882 objects...
Chasing references, expect 313 dots.........................................................................................................................................................................................................................................................................................................................
Eliminating duplicate references.........................................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
查看地址 执行jhat机器ip:7000
jstack -l [vmid] -- 除了堆栈外,显示关于锁的附加信息
jstack -m [vmid] -- 显示调用本地方法的堆栈信息
jstack -F [vmid] -- 强制输出线程堆栈