CMS and G1 garbage collector

  • CMS collector

CMS (Concurrent Map Sweep) collector is a pause in the shortest recovery time objectives collector, typically used on JavaWeb program, attention to service response speed, we want the system to pause the shortest time, but it is based on the "mark - sweep" algorithm .

The whole process is divided into four steps:

      • The initial mark

Just mark what objects can be linked directly to the GC Roots, very fast.

      • Concurrent mark

Is the process of GC RootsTracing

      • Relabel

Mark them that part of the object because the user program continues to operate during the correction concurrent mark which led to marked changes generated, dwell time at this stage is usually longer than the initial phase of some marked, but short of time than the concurrent mark.

      • Concurrent Clear

Clear labeling

Since the whole process takes the longest concurrent mark and clear process of collecting concurrent threads can work together with the user thread, on the whole, the memory recovery process CMS collector is a user concurrently executing threads together.

But it is also a drawback:

      • CMS collector is very sensitive to CPU resources. In a concurrent stage, although it does not lead to the user thread pause, but because of the occupation of a part of the threads (or CPU resources)
      • CMS collector can not handle floating garbage. As the clean-up phase of CMS concurrent user thread is still running, with the program running naturally there will continue to generate new garbage, garbage appear after this part of the marking process, CMS can not dispose of them at times when the collection had to wait until the next time GC again when cleared away.
      • CMS collector is based on the "mark - Clear the" collector's algorithm. There will be plenty of space debris at the end of the collection. When too much space debris, will bring great trouble to the large object allocation, there will always be a lot of room remaining years old, but can not find a large enough contiguous space to allocate the current object, we have been forced to start again FullGC.
  • G1 collector
      • Parallel and Concurrent

G1 can fully advantage of the hardware in a multi-CPU, multi-core environment, the use of multiple CPU to shorten the Stop-The-World's pause time, some of the other collectors would otherwise require GC pause action Java thread execution, G1 collector can still be complicated by the way to make Java program continues.

      • Generational collection

Generational concept phone still preserved in G1.

      • Spatial integration

On the whole G1 is based on the "mark - finishing" collector algorithm from the local (between two Region) point of view it is based on the "copy" of the algorithm. Can be guaranteed not to produce memory space debris during operation of the G1, the collection offers regular memory available.

      • Predictable pause

G1 may establish the prediction model dwell time, it allows users to explicitly specify a length of time segments M msec, the time consumed in the garbage collection can not exceed N milliseconds.

G1 entire Java heap is divided into separate areas (Region) a plurality of equal size, although they retain the new generation of old age concept, but the new generation and the old year is no longer physically separated, and they are part of the Region (not require continuous) collection.

G1 collector model has been able to establish a predictable pause time, because it can be planned to avoid heap garbage collection across the region throughout Java. G1 track individual Region inside the garbage accumulation value size (experience of space and time to recover obtained recovery required), in the background to maintain a priority list, according to each collection time allowed, the maximum recovery value of priority Region (this is Garbage-First name of reason).

G1 collector operation can be divided into the following steps:

      • The initial mark

Just mark what the object GC Roots can be directly linked to, and modify the value of TAMS (Next Top at Mark Start), so that the next phase of the user program to run concurrently, can create new objects in the correct available Region, this stage requires pause thread, but it takes very short.

      • Concurrent mark

Began to heap objects from GC Root reachability analysis to identify live objects, this stage takes a long time, but may be complicated by the user program execution.

      • The final mark

Remembered Set Logs to merge data into Remembered Set, which need to pause the thread stage, but can be executed in parallel.

      • Filter Recycling

First, the recovery value and the cost of each Region of sorts, to develop recycling programs desired by the user according to GC pauses.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zty-lyq/p/11494309.html