当前位置:网站首页>JVM foundation > CMS garbage collector
JVM foundation > CMS garbage collector
2022-06-12 22:09:00 【Ouhuang xiaodezi】
CMS The collector
CMS Full name
Concurrent Mark Sweep, It's a concurrent 、 The main use of markers - The garbage collector of the clearing algorithm , The recycler is designed for the elderly generation , During the initialization phase, it will result in STW.
Here's one
a key: The main mark - The garbage collector of the clearing algorithm
It's not a marker - Sorting algorithm -> It means that there will be many memory gaps , Memory fragmentation , There are solutions- If there is not enough memory during concurrency, new objects will be generated , Will fail concurrently , Virtual Opportunities are forced to be temporarily enabled
Single threaded serial old Garbage collectorTo recycle the old garbage - There is also a parameter configuration , many times FullGC after , The next time FullGC I will execute a paragraph first
Mark - Sorting algorithm
- If there is not enough memory during concurrency, new objects will be generated , Will fail concurrently , Virtual Opportunities are forced to be temporarily enabled
No longer recommended CMS The collectorThe biggest reason is : There is G1 The collector , Improved some of its shortcomings , The authorities marked him as not recommended- In fact, it might CMS Or the most used , Everyone is JDK 8
CMS describe
- CMS The collector says
A new generation of ParNew The collectorandOld age CMS The collectorThe combination of - Whether it's ParNew Collectors are still obsolete Serial and Parallel The collector of , There is a very serious problem
- Is in the ParNew When these collector threads start running , other
All threads are suspended, until GC Thread completed - These collector threads cannot even coexist with other threads , With you and without me
- Is in the ParNew When these collector threads start running , other
- and CMS It is still used in the new generation ParNew The collector , Used in older generations
new CMS The collector, It can run concurrently with other threads- This is not to say that there will be no STW Other threads will not be paused , Not at all
- Is in
Pause for a short time when you need to, Other times threads can coexist , This will lead to visible improvement
So far , No garbage collector can prevent STW The birth of, Can only lower STW To optimize garbage collection efficiencyfor the first timeRealized to let garbage collection thread and user thread ( Basically ) Work at the same time
CMS Application scenarios
Appear in the :
Everything gets stuck and you break downApplications for !!!- APP It's just a light
You don't know what happened for no reasonIt got stuck - Impact on user experience
- APP It's just a light
Relative ,
May not be used CMS Application scenarios of- You know that there is a pause in submitting things, a pause in uploading, and so on
- In theory, you'll get stuck , Slightly stuck , It doesn't affect the user experience much
CMS To configure
Heap memory for 4G, The new generation is 2G, The old generation is also 2G
The new generation adopts ParNew The collector , The old days used concurrent mark removal CMS The collector
When the memory occupancy rate of the old age reaches 80% It's going to be FullGC, And enable defragmentation
-Xms4g -Xmx4g -Xmn2g -Xss1024K
-XX:ParallelGCThreads=5
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC
-XX:+UseCMSCompactAtFullCollection
-XX:CMSInitiatingOccupancyFraction=80
CMS Collection process
Be careful : The process of this description is CMS The collection process in the old days .CMS It was originally a garbage collector in the old days
Initial marker(CMS-initial-mark) , It can lead to STW;- Mark GC Roots Accessible objects ,GC Roots Itself and objects that can be directly referenced -> The markers are all objects from the old age
- The content is not much , Fast ,STW Pause the actual segment
Concurrent Tags(CMS-concurrent-mark), Run with user thread ;- From just marking GC Roots The reachable object starts , Traverse all reachable objects
- It takes a long time , But this phase can run concurrently
Re label(CMS-remark) , It can lead to swt;- Verify the modification tag , Marks that are not marked to
- The reference chain has changed and the tag is reanalyzed
- The time is average , Faster than initial marking , Slower than concurrent markup
- Verify the modification tag , Marks that are not marked to
Concurrent elimination(CMS-concurrent-sweep), Run with user thread ;- Delete directly

CMS The shortcomings of
Use
Mark - The removal algorithm has fragments, But there are solutions , There are corresponding parameters to start sortingFloating garbage: The last concurrent cleanup phase , There will also be new objects coming to the old age , These object garbage can no longer be marked at this time , Can only wait until next timeAffect the overall performance of the program: Because garbage collection is performed concurrently , therefore cpu Will always allocate time to the garbage collection thread , Will always occupy a part of cpu Resources for
give the thumbs-up . handsome young man
边栏推荐
- [proteus simulation] simple digital tube timer clock
- OceanBase 社区版 OCP 功能解读
- Pat grade A - 1167 Cartesian tree (30 points) (buildtree + level traversal)
- 脱颖而出!OceanBase 入选 2021“科创中国”开源创新榜单
- June training (day 12) - linked list
- Thread safe level
- C#读取word中表格数据
- What is the race condition? How do you find and solve the competition?
- 回文链表及链表相交问题(和心怡的人相交)你真的会了吗?
- 六月集训(第10天) —— 位运算
猜你喜欢

SQL tuning guide notes 14:managing extended statistics

Ansible playbook和变量(二)

SQL tuning guide notes 10:optimizer statistics concepts

How to perform disaster recovery and recovery for kubernetes cluster? (22)

Configuring Dingding notification of SQL audit platform archery

Jin AI her power | impact tech, she can

数据库每日一题---第10天:组合两个表

Cloning PDB with ADG standby

leetcodeSQL:574. Elected

Database daily question --- day 10: combine two tables
随机推荐
Ansible Roles-项目案例(四)
Is it safe to open an account in tonghuashun? How to open an account
建立高可用的数据库
Qt Quick 3D学习:使用鼠标键盘控制节点位置和方向
打新债开户安全么,新手该怎么操作?
Recommended Chinese font in the code input box of Oracle SQL developer
3.5 setup and teardown of test classes
How to implement a simple publish subscribe mode
多线程模型下的生产者消费者模式
Thread safe level
生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
List of open source alternative projects of world famous Cloud Service SaaS companies
How to prevent phishing emails? S/mime certificate to help!
Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?
六月集训(第10天) —— 位运算
What is the race condition? How do you find and solve the competition?
Database daily question --- day 10: combine two tables
[simple] 155 Minimum stack
"Oracle database parallel execution" technical white paper reading notes
Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)