当前位置:网站首页>What is the difference between minor GC and full GC?
What is the difference between minor GC and full GC?
2022-07-25 22:09:00 【Hua Weiyun】
Then describe the transformation process between them :
Priority is given to Eden Distribute . When eden When there is not enough space for allocation , The virtual machine will launch once Minor GC.
stay Eden The zone executed the first time GC after , Live objects are moved to one of them Survivor Partition ;
Eden District again GC, The replication algorithm is used , take Eden and from Clean up the area together , Live objects are copied to to District ;
Move once , Object age plus 1, If the object's age is greater than a certain threshold, it will move directly to the old age .GC The threshold of age can be determined by parameters -XX:MaxTenuringThreshold Set up , The default is 15;
Dynamic object age determination :Survivor The sum of the sizes of all objects of the same age > (Survivor The size of the memory area * The target usage ) when , People older than or equal to that age directly enter the elderly generation . Among them, the utilization rate is through -XX:TargetSurvivorRatio Appoint , The default is 50%;
Survivor If there is not enough memory in the buffer, a guaranteed allocation will occur , Objects larger than the specified size can enter the old generation directly .
Large objects go directly into the old generation , Large objects are objects that need a lot of continuous memory space ( such as : character string 、 Array ), In order to avoid the duplication caused by the allocation guarantee mechanism when allocating memory for large objects .
The old generation is full and unable to accommodate more objects ,Minor GC After that it usually goes on Full GC,Full GC Clean up the entire memory heap – Including the young and the old .
Minor GC and Full GC What's the difference ?
Minor GC: Only the new generation of GC.
Full GC: Collect the whole pile , Include The new generation , Old age , Forever ( stay JDK 1.8 And later , Permanent generation removed , Replace with metaspace Meta space ) Wait for all parts of the pattern .
Minor GC The trigger condition : When Eden Area is full , Trigger Minor GC.
Full GC The trigger condition :
adopt Minor GC The average size of backward into old age is larger than the available memory of old age . If found statistics are said before Minor GC The average size of promotion is larger than the current old gen There's a lot of room left , It doesn't trigger Minor GC It's going to trigger full GC.
There was not enough space in the old days to allocate new memory ( Or lack of permanent space , But only JDK1.7 yes , we have , This is also the reason why Metaspace is used to replace permanent generation , Can reduce the Full GC The frequency of , Reduce GC burden , Improve its efficiency ).
from Eden District 、From Space District direction To Space When copying , The object size is greater than To Space Available memory , Then transfer the object to the old age , And the available memory of the old age is smaller than the size of the object .
call System.gc when , System recommendation implementation Full GC, But not necessarily .
Introduce the principle of space allocation guarantee ?
If YougGC A large number of objects survived in the Cenozoic , and survivor There's no room for it , It has to be transferred to the older generation , But at this time, I found that the elderly generation could not put down these objects , How to deal with it ? Actually JVM There is an old age space allocation guarantee mechanism to ensure that the object can enter the old age .
In the execution of every YoungGC Before ,JVM We will first check whether the maximum available continuous space of the old generation is greater than the total size of all objects in the new generation . Because in extreme cases , Maybe the new generation YoungGC after , All the objects survived , and survivor I can't put it in the area , Then maybe all of them are going to be older . At this time, if the available continuous space in the old age is larger than the total size of all objects in the new generation , Then you can do it with ease YoungGC. But if the memory size of the old generation is smaller than the total size of the new generation objects , Then it is possible that the space of the old age is not enough for all the surviving objects of the new generation , This is the time JVM I'll check first -XX:HandlePromotionFailure Parameter whether guarantee failure is allowed , If allowed , It will determine whether the maximum available continuous space of the old age is greater than the average size of the objects promoted to the old age , If it is greater than , There will be an attempt to YoungGC, As soon as possible, this time YoungGC There are risks . If it is less than , perhaps -XX:HandlePromotionFailure Parameter does not allow guarantee failure , It's going to be done once Full GC.
After allowing the guarantee to fail and trying to YoungGC after , There are three possible scenarios :
① YoungGC after , The surviving objects are smaller than survivor size , At this point, the surviving object enters survivor In the area
② YoungGC after , The surviving objects are larger than survivor size , But it's smaller than the big available space for the elderly , At this time, we directly enter the old generation .
③ YoungGC after , The surviving objects are larger than survivor size , It's also bigger than the big available space for the elderly , The older generation can't let go of these objects , And then it happens “Handle Promotion Failure”, It's triggered Full GC. If Full GC after , There is still not enough space in the old days , And then it happens OOM Memory overflow .
边栏推荐
- After three years of software testing at Tencent, I was ruthlessly dismissed in July, trying to wake up my brother who was paddling
- YUV420 YUV420sp 图像格式「建议收藏」
- c sqlite ... ...
- c sqlite ... ...
- TS:typora代码片段缩进显示异常(已解决)-2022.7.24
- El expression improves JSP
- 什么是分区分桶?
- What have I experienced to become a harder tester than development?
- The second short contact of gamecloud 1608
- [hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)
猜你喜欢

Bitcoin.com:usdd represents a truly decentralized stable currency

Fill the whole square with the float property

自动化测试岗花20K招人,到最后居然没一个合适的,招两个应届生都比他们强吧

Jmeter--- set proxy recording request

什么是分区分桶?

Having met a tester with three years' experience in Tencent, I saw the real test ceiling

H5幸运刮刮乐抽奖 免公众号+直运营

Don't vote, software testing posts are saturated
![[go basics 02] the first procedure](/img/af/f32762a828f384bf6aa063ebf959aa.png)
[go basics 02] the first procedure

『SignalR』. Net using signalr for real-time communication
随机推荐
The technical aspects of ByteDance are all over, but the result is still brushed. Ask HR why...
El expression improves JSP
Acwing 866. determining prime numbers by trial division
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
手机端微信发朋友圈功能测试点总结
C language left value and right value description [easy to understand]
C language: random generated number + selective sorting
After 2 years of functional testing, I feel like I can't do anything. Where should I go in 2022?
jsp九大内置对象
[hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
2年功能测试,却感觉自己什么都不会,2022我该何去何从?
redis主从架构锁失效问题(主从)
『SignalR』.NET使用 SignalR 进行实时通信初体验
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc
Uninstall NPM and install NPM_ Use 'NPM uninstall' to uninstall the NPM package 'recommended collection'
Redis master-slave architecture lock failure problem (master-slave)
sql语句练习题整理
ZigBee development board (nxpzigbee Development)
【GO基础02】第一个程序