当前位置:网站首页>JVM garbage collector
JVM garbage collector
2022-07-02 10:58:00 【Big fish eating cats】
Preface
Last time JVM Garbage collection algorithm , After the foreshadowing of the previous article, this article focuses on JVM Of GC Recyclers , The main contents are referred to 《 In depth understanding of Java virtual machine 》.
This article focuses on CMS and G1GC, Other recyclers will be directly carried by .
One 、 Common garbage collectors
Here are JDK8-JDK9 Common garbage collector combinations :
From the above figure, we can draw a conclusion :
- JDK8 Supported garbage collection combinations are :Serial+Serial Old,Parallel Scavenge+Parallel Old,CMS+ParNew,Parallel Scavenge+Serial Old,G1 Five combinations ;
- JDK9 stay JDK8 On the basis of the new Serial + CMS,ParNew+Serial Old Two combinations .
among JDK8 default GC The combination is Parallel Scavenge+Parallel Old,JDK9 Default GC yes G1GC.
Two 、CMS The collector
1. brief introduction
CMS(concurrent mark sweep) Collector is a kind of collector that aims to obtain the shortest recovery pause time .
From its name (mark sweep) You can see that it is based on tags - Clear algorithm implementation .
2. Collection process
The process is relatively complicated , There are mainly 4 part :
- Initial marker , Just mark it GC Roots Objects that can be directly related , Short time , Meeting STW;
- Concurrent Tags , from GC Roots The process of traversing the whole object graph begins with the directly related object , Time consuming . Execute with user thread , There is no need to pause .
- Re label , Increment mark , Resolve the objects that cause tag changes during user thread runtime during concurrent tagging , Less time consuming , Meeting STW( The solution is the recyclable garbage added by the user thread during concurrent marking );
- Concurrent elimination , Objects that are judged to be dead in the clear and delete mark stage . Because it is executed together with the user thread , There is no need to pause .

3. Advantages and disadvantages
advantage :
Concurrent collection , Low pause .
shortcoming :
- Because it is a concurrent collection, it is very sensitive to processor resources , Will take up part of CPU;
- Based on tags - Clear algorithm implementation , There is a memory fragmentation problem ( Mark - Clear algorithm problems );
- Can't handle floating garbage , User threads are running in both the concurrent marking and concurrent cleanup phases , The garbage generated during this period can only be left for the next collection , This is floating garbage .
3、 ... and 、G1 The collector
1. brief introduction
G1 Collector is a milestone in the development of garbage collector technology , It pioneers the design idea of collector for local collection and is based on region Memory form of layout ( Physical zoning , Logical generation ).
It is worth mentioning that JDK8 Support G1GC,JDK9 Default garbage collector , And CMS Reduced to a deprecated garbage collector , As if CMS Alternative optimized version .
It is no longer measured by which generation it belongs , It's about which memory holds the most garbage , Maximum return , namely Mixed GC Pattern .
2. Collection process
There are mainly 4 A process :
- Initial marker , Mark GC Roots Objects that can be directly related to ( For a short time STW);
- Concurrent Tags , from GC Roots Start the reachability analysis of the objects in the heap , Recursively scan the whole heap to find the object to be recycled , Execute in parallel with the user thread ( There is no need to pause , Longer time consuming );
- Final marker , Increment mark , Resolve the objects that cause tag changes during user thread runtime during concurrent tagging ( Shorter STW);
- Screening markers , Is responsible for updating Region Statistical data , To each Region Sorted by recovery value and cost , Make a recycling plan based on the user's expected pause time , You can choose any number Region Make up a recycling set , Then decide to recycle that part Region Of live objects copied to empty region in , And clean up the whole old region All the space of ( Longer STW, Core design , The expected delay time can be set . The default is 200ms).

3. Advantages and disadvantages
advantage :
1. Use alone , There's no need to combine , Less parameters , Low tuning cost ;
2. You can set the estimated pause time ;
3. There will be no memory fragmentation ( A collector based on tag collation Algorithm ).
shortcoming :
1. Need more memory support ( branch region);
2. Yes CPU Multi core is required ( Many concurrent operations ).
summary
In large memory (>=6G) Under the system, if you choose to use CMS and G1 Recommended G1; On the contrary, the system has small memory (<6G) Because of G1GC Partitions occupy more space , In theory, it will be better than CMS Bad .
边栏推荐
- 华为联机对战服务玩家掉线重连案例总结
- Session cookies and tokens
- 洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
- 4. Random variables
- 13. Semaphore critical zone protection
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- 2022-06-17
- 二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
- JS settimeout() and interview questions
- 使用华为性能管理服务,按需配置采样率
猜你喜欢

Shutter - canvas custom graph

Easyexcel, a concise, fast and memory saving excel processing tool

二叉树专题--AcWing 1589. 构建二叉搜索树

JSP webshell免杀——JSP的基础

Analysis of hot spots in AI technology industry

首份中国企业敏捷实践白皮书发布| 附完整下载

HDU1234 开门人和关门人(水题)

Retrofit's callback hell is really vulnerable in kotlin synergy mode!

2022爱分析· 国央企数字化厂商全景报告

洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
随机推荐
In the face of uncertainty, the role of supply chain
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
Jsp webshell Free from killing - The Foundation of JSP
PCL eigen introduction and simple use
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
JSP webshell免杀——JSP的基础
华为快应用中如何实现同时传递事件对象和自定义参数
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
点云投影图片
软件产品管理系统有哪些?12个最佳产品管理工具盘点
快应用中实现自定义抽屉组件
13.信号量临界区保护
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
"Matching" is true love, a new attitude for young people to make friends
Shell programming 01_ Shell foundation
Convert yv12 to rgb565 image conversion, with YUV to RGB test
Hdu1228 a + B (map mapping)
全网显示 IP 归属地,是怎么实现的?
(五)APA场景搭建之挡位控制设置
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application