Differences between CMS and G1, advantages and disadvantages of cms and g1

1 year ago (2023-12-16) Chief Editor
4 minutes
two hundred and eighty-one
zero

Summary, advantages and disadvantages of CMS in four stages of garbage recycling G1 Collector characteristics G1 Four stages of garbage recycling When should you consider using G1G1 to set parameters

Four stages of CMS garbage recycling

Initial mark concurrent mark re mark concurrent cleanup

Initial marking stage: it will stop all threads, that is, Stop the World status

Concurrency marking stage: track all objects. This stage is the most time-consuming. However, this phase runs concurrently with the system, so it will not affect the system operation

Re marking stage: since the second stage is executed concurrently, the old object will become a garbage object when marking garbage objects and creating new objects. Therefore, the third phase will also enter the Stop the World state and be marked again. It marks a few objects that have changed in the second phase, so the running speed is very fast

Concurrent cleaning phase: this phase will also take a lot of time, but because it runs concurrently, it will not have a great impact on the system

Summary, advantages and disadvantages of CMS

CMS uses the mark clean algorithm to mark garbage objects and clear garbage objects. The algorithm is implemented based on the older generation, because the new generation cannot accept the fragment garbage generated by the algorithm.

Advantages: concurrent collection, low pause

Insufficient:

Floating garbage cannot be processed. Concurrent collection will cause too many memory fragments. Because the concurrent marking and concurrent cleaning phases are executed concurrently, additional CPU resources will be consumed

Features of G1 reclaimer

G1 is used to replace 1.5 CMS types of jdk9, which has been implemented in jdk9. By default, jdk9 uses G1 collector and removes all CMS related content. G1 has several characteristics compared with CMS:

Control the time of garbage collection: This is the advantage of G1. It can control the time of garbage collection. It can also establish a pause time model, select a group of appropriate regions as the collection goal, and achieve the goal of real-time collection. Space sorting: Like CMS, it uses the mark cleaning algorithm, but G1 does not produce space debris, so it effectively uses continuous space, It will not cause insufficient continuous space to trigger GC in advance

G1 divides Java memory into multiple equal parts and regions. Logically, there is the concept of the new generation and the old generation, but there is no strict distinction between them

Feel the texture:

The concept of the old age of the Cenozoic still exists, but there is no strict distinction. There are 2048 regions at most

Processing of large objects

In addition to the above advantages, there is another advantage, that is, the processing of large objects. In the CMS memory, if an object is too large, and it is larger than the allocated area when entering S1 and S2, the object will enter the old generation directly. G1 will judge whether an object is larger than 50% of the size of a region when processing large objects. If it is larger than 50%, it will be stored across multiple regions

G1 Four stages of garbage recycling

Initial mark concurrent mark final mark filter recycle

Initial mark: mark the objects that can be directly associated with GC Roots. This phase requires thread pause but takes a short time

Concurrency flag: search for surviving objects, which can be executed concurrently with other programs, taking a long time

Final marking: During concurrent marking, the user program will cause changes in the marking records (like an aunt cleaning up garbage while another person throws garbage). The virtual opportunity records the changes during this period in the Remembered Set Logs. The final marking stage will merge the changes in the concurrent marking stage into the Remembered Set. This phase requires thread pause, and can also be executed concurrently

Filter recovery: sort the recovery costs of each region, and formulate recovery plans according to user-defined recovery time

When should G1 be considered

Refer to official documents:

Real time data occupies more than half of the heap space. The speed of object allocation or promotion changes. It is highly desirable to eliminate long GC pauses (more than 0.5-1 seconds)

G1 setting parameters

Control the time of G1 recycling garbage

-20: MaxGCPauseMillis=200 (default 200ms)

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

Related recommendations

1 year ago (2024-02-20)

How does the WeChat management system manage enterprise WeChat chat content, and chat records of enterprise WeChat administrator permissions

Original title: How does the WeChat management system manage enterprise WeChat chat content How does the enterprise WeChat chat content manage enterprise WeChat chat content? Most WeChat chat content viewers on the market are for private viewing, but viewing WeChat chat content in enterprises is also particularly important. Without the use of WeChat management system, many behaviors such as abusing customers, flying orders, and randomly promising customers are
six hundred and sixty-four
zero
1 year ago (2024-02-20)

Liaocheng Chiping District Sub branch of Agricultural Development Bank of China carried out the second online exercise of the new generation credit management system, and how to do a good job in credit work as a member of Agricultural Development Bank of China

Recently, Chiping District Sub branch of Agricultural Development Bank of China actively implemented the second phase online exercise of the new generation credit management system. In accordance with the requirements of the overall exercise plan issued by the superior bank, it carefully deployed, carefully organized, clearly defined the division of labor, strengthened the coordination and linkage between various departments, closely cooperated, and effectively performed various work responsibilities during the exercise. Chiping District Sub branch organized all staff of the Customer Department to participate in the online drill
four hundred and ninety-one
zero
1 year ago (2024-02-18)

Content marketing is hard to do? Zhiqu Baichuan teaches you how to easily build a content management system, and what needs to be done well in content marketing

Two days ago, we received an official email "to Baichuan to remove from the salesforce app store" - because the United States issued an administrative order on August 6, 2020, prohibiting "any WeChat related transactions", which came into effect 45 days after the administrative order was issued (that is, September 20). The "one-stop marketing cloud" provided by Zhiqu Baichuan includes
three hundred and forty-three
zero
1 year ago (2024-02-18)

Why Enterprise Content Management System?, Why did you choose Business Management

As paper has almost disappeared, your company's important documents and information need to be digitized, stored and used in a way that supports processes and workflows. Through the enterprise content management (ECM) system, you can better manage enterprise content and choose a more interactive way to process the information of the entire enterprise. Do you check the internal documents, invoices, training materials, contracts, finance
two hundred and eighty-nine
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: