当前位置:网站首页>Explore ZGC
Explore ZGC
2022-07-18 06:33:00 【Cheng Ming, Cheng Ming, you're going to be famous】
ZGC(The Z Garbage Collector) yes JDK 11 A low latency garbage collector introduced in , It's at the experimental stage , Its advantages include :
- The pause time shall not exceed 10ms, Can be in KB~TB Garbage collection under the scope of work ;
- The pause time doesn't vary with the size of the heap , Or the size of the active object ;
- Support 8MB~4TB Level heap ( Future support 16TB)
Why introduce ZGC
It is well known that in some applications with high performance and low latency ,GC Often the bottleneck of application , Because in GC In the meantime STW(Stop The World), When STW when , All application threads stop active , wait for GC The pause ended . In some systems with strict response time ,GC It is often very difficult to optimize , This is also an important reason why garbage collectors are evolving .
ZGC Guarantee , In any case , The delay will not exceed 10 millisecond .
The Z Garbage Collector, also known as ZGC, is a scalable low latency garbage collector designed to meet the following goals:
- Pause times do not exceed 10ms
- Pause times do not increase with the heap or live-set size
- Handle heaps ranging from a few hundred megabytes to multi terabytes in size
Now for CMS and G1 Of GC Process and pause time bottlenecks , Globally concurrent ZGC( Mark 、 The transition and relocation phases are almost all concurrent ) Obviously a better choice .
ZGC Characteristics
ZGC The most typical feature is that it is a concurrent (concurrent) Of GC, Other features are as follows :
It can mark memory , Replication and migration (relocate) Memory , All operations are concurrent , At the same time, it has a concurrent reference processor
Other garbage collectors use store barriers,ZGC Use load barriers, Used to track memory
- lock->unlock->read->load Read memory
- use->assign->store->write Write memory
ZGC You can configure the size and policy more flexibly , Compared with G1, It can better handle very large (very large) Release of objects
ZGC Only one generation , No Cenozoic , The old generation , however ZGC It can support local compression , In memory recovery and migration (reclaim and relocate) when ,ZGC It still has high performance
ZGC rely on NUMA-aware( Unbalanced memory access ), We need our memory to support this feature
ZGC Heap memory layout
And G1 equally ,ZGC Also based on Region The heap memory layout of
ZGC Of Region It's dynamic
Dynamic creation and destruction
Dynamic Region Capacity size

Size classification :small Region(Small Region): Fixed size 2MB, Store less than 256KB The little object of
medium Region(Medium Region): Fixed size 32MB, Store more than 256KB Less than 4MB The object of
large Region(Large Region): Size is not fixed , Can change dynamically , But it has to be 2MB Integer multiple , Used to put larger than 4MB Large objects of , Each large Region Only one big object , So the actual capacity may be smaller than medium Region, Minimum to 4MB. large Region stay ZGC There is no reallocation in the implementation , Because copying a large object is too expensive .
ZGC Coloring pointer Technology
Colored pointer is a technique that directly stores a small amount of extra information on the pointer . Currently in Linux Next 64 Bit in the operating system 18 Bits are not addressable , But the rest 46 To support 64T Space , So far we have barely used so much memory . therefore ZGC take 46 High in the middle 4 Bit out , Used to store 4 Flag bits , remainder 42 Bits can support 4TB(2 Of 42 The next power ) Of memory , It also directly leads to ZGC No more memory can be managed than 4TB, As shown in the figure :
- Marked0/marked1: Determine whether the object is marked
- Remapped: Determine if the application has pointed to a new address
- Finalizable: Determine whether an object can only be Finalizer visit
These are a few bits Different states represent different colors of the reference
The process of object marking is to make a three color mark , These tags are essentially only about object references , It has nothing to do with the object itself . Only the reference relation of an object determines its survival .
ZGC Memory multi mapping used (Multi-Mapping) Map multiple virtual memory addresses to the same physical memory address , This is a many to one mapping . Because stained pointers only redefine a few bits of some pointers in memory ,OS And does not support ,OS Only treat the whole pointer as a memory address , It's just that it thinks about it , To solve this problem , Using the virtual memory mapping technology of modern processors .
ZGC Reading barrier technology
The reading barrier is JVM The technique of inserting a small piece of code into application code . When an application thread reads an object reference from the heap , It will execute this code . It should be noted that , only “ Read object references from the heap ” This code will trigger .
ZGC Recycling process

We will disassemble the above figure to understand
- Initial marker (STW)

Stop the user thread , Mark GC Root object . 1、2、4 Marked as a living object .
- Concurrent Tags

Concurrent recursion from GC Root Start traversing reachable objects ,5、8 Marked as a living object .
- move objects

Compared with 3、6、7 It's an expired object , Gray in the middle Region Need to be cleaned up and compressed , So will 4、5、8 Move to the right empty Region, There's a forward table Record this transformation .
- Fixed pointer

because 4、5、8 There was a movement , So it needs to be fixed .
summary
- ZGC As the next generation of garbage collectors , Excellent performance .ZGC The garbage collection process is almost entirely concurrent , actual STW The pause time is very short , Less than 10ms. This is due to the colored pointer and read barrier technology used .
- ZGC No “ Silver bullet ”, It needs to be tuned according to the specific characteristics of the service , And need support NUMA-aware( Unbalanced memory access ), We need our memory to support this feature . Therefore, it is still necessary to weigh according to the needs of the company's business and the actual situation .
Reference link
边栏推荐
- 迭代器与生成器
- 杰理之开启按键配对,第一次配对 tws 后,再进行交叉配对很难配对 成功【篇】
- 图扑 Web 可视化引擎在仿真分析领域的应用
- [C #] commonly used utils
- Jerry opened the key pairing, and after the first pairing TWS, it is difficult to pair successfully by cross pairing [article]
- R语言dplyr包summarise_at函数计算dataframe数据中多个数据列(通过向量指定)的计数个数、均值和中位数、使用list函数指定函数列表并指定自定义函数名称
- [MySQL learning notes 33] log
- 区分子类方法中的重名
- NVIDA CUDA-DirverAPI入门
- Matlab-mex
猜你喜欢
随机推荐
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、设置add参数为箱图添加分布数据点图(点阵图、dot plot)
2、Deep Learning in Higher Dimensions
Special topic of software R & D efficiency demand value stream analysis
MYSQL建表语句错误:1103-Incorrect table name
24. Exchange the nodes in the linked list in pairs
Qdu summer training - warm up match
ECCV 2022 | 多域长尾分布学习,不平衡域泛化问题研究(开源)
R语言使用lm函数构建回归模型、使用MASS包的boxcox函数寻找最佳幂变换提高模型拟合度、可视化boxcox曲线并获取最佳lambda值
es5和es6的区别
MQ系列2:消息中间件的技术选型
如何将notepad++设置为默认打开方式
不能不知道的分布式基础理论
Loj#576-「LibreOJ NOI Round #2」签到游戏【线段树】
Notes on linear algebra 2
Extrait d'un bon article
forEach、for in、for of三者区别
@EqualsAndHashCode注解的使用
G1这么强,你确定不了解一下?
线性代数 笔记2
Database daily question --- day 23: game play analysis L








