The third article: jvm garbage collector

 

 

 

1. Serial collector
The young generation collector must suspend all other worker threads during garbage collection. Namely Stop-The-World.
Evaluation: old and useless, tasteless to eat, a pity to abandon.

 

2. ParNew collector
The new generation collector, the serial multithreaded version.
The ParNew collector and serial are consistent in control parameters, collection algorithms, Stop The World, object allocation principles, and recycling strategies.
 
 

 

paramllel: Parallel, which means that multiple garbage collection threads work in parallel, but the user thread is still in the waiting state.
Concurrent: Concurrency, which means that the user thread is executed at the same time as the garbage collection, (but not necessarily in parallel, may be executed alternately) the user program continues to run, while the garbage collector program runs on another CPU.
3. Parallel Scavenge collector
aka "throughput first" collector
1. The collector's focus is to control empty throughput.
2. Throughput = time to run user code / (time to run user code + garbage collection time)
3. Control throughput parameters:
1) Maximum garbage collection pause time: -XX:MaxGCPauseMillis, the number of milliseconds greater than 0, GC pause time is in exchange for sacrificing throughput and new generation space.
2) Directly set the throughput size: -XX:GCTimeRatio, an integer greater than 0 and less than 100, that is, the ratio of garbage collection time to total time.
If this parameter is set to 19, the maximum allowed GC time is 5% of the total time (ie 1/(1+19)), and the default value is 99, which is the maximum allowed 1% (ie 1/(1+99 )) garbage collection time.
3) -XX:+UseAdaptiveSizePolicy (GC adaptive adjustment strategy GC Ergonomics): switch parameter, when this parameter is turned on, there is no need to manually specify the size of the new generation (-Xmn), the ratio of Eden to Survivor area (- XX: SurvivorRatio), the age of the object in the promotion old age (-XX: PretenureSizeThreshold) and other detailed parameters.
3. The difference between Parallel Scavenge and ParNew: Turn on the switch value, and then set -Xmx, MaxgcPauseMillis and GCTimeRatio, and other specific parameters are automatically adjusted by the virtual machine.
4. Serial Old collector
copy-mark algorithm
5. Parallel Old collector
Marking-collating algorithm, JDK1.6 began to provide,
Parallel Scavenge and Parallel Old are used in combination.

 

6. CMS collector
Concurrent Mark Sweep, Concurrent Low Pause Collector
CMS is a collector whose goal is to obtain the shortest collection pause time.
1. Collection process:
1) Initial mark CMS initial mark
Mark the objects that GC Roots can directly associate with, it is very fast, but it will still issue Stop The World.
2) Concurrent mark CMS concurrent mark
The concurrent marking phase is in the process of GC Roots Tracing
3) Re-mark CMS concurrent sweep
During the uncorrected concurrent marking period, the marking record of the part of the object whose marking is changed because the user program continues to operate. The pause time of this stage is generally slightly longer than the initial marking stage, but it is much shorter than the concurrent marking time.
4) Concurrency clear CMS concurrent sweep
2. 3 obvious disadvantages:
1) The CMS collector is very sensitive to CPU resources.
Default recycling thread: (CPU County Su+3)/4. When the server CPU has only 2 cores, the CMS collector may have a large impact on the application, and the running speed may be reduced by 50%.
CMS collector variant of "Incremental Concurrent Mark Sweep/i-CMS". Let the GC thread and the user thread run alternately during concurrent marking and clearing, and minimize the time that the GC thread monopolizes resources. The effect is general and has been abandoned.
2) CMS cannot handle Floating Gargage, and Concurrent Mode Failure may fail, resulting in another Full GC.
Floating garbage: CMS garbage collection is running, and the user's thread is also running and constantly generating garbage. This part of garbage appears after the marking process, and CMS cannot process them in the current collection. Just wait for the next GC to clear it. Part of the garbage becomes floating garbage.
The startup threshold of the JDK1.6 collector is 92%, that is, when the old generation uses 92%, the CMS collector will be activated. If the memory reserved during the running of the CMS cannot meet the needs of the program, Concurrent Mode Failure will occur. At this time, the virtual machine starts the preparatory plan: temporarily enable the Serial Old collector to perform the garbage collection of the old generation again, so that the pause time is longer.
If the growth rate is too fast in the coming years, you can adjust the parameters appropriately:
-XX: CMSInitiatingOccupancyFraction increases the penalty percentage. Of course, if the ratio of this parameter is too high, a large number of Concurrent Mode Failures will easily occur, and the performance will be reduced.
3) A large amount of space debris appears. When a large number of fragments are generated, there will be a lot of space in the old age, but there is still not enough continuous space to allocate the current object, and a Full GC has to be triggered in advance.
Seven, G1 collector
Features of G1:
1) Parallelism and Concurrency.
2) Generation collection.
3) Spatial integration. G1 is a collector based on the tag-collation algorithm as a whole, and based on a replication algorithm from a local (between two Regions) perspective.
4) Predictable pauses. The predictable residence time model of G1 resume allows users to clearly specify that within a time judgment of M milliseconds, the time spent on garbage collection does not exceed N milliseconds, which is almost a feature of real-time Java garbage collectors .
Divide the heap into multiple Regions, compatible with the concepts of old and new generations, not physical isolation but a collection of Regions (discontinuous)
G1 collector operation steps:
initial mark
concurrent marking
final mark
Screening for recycling

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324656789&siteId=291194637