当前位置:网站首页>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 .
边栏推荐
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- 从.bag文件中读取并保存.jpg图片和.pcd点云
- PCL 投影点云
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- Oracle 笔记
- UVM - usage of common TLM port
- Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
- Pywin32 opens the specified window
- 二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
- js数组常用方法
猜你喜欢
随机推荐
Ks009 implement pet management system based on SSH
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
大华设备播放过程中设置播放速度
Point cloud projection picture
华为联机对战服务玩家掉线重连案例总结
nodejs+express+mysql简单博客搭建
【TS】1368- 秒懂 TypeScript 泛型工具类型!
学习open62541 --- [66] UA_String的生成方法
Oracle 笔记
MySQL environment configuration
2022-06-17
PCL 从一个点云中提取一个子集
如何使用IDE自动签名调试鸿蒙应用
Leetcode+ 76 - 80 storm search topic
Kustomize使用手册
PCL point cloud to depth image
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
"Matching" is true love, a new attitude for young people to make friends
13.信号量临界区保护
Hdu1236 ranking (structure Sorting)








