Java8启动eden:s0:s1内存不是8:1:1
在java8下执行jmap命令发现SurvivorRatio=8,但是实际eden区域的内存和s0,s1不是8:1:1的比例,
eden:512.5MB,from85MB。
如下图所示:
[root@nicad-1 test]# nohup java -jar -Xms2g -Xmx2g demo-0.0.1-SNAPSHOT.jar &
[1] 12426
[root@nicad-1 test]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@nicad-1 test]# jmap -heap 12426
Attaching to process ID 12426, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.342-b07
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 715653120 (682.5MB)
MaxNewSize = 715653120 (682.5MB)
OldSize = 1431830528 (1365.5MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 537395200 (512.5MB)
used = 198918408 (189.70337677001953MB)
free = 338476792 (322.79662322998047MB)
37.0152930282965% used
From Space:
capacity = 89128960 (85.0MB)
used = 0 (0.0MB)
free = 89128960 (85.0MB)
0.0% used
To Space:
capacity = 89128960 (85.0MB)
used = 0 (0.0MB)
free = 89128960 (85.0MB)
0.0% used
PS Old Generation
capacity = 1431830528 (1365.5MB)
used = 5872112 (5.6000823974609375MB)
free = 1425958416 (1359.899917602539MB)
0.4101122224431298% used
12878 interned Strings occupying 1116008 bytes.
原因分析:
jdk8默认使用的垃圾回收器是ParallelGC,这个GC会自动打开自适应参数UseAdaptiveSizePolicy 。因此我们需要手动关闭这个参数-XX:-UseAdaptiveSizePolicy。而且这个参数和-XX:SurvivorRatio=8参数存在不兼容的情况,需要我们两个参数都设置
解决方案:
在不切换垃圾收集器的前提下我们可以修改启动参数,改成如下命令启动
nohup java -jar -Xms2g -Xmx2g -XX:SurvivorRatio=8 -XX:-UseAdaptiveSizePolicy demo-0.0.1-SNAPSHOT.jar &
[root@nicad-1 test]# nohup java -jar -Xms2g -Xmx2g -XX:SurvivorRatio=8 -XX:-UseAdaptiveSizePolicy demo-0.0.1-SNAPSHOT.jar &
[1] 12556
[root@nicad-1 test]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@nicad-1 test]# jmap -heap 12556
Attaching to process ID 12556, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.342-b07
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 715653120 (682.5MB)
MaxNewSize = 715653120 (682.5MB)
OldSize = 1431830528 (1365.5MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 573046784 (546.5MB)
used = 200569904 (191.2783660888672MB)
free = 372476880 (355.2216339111328MB)
35.0006159357488% used
From Space:
capacity = 71303168 (68.0MB)
used = 0 (0.0MB)
free = 71303168 (68.0MB)
0.0% used
To Space:
capacity = 71303168 (68.0MB)
used = 0 (0.0MB)
free = 71303168 (68.0MB)
0.0% used
PS Old Generation
capacity = 1431830528 (1365.5MB)
used = 5870568 (5.598609924316406MB)
free = 1425959960 (1359.9013900756836MB)
0.4100043884523183% used
执行完看到eden:from:to=8:1:1