What is the difference between the G1 of Java 8 and the previous CMS?

1 year ago (2024-01-12) Chief Editor
5 minutes
two hundred and twenty-two
zero

The full name of the CMS CMS garbage collector is Concurrent Mark Sweep. From the name, we can also see that the garbage collector is implemented based on the mark clearing algorithm. First, "Concurrency" means that the GC thread can execute concurrently with the user thread. At the same time, since it is a mark and clear algorithm, it means that this garbage collector will generate many fragments, which is the disadvantage of the mark and clear algorithm. At the same time, CMS works in the old age, and the garbage collection frequency of the old age is lower than that of the young generation. CMS garbage collection has four process initialization marks: concurrency mark: re mark: concurrent clear: when the initial mark is made, it is a STW (stop the world) process, and all user threads will stop. At this time, it just marks the objects that GC Roots can directly reach. Because it is only marking one layer, the overall speed will be relatively fast. The concurrent mark is a GC Roots scanning process, which scans the objects that can be recycled for the entire link mark; Because the entire link will be long, it will take a little longer. However, because this process is concurrent, it has no impact on the operation of user threads. Just as the name implies, remarking is a process of remarking and also a process of STW. The reason for this process is that the user thread is still running in the process of concurrent marking in the previous step, so the reference relationship of objects will change and new garbage will be generated when running. Only objects that have changed in the previous step will be marked here. Although STW is possible, it is also fast. Concurrent cleanup is the last stage. This stage is relatively time-consuming because it needs to clear all garbage objects scanned before. However, this stage can be performed concurrently, so it will not affect the operation of user threads. After the above four processes, a complete GC is completed. As we mentioned earlier, the entire CMS garbage collector is based on the mark and clear algorithm. First, mark the objects to be cleaned through three processes, and then clean them. The initial marking and re marking will trigger STW in the whole process, and the other two stages are carried out concurrently. The mark and clear algorithm will generate memory fragments, so it is not suitable for the young generation that needs frequent recycling, so it is only suitable for the old age. Fragmentation is the disadvantage of CMS, and concurrency is the advantage of CMS. After all, any collector has advantages and disadvantages. Before G1, we finished talking about CMS. Next, we will talk about G1. The full name of G1 is Garbage First. Before we talk about the details of G1 garbage collector, the first thing we need to know is that G1 redefines the entire heap space. The old and young generations in G1 are no longer physically isolated, but logically isolated. In G1, the entire heap space is divided into region blocks of the same size, and multiple region blocks logically form the young generation and the old generation. This is because it is not necessary to scan the entire heap space during garbage collection, and garbage collection can be performed according to the specified pause time. G1 will quantify the recovery cost of each region to achieve a cost control. Recovery can be completed within a limited pause time, which is the biggest feature of G1. G1 recovery is also divided into four processes: initial marking: initial marking and CMS are also only scanning the objects directly reached by GC Roots. This stage also requires STW, but the time is also very short; Concurrency flag: start from GC Roots to analyze the accessibility of objects in the heap and find the surviving objects. This phase takes a long time, but it can be executed concurrently with the user program; Final marking: The idea of final marking and CMS re marking has always been to correct the part of objects whose marking changes due to the concurrent running of user programs during the concurrent marking period, but the difference is that G1 will record the object changes during this period in the thread Remembered Set Logs, In the final marking stage, the data of the Remembered Set Logs needs to be merged into the Remembered Set. In this stage, the thread needs to be paused, but it can be executed in parallel; Filtering and recycling: the last step is the biggest difference between G1 and CMS. G1 first quantifies and sorts the costs of each region to be recycled, and then formulates a recycling plan based on the expected GC pause time. The expected recycling time is specified by the - XX: MaxGCPauseMillis parameter. This phase can also be executed concurrently with the user program, but because only a part of the region is recycled, the time is controllable by the user, and pausing the user thread will greatly improve the collection efficiency. A Remembered Set memory set mentioned above is used to record object references. It will be recorded here when there are changes in object references during concurrent marking, and will be corrected when the final marking is made. On the whole, G1 uses the tag collation algorithm for garbage collection, and does not generate content fragments like CMS does. Therefore, G1 can perform garbage collection for young and old generations at the same time. Compared with CMS, G1 is more flexible, and because G1 divides memory into regions, it will not cause the problem of space waste caused by the replication algorithm. First of all, CMS and G1 are both concurrent and generational garbage collectors with low latency; CMS is based on the mark and clear algorithm. It is only suitable for the young generation, with unpredictable pause time. At the same time, the young generation and the old generation are physically isolated. G1 is a mark and sort based garbage collector with high throughput and predictable pause time. It can be used in the young generation and the old generation at the same time. At the same time, the young generation and the old generation are logically isolated.

Transferred from the official account: Java geek technology

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/3767.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What are the main contents of wms system in warehouse management

Original title: What does the wms system mainly embody in warehouse management? What does the wms system mainly embody in warehouse management? Warehouse management has standardized and intelligent process oriented management. A good warehouse management mechanism can improve the efficiency of warehouse managers, relieve their pressure, and complete efficient and accurate work. 1. Warehouse management is accompanied by the progress of the times
1 year ago (2024-02-18)

How to implement the mptt comment function of CMS content management system in Django?, Django management page

During the daily development of content related Web systems in the directory, whether it is Blog or CMS, if you need to add links to interact with users, you must need the comment function. Next, you can implement the comment reply function in Django based on Python's MPTT framework. Note: Because the user comment function will involve a
three hundred and ninety-four
zero
1 year ago (2024-02-18)

Best CMS content management system in 2022, good novel in 2021

Looking for the best CMS software to build your website? At a high level, CMS or content management systems can help you create functional websites without having to use code to build every page from scratch. However, different CMS software has different advantages and disadvantages, so you need to choose the tool that best suits your specific needs and budget. To help, we accept
four hundred and six
zero
1 year ago (2024-02-18)

Shenzhen promotes the access of 5G base station energy storage system to the virtual power plant management center in the city. Does the Shenzhen 5g government subsidize the flow package charge

Xinhua News Agency, Shenzhen, December 14 (Reporter Wang Feng) At the 2022 Carbon Peak Carbon Neutralization Forum and Shenzhen International Low Carbon City Forum held here in Shenzhen, Shenzhen Virtual Power Plant Management Center signed a cooperation agreement on virtual power plant construction with China Tower, China Telecom, China Mobile, China Unicom, Huawei Digital Energy and other units on the 13th, which will jointly promote the city's 5G base station energy storage system
three hundred and forty-three
zero
1 year ago (2024-02-18)

Common website cms content management system recommendation, common website cms content management software

CMS is the abbreviation of "Content Management System", which means "Content Management System" in Chinese. These systems have developed common website functions and provided them to users for download, greatly improving the efficiency of website construction. The most common functions of CMS are column management, article management, product management, picture management
three hundred and twenty-eight
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: