In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the use of the G1 collector in JVM, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
First, take a look at the memory model of the G1 collector.
First, although the GI collector is also a generational collector, it is quite different from other collectors in memory structure, from which we can see that G1 is a physical partition and a logical generation, and G1 does not need to be copied by survivorTo.
Second, G1 has a Humongous area, which is an area for storing giant objects. When an area is accounted for more than half, there will be no room for one area. At this time, multiple consecutive partitions are needed. It is very difficult to find a continuous memory interval. If there is not enough memory, it may result in Full GC.
First, let's talk about the shortcomings of CMS:
1. As a result of concurrency, CMS will increase the consumption of heap memory in both collection and application threads, that is, CMS must complete garbage collection before the old heap memory is exhausted, otherwise, when CMS collection fails, the guarantee mechanism will be triggered, and the serial old age collector will perform a GC in the way of STW (Stop-the-world), resulting in a larger pause time.
In G1, the design principle is "collect as much garbage as possible (Garbage First) first". G1 will give priority to areas with a high percentage of garbage, rather than waiting for memory to run out, but when the G1 collector is very busy, memory overflow will also trigger a guarantee mechanism, which is to use the serial old collector for a Full GC.
two。 The tag removal algorithm can not defragment the space, and the old space will be gradually exhausted with the application time, and finally the heap memory will have to be compressed through the guarantee mechanism. CMS also provides the parameter-XX:CMSFullGCsBeForeCompaction (default 0, which is demarcated each time) to specify how many CMS collections are followed by a compressed FullGC.
G1 does not produce memory fragmentation and uses flag destructing algorithm.
Let's take a look at the collection process of G1:
Initial tag: marks objects that are directly reachable from the root node. This phase is accompanied by a new generation of GC, which produces a global pause at which the application must stop execution.
Root zone scan: since the initial tag is bound to be accompanied by a new generation of GC, after initializing the tag, the eden is cleared and the surviving object is moved to the survivor area. At this stage, older areas directly reachable from the survivor area are scanned and these directly reachable objects are marked. This process can be performed concurrently with the application. However, root zone scanning cannot occur at the same time as the new generation GC (because the root zone scan depends on the objects in the survivor zone, and the new generation GC will modify this area), so if you happen to need the new generation GC,GC at this time, you need to wait for the end of the root zone scan. If this happens, the time of this new generation GC will be extended.
Concurrent tags: similar to CMS, concurrent tags will scan and find surviving objects throughout the heap and mark them. This is a concurrent process, and it can be interrupted by a new generation of GC.
Relabeling: like CMS, relabeling can bring the application to a standstill, and since the application is still running during the concurrent tagging process, the tagging results may need to be corrected, so the previous markup is supplemented at this stage. In G1, this process is done using the SATB (Snapshot-At-The-Begining) algorithm, which means that G1 creates a snapshot of the living object at the beginning of the tag, which helps speed up the relabeling.
Exclusive cleanup: as the name implies, this phase can cause a pause. It will calculate and sort the proportion of surviving objects and GC recycling in each region to identify the areas that can be mixed for recycling. At this stage, the memory set is also updated. In this stage, the areas that need to be mixed and recycled are given and marked, and this information is needed in the mixed recycling phase.
Concurrency cleanup phase: identify and clean up completely idle areas. It is a concurrent cleanup and does not cause a pause.
Tricolor mark
When it comes to concurrent tags, we have to understand the tricolor marking algorithm for concurrent tags. It is a useful method to describe the traceable collector, and it can be used to deduce the correctness of the collector.
First, we divide objects into three types:
Black: follow the object or the object and its children are scanned (marked complete).
Gray: the object itself is marked complete, but the child objects in the object have not been scanned yet
White: objects that are not scanned. Or after the scan is completed, the final white object is unreachable, that is, the junk object.
Thank you for reading this article carefully. I hope the article "what is the use of G1 Collector in JVM" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.