本文主要是介绍为什么From/To space的大小几乎变成 0 了呢?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章来源
https://hllvm-group.iteye.com/group/topic/39440
一、问题描述
Attaching to process ID 26424, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.231-b11using thread-local object allocation.
Parallel GC with 15 thread(s)Heap Configuration:MinHeapFreeRatio = 40MaxHeapFreeRatio = 70MaxHeapSize = 1073741824 (1024.0MB)NewSize = 357564416 (341.0MB)MaxNewSize = 357564416 (341.0MB)OldSize = 716177408 (683.0MB)NewRatio = 2SurvivorRatio = 8MetaspaceSize = 21807104 (20.796875MB)CompressedClassSpaceSize = 1073741824 (1024.0MB)MaxMetaspaceSize = 17592186044415 MBG1HeapRegionSize = 0 (0.0MB)Heap Usage:
PS Young Generation
Eden Space:capacity = 268435456 (256.0MB)used = 268435456 (256.0MB)free = 0 (0.0MB)100.0% used
From Space:capacity = 44564480 (42.5MB)used = 425984 (0.40625MB)free = 44138496 (42.09375MB)0.9558823529411765% used
To Space:capacity = 44564480 (42.5MB)used = 0 (0.0MB)free = 44564480 (42.5MB)0.0% used
PS Old Generationcapacity = 716177408 (683.0MB)used = 577780552 (551.0144729614258MB)free = 138396856 (131.98552703857422MB)80.67561829596278% used41099 interned Strings occupying 4972688 bytes.
启动参数是:
-Xms2048m -Xmx2048m -XX:NewSize=256m -XX:PermSize=256m -server -XX:+DisableExplicitGC -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails
SurvivorRatio是 8 ,这个时候Eden 也 600多M,为啥From/To 几乎是 0 呢?
Jdk version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
二、解决方法
因为ParallelScavenge GC会动态调整各个区的大小。这个行为叫做adaptive size policy。要禁用的话请用 -XX:-UseAdaptiveSizePolicy 。可以通过 -XX:+PrintAdaptiveSizePolicy 来观察它对各个区的大小的调整。
如果survivor space都几乎变成0了,多半意味着tenuring threshold已经降到1了,也就是说所有eden里活的对象在经历第一次minor GC的时候就会被晋升到old generation。那样的话survivor space就完全没用了,所以会被设置到几乎0。(无法真的完全设置到0大小是实现上的细节…有分区之间有对齐需求)
为啥tenuring threshold会下降,最终降到1?有两种可能:
- minor GC耗时比期望的时间长。为了降低minor GC的耗时,降低tenuring threshold来让更多对象晋升,减少留在young generation里的对象
- survivor space有溢出
说到底还是创建对象太多太快了
这篇关于为什么From/To space的大小几乎变成 0 了呢?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!