文章目录
- Jinfo
- 查看JVM参数
- 查看JAVA系统参数
- Jmap
- 查看JAVA堆信息
- 查看JAVA对象堆信息
- 转储JAVA对象堆信息
- Jstack
- 查看死锁信息
- Jstat
- 垃圾回收统计
- 堆内存统计
- 新生代垃圾回收统计
- 新生代内存统计
- 老年代垃圾回收统计
- 老年代内存统计
- 元空间数据统计
Jinfo
查看正在运行的Java应用程序的扩展参数。
>jinfo --help
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
-flag <name> to print the value of the named VM flag
-flag [+|-]<name> to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
<no option> to print both of the above
-h | -help to print this help message
主要掌握两个命令,一个是查看JVM参数的命令,一个是查看JAVA系统参数的命令。
查看JVM参数
查看JVM参数的命令>jinfo -flags 进程ID
Attaching to process ID 4746, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.211-b12
Non-default VM flags: -XX:CICompilerCount=3 -XX:CompressedClassSpaceSize=260046848 -XX:ConcGCThreads=1 -XX:+DisableExplicitGC -XX:ErrorFile=null -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=536870912 -XX:InitialTenuringThreshold=7 -XX:InitiatingHeapOccupancyPercent=45 -XX:MarkStackSize=4194304 -XX:MaxGCPauseMillis=200 -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=268435456 -XX:MaxNewSize=2576351232 -XX:MinHeapDeltaBytes=1048576 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:ReservedCodeCacheSize=134217728 -XX:+TieredCompilation -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:+UseStringDeduplication
查看JAVA系统参数
查看JAVA系统参数的命令>jinfo -sysprops 进程ID
Attaching to process ID 4746, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.211-b12
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.211-b12
java.io.tmpdir = /tmp
Jmap
可以用来查看内存信息。
>jmap -help
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system
查看JAVA堆信息
打印Java堆摘要>jmap -heap 进程ID
Attaching to process ID 4746, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.211-b12
using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 4294967296 (4096.0MB)
NewSize = 1363144 (1.2999954223632812MB)
MaxNewSize = 2576351232 (2457.0MB)
OldSize = 5452592 (5.1999969482421875MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 260046848 (248.0MB)
MaxMetaspaceSize = 268435456 (256.0MB)
G1HeapRegionSize = 1048576 (1.0MB)
Heap Usage:
G1 Heap:
regions = 4096
capacity = 4294967296 (4096.0MB)
used = 377291272 (359.81299591064453MB)
free = 3917676024 (3736.1870040893555MB)
8.78449697047472% used
G1 Young Generation:
Eden Space:
regions = 269
capacity = 331350016 (316.0MB)
used = 282066944 (269.0MB)
free = 49283072 (47.0MB)
85.12658227848101% used
Survivor Space:
regions = 7
capacity = 7340032 (7.0MB)
used = 7340032 (7.0MB)
free = 0 (0.0MB)
100.0% used
G1 Old Generation:
regions = 85
capacity = 198180864 (189.0MB)
used = 87884296 (83.81299591064453MB)
free = 110296568 (105.18700408935547MB)
44.345500481822505% used
查看JAVA对象堆信息
以一般格式文件转储Java对象堆[存活对象]的信息>jmap -histo[:live] 进程ID > map.txt
转储JAVA对象堆信息
以hprof二进制格式转储Java堆信息>jmap -dump:format=b,file=charging.hprof 进程ID
Jstack
可以用来查看线程信息,典型的可以查找死锁。
>jstack -help
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
查看死锁信息
>jstack 进程ID
Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x00007fec2a03f418 (object 0x0000000797608600, a java.lang.Object),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x00007fec2a041ca8 (object 0x0000000797608610, a java.lang.Object),
which is held by "Thread-1"
Java stack information for the threads listed above:
===================================================
"Thread-1":
at com.ambition.study.DeadLockTest.lambda$main$1(DeadLockTest.java:38)
- waiting to lock <0x0000000797608600> (a java.lang.Object)
- locked <0x0000000797608610> (a java.lang.Object)
at com.ambition.study.DeadLockTest$$Lambda$2/1922154895.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)
"Thread-0":
at com.ambition.study.DeadLockTest.lambda$main$0(DeadLockTest.java:23)
- waiting to lock <0x0000000797608610> (a java.lang.Object)
- locked <0x0000000797608600> (a java.lang.Object)
at com.ambition.study.DeadLockTest$$Lambda$1/793589513.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)
Found 1 deadlock.
Jstat
可以查看堆内存各部分的使用量,以及加载类的数量。
>jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
jstat [-命令选项] [vmid] [间隔时间(毫秒)] [查询次数]
垃圾回收统计
垃圾回收统计>jstat -gc 进程ID
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
0.0 6144.0 0.0 6144.0 324608.0 45056.0 193536.0 76996.9 134328.0 128112.0 16568.0 15547.2 1043 15.308 2 0.850 16.158
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小(元空间)
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间,单位s
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间,单位s
GCT:垃圾回收消耗总时间,单位s
堆内存统计
堆内存统计>jstat -gccapacity 进程ID
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
0.0 4194304.0 330752.0 0.0 6144.0 324608.0 0.0 4194304.0 193536.0 193536.0 0.0 1167360.0 134328.0 0.0 1048576.0 16568.0 1045 2
NGCMN:新生代最小容量
NGCMX:新生代最大容量
NGC:当前新生代容量
S0C:第一个幸存区大小
S1C:第二个幸存区的大小
EC:伊甸园区的大小
OGCMN:老年代最小容量
OGCMX:老年代最大容量
OGC:当前老年代大小
OC:当前老年代大小
MCMN:最小元数据容量
MCMX:最大元数据容量
MC:当前元数据空间大小
CCSMN:最小压缩类空间大小
CCSMX:最大压缩类空间大小
CCSC:当前压缩类空间大小
YGC:年轻代gc次数
FGC:老年代GC次数
新生代垃圾回收统计
新生代垃圾回收统计>jstat -gcnew 进程ID
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
0.0 7168.0 0.0 7168.0 15 15 19968.0 323584.0 217088.0 1050 15.405
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
TT:对象在新生代存活的次数
MTT:对象在新生代存活的最大次数
DSS:期望的幸存区大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
新生代内存统计
新生代内存统计>jstat -gcnewcapacity 进程ID
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
0.0 4194304.0 330752.0 0.0 0.0 4194304.0 8192.0 4194304.0 322560.0 1052 2
NGCMN:新生代最小容量
NGCMX:新生代最大容量
NGC:当前新生代容量
S0CMX:最大幸存1区大小
S0C:当前幸存1区大小
S1CMX:最大幸存2区大小
S1C:当前幸存2区大小
ECMX:最大伊甸园区大小
EC:当前伊甸园区大小
YGC:年轻代垃圾回收次数
FGC:老年代回收次数
老年代垃圾回收统计
老年代垃圾回收统计>jstat -gcold 进程ID
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
134328.0 128112.0 16568.0 15547.2 193536.0 77731.4 1053 2 0.850 16.297
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
OC:老年代大小
OU:老年代使用大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
老年代内存统计
老年代内存统计>jstat -gcoldcapacity 进程ID
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
0.0 4194304.0 193536.0 193536.0 1053 2 0.850 16.297
OGCMN:老年代最小容量
OGCMX:老年代最大容量
OGC:当前老年代大小
OC:老年代大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
元空间数据统计
元空间数据统计>jstat -gcmetacapacity 进程ID
MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT
0.0 1167360.0 134328.0 0.0 1048576.0 16568.0 1054 2 0.850 16.308
MCMN:最小元数据容量
MCMX:最大元数据容量
MC:当前元数据空间大小
CCSMN:最小压缩类空间大小
CCSMX:最大压缩类空间大小
CCSC:当前压缩类空间大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间