Java虚拟机
运行时数据区
JVM栈
堆
垃圾判定
- 经过可达性分析判定为不可达
GC算法
- 标记-清除
- 复制
- 标记-整理
垃圾收集器
JVM参数
-X:
非标准选项-XX:
非标准高级选项,不建议随意使用。这些是开发人员用于调优 Java HotSpot 虚拟机操作的特定区域的选项-XX:+<option>
启用选项-XX:-<option>
不启用选项-XX:+<option>=<number>
给选项设置一个数字类型值,可跟单位-XX:+<option>=<string>
给选项设置一个字符串值行为选项
Option and Default Value | Description |
---|---|
-Xms | 设置JVM初始化堆内存大小 |
-Xmx | 设置JVM最大的堆内存大小 |
-Xss | 设置JVM栈内存大小 |
-Xmn | 设置young generation的堆内存大小,一般设置为Xmx的1/3 |
命令和工具
jps -l
[root@a2741578e829 export]# jps
64 -- process information unavailable
170 Jps
78 task-afs.jar
jstat -gc 87865 250 20
每250毫秒查询一次进程 一共查询20次
[root@a2741578e829 export]# jstat -gc 78 250 20
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123161.1 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123491.6 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 123850.2 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
11776.0 12288.0 8168.3 0.0 145920.0 124029.6 65536.0 34663.9 67760.0 65645.5 8368.0 7976.3 24 0.217 3 0.325 0.541
jinfo
查看jvm 参数选项信息
➜ ~ jinfo -flags 47077
VM Flags:
-XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=10485760 -XX:NewSize=10485760 -XX:+PrintGC -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseCompressedOops -XX:+UseParallelGC
jmap -heap
[root@a2741578e829 export]# jmap -heap 110
Attaching to process ID 142, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.20-b23
using thread-local object allocation.
Parallel GC with 23 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 3221225472 (3072.0MB)
NewSize = 1073741824 (1024.0MB)
MaxNewSize = 1073741824 (1024.0MB)
OldSize = 2147483648 (2048.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 268435456 (256.0MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 1066401792 (1017.0MB)
used = 131154680 (125.07884979248047MB)
free = 935247112 (891.9211502075195MB)
12.298805289329446% used
From Space:
capacity = 3670016 (3.5MB)
used = 802832 (0.7656402587890625MB)
free = 2867184 (2.7343597412109375MB)
21.875435965401785% used
To Space:
capacity = 3145728 (3.0MB)
used = 0 (0.0MB)
free = 3145728 (3.0MB)
0.0% used
PS Old Generation
capacity = 2147483648 (2048.0MB)
used = 43741080 (41.714744567871094MB)
free = 2103742568 (2006.285255432129MB)
2.0368527621030807% used
27233 interned Strings occupying 3197480 bytes.
jmap -dump
内存映像
[root@a2741578e829 export]# jmap -dump:format=b,file=test.bin 78
Dumping heap to /export/test.bin ...
Heap dump file created
jmap -histo 110
num #instances #bytes class name
----------------------------------------------
1: 86420 80081360 [I
2: 582484 29354720 [C
3: 273669 15325464 java.util.concurrent.ConcurrentHashMap$KeyIterator
4: 186997 14524120 [Ljava.lang.Object;
5: 38437 10039288 [B
6: 413115 9914760 java.lang.String
7: 139971 8958144 java.net.URL
8: 70058 5605744 [S
9: 69796 5583680 org.springframework.boot.loader.jar.JarURLConnection
10: 36127 2312128 java.nio.DirectByteBuffer
11: 69795 2233440 java.io.IOException
12: 69704 2230528 java.util.HashMap$Node
13: 28122 1799808 java.util.concurrent.ConcurrentHashMap
14: 17581 1547128 java.lang.reflect.Method
15: 41988 1343616 java.util.concurrent.ConcurrentHashMap$Node