当前位置:网站首页>When will JVM garbage collection enter the older generation

When will JVM garbage collection enter the older generation

2022-06-26 10:08:00 ZZ learn java well


 

The new generation Minor GC There are too many surviving objects after , Could not add Survivor In the area , At this time, these must be saved to
The elephant moves directly to the old age , What if there is not enough space for the elderly at this time ?
1、 Execute any time Minor GC Before ,JVM I'll check the available memory space in the old days first , Is it larger than the new generation
Total size of all objects , Because in extreme cases , Maybe the new generation Minor GC after , The new generation needs all objects
Survive , That will cause all objects of the new generation to enter the old generation ;
2、 If the available memory of the old generation is greater than the total size of all objects of the new generation , At this time, we can safely and boldly launch the new generation
once Minor GC, because Minor GC Then even if all objects survive ,Survivor There's no room for it , You can also turn
Move to the old age ;
3、 If you execute MInor GC Before , It is found that the available space in the old age is less than the total size of all objects in the new generation ,
Then the next judgment will be made , Judge the available space in the old age , Is it greater than every time before Minor GC Backward
The average size of objects entering the old age , If you find the memory size of the old age , Greater than every time before Minor GC
The average size of objects in the late to old age , So you can take a risk and try Minor GC, But this time really can
There can be risks , That's it Minor GC later , The size of the remaining surviving objects , Greater than Survivor The size of the space , also
Larger than the amount of space available for older generations , The old generation can't let go of these surviving objects , This will trigger once “Full GC";
So the purpose of the old space allocation guarantee mechanism ? Also to avoid frequent Full GC;
4、 If Full GC after , There is still not enough space for storage in the old age Minor GC The remaining surviving objects , that
Then it will lead to “OOM” out of memory ;

Under what circumstances will the object enter the old generation
 1、 Evade 15 Time GC Then into the old generation ,I It can be done by JVM Parameters "-XX:MaxTenuring Threshold" To set the age , The default is 15 year ;
2、 Dynamic object age determination ;
3、 The old space guarantee mechanism ;
4、 Large objects go directly into the old generation ;

Large objects are those that require a large amount of continuous memory space Java object , For example, a long string or a large array or
List aggregate , When large objects allocate space , It is easy to trigger garbage collection in advance when there is still a lot of space in the memory
Get enough contiguous space to store them , And when copying objects , Large objects will cause high memory replication overhead , by
To avoid those big objects in the new generation , And then repeatedly dodged GC And copy back and forth , here JVM Just put the big ,
Put the object into the old generation , Not through the new generation ;
 

原网站

版权声明
本文为[ZZ learn java well]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260922192479.html