当前位置:网站首页>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 .
边栏推荐
- 二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
- nodejs+express+mysql简单博客搭建
- Hdu1228 a + B (map mapping)
- UVM - configuration mechanism
- What are the popular frameworks for swoole in 2022?
- JSP webshell免杀——webshell免杀
- Win11 arm系统配置.net core环境变量
- Is this code PHP MySQL redundant?
- 从MediaRecord录像中读取H264参数
- LeetCode+ 76 - 80 暴搜专题
猜你喜欢

全网显示 IP 归属地,是怎么实现的?
![[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)](/img/9f/4265f1e3927fcf66602f0fc9e7a9d9.jpg)
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)

Overview of integrated learning

二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)

使用sqlcipher打开加密的sqlite方法

AI技术产业热点分析

12. Process synchronization and semaphore

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

华为应用市场应用统计数据问题大揭秘

MYSQL环境配置
随机推荐
Introduction to MySQL 8 DBA foundation tutorial
拆解美图SaaS:开着飞机换引擎
618再次霸榜的秘密何在?耐克最新财报给出答案
简洁、快速、节约内存的Excel处理工具EasyExcel
Analysis of hot spots in AI technology industry
二叉树专题--AcWing 1589. 构建二叉搜索树
2. Hacking lab script off [detailed writeup]
PCL extracts a subset from a point cloud
4. Random variables
Shapiro Wilk normal analysis by SPSS
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
Convert yv12 to rgb565 image conversion, with YUV to RGB test
MYSQL环境配置
PCL 从一个点云中提取一个子集
shell编程01_Shell基础
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
一招快速实现自定义快应用titlebar
1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
Database dictionary Navicat automatic generation version
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)