当前位置:网站首页>Main stages of garbage collection in ZGC

Main stages of garbage collection in ZGC

2022-06-12 21:17:00 lixia0417mul2

zgc At present, it is collected by the whole heap , There are no generations , So it's saved Rset Memory consumption of cross generational record references ,zgc The whole gc The process is mainly divided into the following stages :
1. Initial identification (stw): Identify the root object in the heap , The root object mainly includes the thread stack , Global variables, etc

2. Concurrent identification : Starting from the root of the first stage , Concurrency identifies other objects reachable from the root object , Run concurrently with the application , The identification algorithm uses the three color method to mark objects , See the previous article for the principle of three color method to identify objects

3. Re identify (stw): This phase is mainly to re identify the missing identification of objects caused by the concurrent running of threads in the parallel phase .

4. Non strong root reference processing : Processing at this stage Finalizer quote , Virtual reference , Objects such as weak references and ghost references

5. Reset transfer set + Recycle invalid pages : Because of the last round of zgc in , Some objects have been moved to new pages , But the address actually referenced in the object is still the old address ( Because after the last round of object migration , These objects have never been accessed , The read barrier has not been triggered to change to a new address 【 However, the number of such objects should not be large 】), After the previous identification phase , The actual reference address of these objects has been changed to the new address , In this way, the transfer table can be reset safely ( Because the values referenced by all objects are new address values ), After resetting the transfer table , Because the transfer table is on the old page , At this time, you can also recycle the old pages by the way

6. Select the page to be recycled ( step 1) : This stage will recycle those pages that are full of garbage objects , Note that this stage is in zgc Is executed concurrently , Corresponding to g1 Initial cleanup Stage , however g1 Initial cleanup Stage is stw Of , Do more than this zgc At this stage of , such as g1 Initial cleanup Stage + Concurrent cleanup also sorts pages according to the amount of garbage on the page , For the subsequent mixed gc Make a plan

7. Select the page to be recycled ( step 2): This stage will sort according to the proportion of garbage size in each page , And select those whose garbage proportion is greater than the threshold ( Configurable ZFramentLimit) The page of enters the garbage collection candidate set

8. Initial transfer stw: This phase will shift root Object to the new page address , Corresponding to G1 in evacuation Part of the stage , But with the g1 evacuation The whole stage is stw Different ,zgc Only the initial transfer root Stage is stw Of

9. Concurrent transfers :zgc Transfer the remaining non root Objects are executed concurrently with the application , This stage corresponds to G1 Medium Evacuation pause Stage (ygc perhaps mixed gc Transfer phase of ), Be careful g1 Medium Evacuation Stage is stw Of

原网站

版权声明
本文为[lixia0417mul2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206122116177884.html