当前位置:网站首页>JVM foundation > G1 garbage collector
JVM foundation > G1 garbage collector
2022-06-12 22:09:00 【Ouhuang xiaodezi】
say something G1 Garbage collector
G1 overview
G1 GC The full name is Garbage First Garbage Collector, Garbage priority garbage collector , hereinafter referred to as G1.
G1 yes HotSpot JVM Of
Short pause garbage collector.In fact, about G1 My thesis dates back to 2004 In, there was , however G1 Is in 2012 year 4 Released on
JDK 7u4It's only in the middle of the world .In the long run ,G1 Aimed at
replace CMS(Concurrent Mark Sweep) Garbage collector .G1 from JDK9 Started as
Default garbage collector.If pause time is more important to an application than throughput ,G1 It's a very suitable choice .
On the whole G1 It has the following characteristics :
- G1 Still generational ( The younger generation , Old age ) The garbage collector
- G1 Two garbage collection algorithms are implemented ->
Mark - Copy algorithm+Mark - Sorting algorithm - G1 There is no need to recycle all the garbage in the heap at one time ,G1 A piece of memory with too much garbage will be dynamically selected for priority recycling
- And you can specify the desired pause time
G1 Innovative design of waste recycling
Memory layout
G1Although it is still divided into generations ( The younger generation , Old age ) The garbage collector , But it no longer follows the generational arrangement of objects in the heap , Instead, the heap is divided into several equal sized areas .

But to become :
Equalize heap memory into small chunks (Region), This little piece (Region) How big is controllable
Through parameters
-XX:G1HeapRegionSize=nYou can specify the partition size (1MB~32MB, And it must be 2 The power of )By default, the whole heap is divided into 2048 Zones -> If the heap is 2g, So every little piece (Region) Namely 1M
Humongous: When you allocate more than half of an object area (Region) The size of ( exceed 0.5M when ), This object will be placed in this area . This area belongs to the old age area .
G1 Garbage collection process
G1 Garbage collection mainly includes 2 individual :
- Cenozoic recycling process (young gc) -> Recycling
- Applications allocate memory , When the new generation Eden When the zone is exhausted, the new generation recycling process begins
- Mixed recycling process (mixed gc) -> Recycling
- When the heap memory usage reaches a certain value ( Default 45%) when , Start the old age concurrent tagging process , Mark complete and start the mixed recycling process immediately .
Cenozoic recycling process
The general logic will not change much :The living object is transferred to a / Or more survivor Put it on the block . If the survival time reaches the threshold , This part of the object will be promoted to the old age .
Mixed recycling process
Initial marker
Just mark GC roots Objects that can be directly related to . This step requires STW, But the time is very short .Concurrent Tags
from GC roots Using reachability algorithms , Mark objects in heap memory (Tricolor notation), Recursively scans the entire heap . This step takes too long , It is executed concurrently with the user business program .Re label
For user threads For a short time STW, Used to handle the finalization of some changes to objects in concurrent markup .Screening and recovery
G1 According to the pause time specified by the user , Maximum recycling region, Will need to be recycled region Copy to blank region in , Then put the original region All recycled . The Steps also require STW, Because it involves the movement of objects ( One region To another region).
边栏推荐
- Ansible Roles-项目案例(四)
- My struggle: my years in foreign enterprises (1)
- [data analysis] data clustering and grouping based on kmeans, including Matlab source code
- Ansible roles project case (IV)
- Design and practice of Hudi bucket index in byte skipping
- SQL tuning guide notes 17:importing and exporting optimizer statistics
- Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases
- How to prevent phishing emails? S/mime certificate to help!
- SQL调优指南笔记8:Optimizer Access Paths
- What are thread scheduler and timeslicing?
猜你喜欢

关于 安装Qt5.15.2启动QtCreator后“应用程序无法正常启动0xc0000022” 的解决方法

SQL tuning guide notes 14:managing extended statistics

Ansible playbook和Ansible Roles(三)

IPhone: save Boolean into core data - iphone: save Boolean into core data

MySQL architecture and basic management (II)

微信小程序提现功能

Mr. Sun's version of JDBC (21:34:25, June 12, 2022)

孙老师版本JDBC(2022年6月12日21:34:25)
![[C language] data type occupation](/img/12/e0f9679076d89fb5bd993ee3c345bf.jpg)
[C language] data type occupation

设计消息队列存储消息数据的 MySQL 表格
随机推荐
关于 安装Qt5.15.2启动QtCreator后“应用程序无法正常启动0xc0000022” 的解决方法
六月集训(第11天) —— 矩阵
MySQL介绍和安装(一)
Is it safe to open an account in tonghuashun? How to open an account
SQL tuning guide notes 17:importing and exporting optimizer statistics
Is it safe to open an account with new bonds? How should novices operate?
My struggle: my years in foreign enterprises (1)
设计消息队列存储消息数据的 MySQL 表格
USB mechanical keyboard changed to Bluetooth Keyboard
What is the race condition? How do you find and solve the competition?
June training (day 10) - bit operation
在同花顺开户证券安全吗,证券开户怎么开户流程
[Jianzhi offer simple] Jianzhi offer 06 Print linked list from end to end
SQL tuning guide notes 16:managing historical optimizer statistics
February 27th
leetcodeSQL:574. Elected
The kotlin coroutine -- coroutine context and exception propagation
How to write a vscode plug-in by yourself to realize plug-in freedom!
【Proteus仿真】简易数码管定时器时钟
SQL tuning guide notes 11:histograms