当前位置:网站首页>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 .
边栏推荐
- Start class, data analysis, high salary training plan, elite class
- JSP webshell免殺——JSP的基礎
- 软件产品管理系统有哪些?12个最佳产品管理工具盘点
- [SUCTF2018]followme
- 12.进程同步与信号量
- MYSQL环境配置
- Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
- UVM - configuration mechanism
- 首份中国企业敏捷实践白皮书发布| 附完整下载
- Leetcode+ 76 - 80 storm search topic
猜你喜欢
随机推荐
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
【AI应用】海康威视iVMS-4200软件安装
UVM learning - object attribute of UVM phase
618再次霸榜的秘密何在?耐克最新财报给出答案
6种单例模式的实现方式
js数组常用方法
二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
static 函数中的静态变量
集成学习概览
正则及常用公式
使用华为性能管理服务,按需配置采样率
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
Solution of mysql8 forgetting password file in Windows Environment
In the face of uncertainty, the role of supply chain
Is the account above changtou school safe?
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
Sus system availability scale
Hdu1234 door opener and door closer (water question)
The URL in the RTSP setup header of the axis device cannot take a parameter
![[SUCTF2018]followme](/img/63/9104f9c8bd24937b0fc65053efec96.png)








