当前位置:网站首页>10 minutes to understand CMS garbage collector in JVM
10 minutes to understand CMS garbage collector in JVM
2022-07-02 04:03:00 【Java architecture design】
CMS It's based on markers - Clearing algorithm's , The collection is divided into 4 A step :
Initial marker
Concurrent Tags
Re label
Concurrent elimination
Initial marker
The initial mark is just a mark GC Roots Objects that can be directly related to , So it's very fast . For example, below , This way GC Roots Using the virtual machine stack as an example . Two VMS stack tables create objects OBJ_A1 and OBJ_B1, They also have their own other quotes , At this stage , He just marks OBJ_A1 and OBJ_B1, Other references are unmarked , So even though this stage has STW, But the number of markers is small , Time soon , It doesn't affect .

Concurrent Tags
Concurrent marking is based on the object directly or indirectly referenced by the initial marked object , For example, the figure below is right OBJ_A2,OBJ_AN Mark concurrency . There's no such thing at this stage STW, So you can create objects , Add a new reference , It also causes some objects to lose references , For example, below ,OBJ_B1 It has become rubbish ,OBJ_C1 It's a new live object . This stage is due to tracking all the objects of the old age , So it's very time consuming .

Re label
In concurrent tags , We see living objects OBJ_C1 And garbage objects OBJ_B1 Wait is not marked , So this stage is to re label these objects . There are also STW, However, only objects with changes in concurrent tags are marked , These numbers are relatively small , So the speed is also very fast .

Concurrent elimination
This stage , It's just after the tagging , Cleaning up garbage objects , Just like concurrent tags , It's time consuming , Because there is no STW, So it has little effect on the operation of the program .CMS It uses the marking and clearing algorithm .

shortcoming
CMS Of 4 Stages , Initial marking and relabeling require STW, But the time is short , The impact is not big . Concurrent marking and concurrent cleanup do not require STW, Although it takes time , But concurrent execution , It doesn't matter much , look CMS Perfect. , But he also has some shortcomings .
CPU
CMS The number of recycle threads started by default is (CPU Number +3)/ 4, That is to say CPU stay 4 More than one time , The garbage collection thread shall not be less than 25% Of CPU resources , And with CPU An increase in quantity leads to a decrease . For example, the server is 2 nucleus 4G, Then we need to use (2+3)/4=1 Threads to handle concurrent tagging and concurrent cleanup , At this time, only 1 Threads handle other things .
Floating garbage
The production of floating garbage , Mainly in the concurrent cleanup phase . After re labeling ,CMS The garbage collector will know what needs to be cleaned up , In the concurrent cleanup phase , Clean up the re marked garbage objects , There's no such thing at this stage STW, So it's possible to create new objects .
For example, in the picture below OBJ_N, After you create , Stack frames are recycled , The quotation is gone , He can't be cleared at this stage , I can only wait for the next garbage collection , Marked and cleared .
If the objects in the old age of this stage exceed the remaining space , Will appear Concurrent Mode Failure Failure , The virtual opportunity is temporarily enabled Serial Old Collector for old age garbage collection .
It can be used XX:CMSInitiatingOccupancyFraction Set the percentage of old age space occupied CMS Recycling ,JDK1.6 After the default 92%.

space debris
stay 《JVM Garbage collection algorithm 》 It is mentioned in the article , Mark - The clean-up algorithm will generate space debris , If there is not enough contiguous memory space to hold objects that are about to enter the old age , This will trigger Full GC.
To avoid that ,CMS The collector provides a -XX:+UseCMSCompactAtFullCollection, Open by default , When Full GC After completion , He will STW, To organize the memory , Keep the living objects together , Make room for continuity .
If you have to reset the memory every time , The city STW, therefore CMS It also provides -XX:CMSFullGCsBeforeCompaction Parameters , The default is 0, Indicates how many times Full GC After finishing the memory .
Link to the original text :https://mp.weixin.qq.com/s?__biz=Mzg4MjU0OTM1OA==&mid=2247499410&idx=1&sn=787037527afd5762e407626d010a7589
边栏推荐
- The confusion I encountered when learning stm32
- 【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真
- pip 安装第三方库
- Uni app - realize the countdown of 60 seconds to obtain the mobile verification code (mobile number + verification code login function)
- How to model noise data? Hong Kong Baptist University's latest review paper on "label noise representation learning" comprehensively expounds the data, objective function and optimization strategy of
- Fluent icon demo
- Demonstration description of integrated base scheme
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
- Li Kou interview question 02.08 Loop detection
- Interface debugging tool simulates post upload file - apipost
猜你喜欢

【IBDFE】基于IBDFE的频域均衡matlab仿真

【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)

2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板,老板也有建设积分和捣乱积分, 排好队后,所有

Sword finger offer II 006 Sort the sum of two numbers in the array

The 11th Blue Bridge Cup single chip microcomputer provincial competition

First acquaintance with string+ simple usage (II)

《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮

MySQL error: expression 1 of select list is not in group by claim and contains nonaggre

《动手学深度学习》(二)-- 多层感知机

Déchirure à la main - tri
随机推荐
PIP installation of third-party libraries
Analysis of the overall design principle of Nacos configuration center (persistence, clustering, information synchronization)
0基础如何学习自动化测试?按照这7步一步一步来学习就成功了
Vite: scaffold assembly
Which is better, industrial intelligent gateway or edge computing gateway? How to choose the right one?
Wechat applet - realize the countdown of 60 seconds to obtain the mobile verification code (mobile number + verification code login function)
L'avènement de l'ère 5G, une brève discussion sur la vie passée et présente des communications mobiles
蓝湖的安装及使用
It took me only 3 months to jump out of the comfort zone and become an automated test engineer for 5 years
Uni app - realize the countdown of 60 seconds to obtain the mobile verification code (mobile number + verification code login function)
Fluent icon demo
Introduction to vmware workstation and vSphere
Vite: configure IP access
[tips] use Matlab GUI to read files in dialog mode
66.qt quick-qml自定义日历组件(支持竖屏和横屏)
【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)
Learn more about materialapp and common attribute parsing in fluent
潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
接口调试工具模拟Post上传文件——ApiPost
Welcome the winter vacation multi school league game 2 partial solution (B, C, D, F, G, H)