当前位置:网站首页>【JVM】G1垃圾回收器簡述
【JVM】G1垃圾回收器簡述
2022-06-30 09:54:00 【右眸Remnant】
提示:文章寫完後,目錄可以自動生成,如何生成可參考右邊的幫助文檔
G1垃圾回收器簡述
為什麼不使用CMS?
之前介紹CMS是以響應停頓時間最短為目的,是垃圾收集器中的裏程碑,CMS分為Background和Foreground, Background為正常模式,整個回收過程分為4步:初始標記,並發標記,重新標記,並發清除,為了避免全量掃描的大數據量,在並發標記過程後Eden區容量達到2M,存在預標記階段,當占用空間達到Eden的50%終止這個階段進入重新標記;Foreground為並發失敗進入的錯誤環境,執行狀態為單線程。
盡管CMS的響應停頓時間很好,但是忽略了吞吐量,在單線程或者雙線程狀態下CMS的使用狀態也不佳,因為雙線程並發的時候,分為一個業務線程和一個垃圾回收線程,也存在CPU的調度導致頻繁的上下文切換,因此有效率損耗問題。
其次,在可終止的預標記階段,如果沒有發生minor GC,CMS會停頓極限時間為5s;而進入foreground也錶示CMS需要進行Full GC;
綜上:CMS的缺點在於他的並發失敗,停頓不可預測以及吞吐量較低。
G1概述
G1的目的:Garbage First,也就是垃圾優先原則,也就是空間方面的關注點。同時照顧到停頓時間以及吞吐量。
G1對內存空間重新定義,不再以物理空間分為Old和Young,而是在邏輯上將內存劃分為若幹Region,內存中默認Region為2048個,每個Region的大小為1M~32M
對象分為:自由對象(Empty),新生代(Eden, Survivor),Old區和大對象
Region對於自身的角色是不固定的,即可能在下次分配空間的時候角色從Old變為E或者其他
JDK11之後有一類特殊的分區,叫做歸檔分區,關閉歸檔分區以及開放歸檔分區
TLAB:線程本地分配內存, 在G1中分配對象內存的時候,由於G1是並發處理的垃圾收集器,同一時間可能由高並發,這就涉及了數據的並發安全問題需要全局鎖保證數據安全,但是會帶來效率上的下降。
TLAB是Eden區上的一部分區域(1%),在分配內存的時候首先判斷TLAB上是否能够分配,如果不可以,會選擇TLAB外的Region區域進行分配,如果還是空間不足進行Full GC。
其他概念
RSet:應用集,是G1中對與記憶集的實現,類比CMS中的卡錶。
在G1中,假設有A Region, Rset會記錄其他Region執行A的記錄;
Q:這樣做的優勢是什麼?
A:假設如果有O區對象指向Y區(感覺相反情况也類似),在對新生代回收的時候,還需要對O區進行一次遍曆,間接的成為了全量掃描,而通過Rset可以記錄到:設這裏Y區對象就是A,因此Rset中的記錄為O區引用,這樣只需要掃描Rset就可以知道所有的引用情况了,不需要全量掃描。
沒深入研究的部分:稀疏錶,粗粒度比特圖,細粒度比特圖
边栏推荐
- OCX child thread cannot trigger event event (forward)
- ABAP time function
- JVM tuning tool introduction and constant pool explanation
- Distributed ID
- Is the jar package for the project or the project for the jar package
- Valuenotifier and valuelistenablebuilder in fluent
- JVM family
- 单片机 MCU 固件打包脚本软件
- Redis docker 主从模式与哨兵sentinel
- Enterprise data center "cloud" transformation solution
猜你喜欢

小程序手持弹幕的原理及实现(uni-app)

安装和使用

How do databases go to the enterprise cloud? Click to view the answer

Xlnet (generalized autorefressive trainingfor language understanding) paper notes

Dart development skills

How to build an all-in-one database cloud machine that meets the needs of information innovation?

Good partner for cloud skill improvement, senior brother cloud of Amazon officially opened today

Comparison problems encountered in recent study

Read the difference and connection between hyperfusion and private cloud

Network based dynamic routing protocol (OSPF)
随机推荐
Why won't gold depreciate???
Upgrade log4j2 to 2.17.1 stepped pit
The present situation and challenge of the infrastructure of Yiwen parsing database
小程序手持弹幕的原理及实现(uni-app)
Principle and implementation of small program hand-held bullet screen (uni APP)
MySQL internal component structure
[ubuntu-mysql 8 installation and master-slave replication]
Bloom filter
银河麒麟server-V10配置镜像源
Design of mfc+mysql document data management system based on VS2010
Good partner for cloud skill improvement, senior brother cloud of Amazon officially opened today
Create thread pool demo
11.自定义hooks
[new book recommendation] cleaning data for effective data science
Redis docker master-slave mode and sentinel
[new book recommendation] DeNO web development
2021-11-15
qmlplugindump executable not found.It is required to generate the qmltypes file for VTK Qml
Flume learning III
【Ubuntu-MySQL8安装与主从复制】