当前位置:网站首页>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
边栏推荐
- JVM知识点
- JVM knowledge points
- Vite: configure IP access
- 【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)
- Monkey test
- 整理了一份ECS夏日省钱秘籍,这次@老用户快来领走
- Go language introduction
- Lei Jun wrote a blog when he was a programmer. It's awesome
- Force buckle 540 A single element in an ordered array
- "No war on the Western Front" we just began to love life, but we had to shoot at everything
猜你喜欢
[tips] use Matlab GUI to read files in dialog mode
树莓派GPIO引脚控制红绿灯与轰鸣器
Installation et utilisation du lac bleu
MySQL advanced SQL statement 2
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板,老板也有建设积分和捣乱积分, 排好队后,所有
Microsoft Research Institute's new book "Fundamentals of data science", 479 Pages pdf
First acquaintance with P4 language
66.qt quick QML Custom Calendar component (supports vertical and horizontal screens)
The second game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
[ibdfe] matlab simulation of frequency domain equalization based on ibdfe
随机推荐
Opencv learning example code 3.2.4 LUT
The 7th Blue Bridge Cup single chip microcomputer provincial competition
The original author is out! Faker. JS has been controlled by the community..
MySQL error: expression 1 of select list is not in group by claim and contains nonaggre
Li Kou interview question 02.08 Loop detection
Wechat applet - realize the countdown of 60 seconds to obtain the mobile verification code (mobile number + verification code login function)
文档声明与字符编码
Feature Engineering: summary of common feature transformation methods
go 分支与循环
go 函数
0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
The 6th Blue Bridge Cup single chip microcomputer provincial competition
Sword finger offer II 006 Sort the sum of two numbers in the array
Basic operations of MySQL database (based on tables)
【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真
《动手学深度学习》(二)-- 多层感知机
MySQL advanced SQL statement 2
Lost a few hairs, and finally learned - graph traversal -dfs and BFS
一文彻底理解评分卡开发中——Y的确定(Vintage分析、滚动率分析等)