This is the 9th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Classic garbage collector

Serial collector

  • The collector is a single-threaded collector, but “single-threaded” means more than just that it uses only one processor or one collection thread to complete the garbage collection.
  • It is more important to emphasize that while it is garbage collecting, all other worker threads must be suspended until it finishes collecting.

ParNew collector

  • The ParNew collector is essentially a multi-threaded parallel version of the Serial collector

== Concurrency and parallelism in the collector ==

  • Parallel: Parallel 􏰀 refers toRelationships between multiple garbage collector threads
  • Note Multiple threads are working together at the same time. By default, the user thread is in the waiting state.
  • Concurrent: Concurrent 􏰀 refers toThe relationship between the garbage collector thread and the user thread
  • Both the garbage collector thread and the user thread are running at the same time. Since the user thread is not frozen, the application can still respond to the service request, but because the garbage collector thread consumes some of the system resources, the throughput of the application processing will suffer.

Parallel Scavenge

  • A mark-copy algorithm based collector is also a multithreaded collector that can collect in parallel
  • Two parameters are provided to precisely control throughput, the -xx :MaxGCPauseMillis parameter that controls the maximum garbage collection pause time
  • And directly set the throughput size of -xx :GCTimeRatio parameter.

Serial Old collector

  • Serial Old is an Old version of the Serial collector,
  • It is also a single-threaded collector, using the mark-collation algorithm

Parallel Old collector

  • Parallel Old is an Old version of the Parallel Scavenge
  • Support multi-threaded concurrent collection, based on the tag – collation algorithm.


CMS

  • A collector whose goal is to obtain the shortest collection pause time

== Four steps ==

  1. CMS Initial Mark
  2. CM S Concurrent Mark
  3. (CM S remark)
  4. CMS Concurrent Sweep

= = = =

  • Concurrent collection, low pause

= = = = shortcomings

  • It does not cause user threads to stall, but it can slow the application by taking up some of the threads, reducing overall throughput
  • User threads continue to run during the concurrent markup and concurrent cleanup phases of the CMS,
  • While the program is running, new garbage objects will be generated, but this part of the garbage objects will appear after the end of the marking process.
  • CMS is unable to dispose of them in this collection and has to clean them up for the next garbage collection. This part of the garbage is called “floating garbage.”

Garbage First

  • followGenerational collectionThe region-based heap memory layout pioneered is key to its ability to achieve this goal
  • Initial Marking: Simply Marking the objects that GC Roots can directly relate to and changing the value of the TAMS pointer so that the next phase, when user threads are running concurrently, can properly allocate new objects in available regions. This phase involves pausing threads, but it takes a short time and is synchronized from Minor GC, so the G1 collector does not actually have any additional pauses during this phase.
  • Concurrent Marking: Start with GC Root to analyze the reactability of objects in the heap, recursively scan 􏰁 the whole heap object graph to find the objects to be collected, this phase takes a long time, but can be executed concurrently with the user program. When the object graph scan 􏰁 is completed, the concurrent objects recorded by SATB should be reprocessed
  • Final Marking: Another short pause on the user thread to process the last few SATB records that remain after the concurrent phase has ended.
  • Live Data Counting and Evacuation (Counting and Evacuation): Updates statistical Data of regions, sorts the value and cost of each Region, and works out a collection plan based on the expected pause time. You can select any number of regions to collect, copy the remaining objects of the Region to an empty Region, and then clear up all the space of the old Region. The operation here involves the movement of the living objects, which must be paused by the user thread, and is done in parallel by multiple collector threads.