当前位置:网站首页>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

边栏推荐
- C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
- PAT 乙等 1014 C语言
- 数字藏品赋能实体产业释放了哪些利好?
- Redis cache penetration solution - bloom filter
- Alibaba cloud object storage oss+picgo+typera implements the construction map
- PAT 乙等 1016 C语言
- Addressing and addressing units
- mysql字符集
- Special research on Intelligent upgrading of heavy trucks in China in 2022
- ORB_SLAM2运行
猜你喜欢

True question of MySQL interview (29) -- case - finding favorite movies

The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming

Activity启动模式和生命周期实测结果

Wireshark TS | 视频 APP 无法播放问题

June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai

New classes are launched | 5 minutes each time, you can easily play with Alibaba cloud container service!

How does win11 enable mobile hotspot? How to enable mobile hotspot in win11

Wechat applet: elderly blessing short video

雷达图canvas

数字藏品市场才刚刚开始
随机推荐
Arctime makes Chinese and English subtitle video
Kotlin Android simple activity jump, simple combination of handler and thread
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
【数据库备份】通过定时任务完成MySQL数据库的备份
Analysis on the problems and causes of digital transformation of manufacturing industry
What is the magic of digital collections? Which reliable teams are currently developing
Real MySQL interview question (23) -- pinduoduo ball game analysis
PAT 乙等 1016 C语言
JS interview question - anti shake function
[graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
Explanation of penetration test process and methodology (Introduction to web security 04)
MySQL面试真题(二十三)——拼多多-球赛分析
PAT 乙等 1013 C语言
PAT 乙等 1022 D进制的A+B
Addressing and addressing units
AHA C language Chapter 8 game time is up (lesson 29)
技术开发团队视角看到的数字藏品机遇与挑战
Software design and Development Notes 2: serial port debugging tool based on QT design
三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会