当前位置:网站首页>jvm-06. Garbage collector
jvm-06. Garbage collector
2022-06-23 05:56:00 【CaptainCats】
Garbage collector
jvm There are ten kinds of garbage collectors 
Generational model
6 Kind of
The younger generation
3 Kind of
ParNew、Serial、Parallel Scavenge.
Old age
3 Kind of
CMS、Serial Old、Parallel Old.
Partition model
3 Kind of
G1、ZGC、Shenandoah.
jdk1.8 Default garbage collector
java -XX:+PrintCommandLineFlags -version

It represents the young generation Parallel Scavenge And the old generation Parallel Old,
abbreviation PS+PO.
Young generation GC It's called minor GC or young GC, Old age GC It's called major GC or old GC, The whole of the younger and older generations GC It's called Full GC.
About jdk Version of , Here's an explanation ,
The reason to use "1.8.0_251" Because my motorcycle happens to be called 251.
Serial
A single threaded garbage collector using the copy method
The blue arrow represents the normal working thread , The yellow arrow represents the garbage collector ,
When the garbage collector is going to work , The worker thread stops at a safe point, Like archiving ,
After the garbage collection is over , The worker thread continues to execute .
stop-the-world,STW: Pause time .
Serial Old
A man who works in an old age , Use markers to remove / A single threaded garbage collector for compression methods .
Parallel Scavenge
Serial Multithreaded version of .
Parallel Old
Serial Old Multithreaded version of .
CMS
concurrent mark sweep
Garbage collection threads and business worker threads are parallel .
It is a very good solution , But it will bring a series of problems caused by concurrency .
ParNew
and Parallel Scavenge be similar , It is designed to cooperate with CMS Produced by use .
Tricolor notation
white : The object is not marked ;
gray , Object has been marked , The member variable is not marked ;
black : Both the object itself and the member variables have been marked .
The tricolor marker refers to the garbage collector scanning the reference chain ,
A mark given to an object on a chain , To identify whether it has been scanned .
The scan starts with a gray object , If you encounter a black object, you will not continue , Stop scanning .
There may be problems
Leakage and
A Is such an object , It has a member variable reference to B,B There is a member variable that refers to C.
During garbage collector scanning :
When the garbage collection thread scans , Business threads are also executing .
As the business goes on , During the execution of the business thread ,
B→D The reference to the lost , For example B Execution method b.setD(null);
When the garbage collector continues ,
because B It's gray. , Then go on to scan B Member variables of D when , Can not find .
This is called missed scanning ,
D It's called floating garbage , But it doesn't matter , The next recycling will D eliminate .
Wrong mark
As the business goes on ,A One more point D References to ,
But the garbage collector sees A It's black , No more scanning for references to its member variables ,
This is the time D May be considered garbage , So as to eliminate .
This is absolutely not allowed , Is the most serious problem .
CMS Solution :Incremental Update
When a black object is found to have a reference to a white object , Turn black into gray .
It is achieved by writing barriers , When a write operation occurs ,
example a.setD(d) when , If you find that A It's black ,B It's white , Just put A Marked gray .
But this solution creates hidden and deadly problems :
During the garbage collection process, there may be multiple recycling threads to modify the color mark .
It is equivalent to that there is still no missing mark , It's not practical .
therefore CMS Of remark Stage , amount to STW Of safe point,
It has to be scanned from the beginning ,
Scan points that may be missed , Low efficiency .
G1 Solution :SATB Snapshot At The Begining

边栏推荐
- MySQL面试真题(二十七)——RFM分析法对用户进行分类
- visdom的使用
- The traditional Internet like platform may no longer exist, and a new industry integrating industrial characteristics and Internet characteristics
- 新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!
- Work accumulation - judge whether GPS is on
- jvm-06.垃圾回收器
- Basic calculator II for leetcode topic analysis
- Opportunities and challenges of digital collections from the perspective of technology development team
- ORB_SLAM2运行
- MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选
猜你喜欢

技术开发团队视角看到的数字藏品机遇与挑战

True MySQL interview question (21) - Finance - overdue loan

Real MySQL interview questions (XXVI) -- didi 2020 written examination questions

C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)

The digital collection market has just begun

The construction of digital factory can be divided into three aspects

How can digital collections empower economic entities?

Opportunities and challenges of digital collections from the perspective of technology development team

Heimdall database proxy scale out 20 times

What does the English letter PC mean? What does the Internet PC mean
随机推荐
Opportunities and challenges of digital collections from the perspective of technology development team
三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
Skill self check | do you know these 6 skills if you want to be a test leader?
编址和编址单位
PAT 乙等 1010 C语言
PAT 乙等 1015 C语言
Software design and Development Notes 2: serial port debugging tool based on QT design
Leetcode topic analysis: factorial training zeroes
Basic calculator II for leetcode topic analysis
【斯坦福计网CS144项目】Lab2: TCPReceiver
数字藏品市场才刚刚开始
PAT 乙等 1023 组个最小数
[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
The official artifact of station B has cracked itself!
Real MySQL interview question (30) -- shell real estate order analysis
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
PAT 乙等 1009 C语言
The difference between SaaS software and traditional software delivery mode
android Handler内存泄露 kotlin内存泄露处理
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions