当前位置:网站首页>New generation garbage collector ZGC

New generation garbage collector ZGC

2022-07-06 19:56:00 Chat with Lao Wang

Catalog

1、 What is? ZGC

2、ZGC Design purpose

3、ZGC present situation

4、ZGC Core technologies

4.1  Multiple mapping

4.2  Dye pointer

4.3 Reading barrier


1、 What is? ZGC

ZGC(The Z Garbage Collector) yes JDK 11 Launched in the pursuit of an ultimate low latency experimental garbage collector .

ZGC It was recently by Oracle by OpenJDK New open source garbage collector . It is mainly composed of Per Liden To write .ZGC Be similar to Shenandoah or Azul Of C4, Focus on reducing pause times while still compressing the heap .

2、ZGC Design purpose

ZGC The core of is a concurrent garbage collector , The goal of its design is :

1)  The pause time shall not exceed 10ms;

2)  The pause time doesn't vary with the size of the heap , Or the size of the active object ;

3)  The supported heap range is 8MB~4TB Level ( Future support 16TB).

All in all , ZGC The purpose of is to reduce the pause time at the same time , Can still compress the heap .

3、ZGC present situation

Up to date JDK15 Look at ,“ The pause time shall not exceed 10ms” and “ Support 16TB A pile of ” These two goals have been achieved , And the official made it clear that JDK15 Medium ZGC No longer an experimental garbage collector , And it is suggested to put into production .

4、ZGC Core technology of Technique

4.1  Multiple mapping

Let's first look at an interesting example .

You are a son in the eyes of your parents , In your girlfriend's eyes, it's a boyfriend . In front of people all over the world is the most handsome person . You have another name , But the name is just your code name , It's not you . If your name is the only one in the world , adopt “ What's your name ”、“ Your father's son ”、“ Your girlfriend's boyfriend ”,“ The most handsome man in the world ” It's all about you in the end .

Now let's see ZGC Memory management for .

ZGC The basic unit for managing physical memory in is segment.segment Default and small page size equally , All are 2MB. introduce segment To avoid frequent system calls to request and free memory , An application 2MB, When segment Idle , Will be added to the free list , Wait and reuse .

ZGC In order to be efficient 、 Flexible memory management , Two level memory management is realized : Virtual memory and physical memory , And the mapping between physical memory and virtual memory is realized . This is basically consistent with the design idea of virtual address and physical address in the operating system .

When an application creates an object , First, apply for a virtual address in heap space ,ZGC At the same time, for the object in Marked0、Marked1 and Remapped Each of the three view spaces applies for a virtual address , And these three virtual addresses correspond to the same physical address .

stay ZGC There is only one valid space among the three spaces at the same time .

Why is it so designed ?

This is it. ZGC The brilliance of , Use virtual space for time .

The switching of these three spaces is triggered by different stages of garbage collection , By limiting three spaces to have and only one space at the same time, it can be completed effectively and efficiently GC Concurrent operation of process , This and ZGC Concurrent processing algorithm is related .ZGC The concurrent processing algorithm makes use of the switch between global spatial view and object address view , combination SATB The algorithm achieves efficient concurrency .

4.2  Dye pointer

We all know , Previous garbage collectors used to put GC Information ( Tag information 、GC Generational age ..) There is an object header Mark Word in .

and ZGC Here's how it works :

If an object is a garbage object . Mark this object as garbage in the information of this object . No matter where this object is used in the future , We all know that he is a garbage object .

ZGC Store the object information in the pointer , This technology is called —— Dye pointer (Colored Pointer).

stay 64 In a bit machine , The object pointer is 64 Bit .

ZGC Use 64 Bit address space 0~43 Bit storage object address ,2^44 = 16TB, therefore ZGC The biggest support 16TB A pile of .

And the first 44~47 Bit as a color marker bit ,Marked0、Marked1 and Remapped Represents three view flags ,Finalizable Indicates that this object can only be accessed through finalizer Ability to visit .

The first 48~63 The bit is fixed to 0 There is no use .

4.3 Reading barrier

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 . Don't compare this barrier with Java The read barrier in the memory model is confused , The two are not the same thing at all ,ZGC The reading barrier is more like AOP technology , Add an extra processing to the read operation at the bytecode level or at the compile code level .

ZGC As an excellent garbage collector , It draws on Pauseless GC, But in G1 It's not popular today , talk about ZGC It seems too early . But maybe we're not talking about ZGC, It is ZGC The design idea behind it .

Official account + Input [ Interview questions ] + Get the interview materials free of charge ( Interview outline + Interview answers )!  

原网站

版权声明
本文为[Chat with Lao Wang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061154024777.html