This is the 20th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

preface

We know that the heap memory collection area is divided into new generation and old generation. They all have their own garbage collectors, which can be combined. The combination is shown above.

Cenozoic collector

Serial collector (Serial collector -XX:+UseSerialGC)

The new generation and the old use serial recycling; New generation copy algorithm, old age tag – compression, Stop The World during garbage collection

ParNew collector (multithreaded version of Serial, new generation to parallel)

  1. -xx :+UseParNewGC: ParNew collector

  2. -xx :ParallelGCThreads: Limits the number of threads

Avenge (-xx :+UseParallelGC)

Adaptive tuning can be turned on with parameters that the virtual machine adjusts dynamically to provide the most appropriate pause times or throughput. The time of GC is controlled by parameters no more than milliseconds. New generation replication algorithm, old age marking – compression, old age serial

Old age collector

ParallelOld collector (-xx :+UseParallelOldGC)

Older ages use the mark-cleanup, Parallel, and Parallel Scavenge avenge to achieve throughput first

CMS(Concurrent MarkSweep) collector (-xx :+UseConcMarkSweepGC)

1. The target

A collector with the goal of obtaining the shortest recovery pause time attaches importance to server response speed and requires the shortest system pause time, based on mark-clear

Step 3.

Initial tag: Stop The World, marks only objects that GC Roots can be directly associated with, soon

Concurrent marking: The process of GC Roots Tracing

Relabeling: Stop The World fixes object markers that have been changed by user actions during concurrent marking

Concurrent cleanup: The collection thread executes concurrently with the user thread

3. The parameters

– XX: + UseCMSCompactAtFullCollection: after Full GC, a defragmentation; The collation process cannot be concurrent, resulting in longer pause times

– XX: + CMSFullGCsBeforeCompaction: set a few times after Full GC, a defragmentation

-xx :ParallelCMSThreads: Set the number of threads in a CMS (approximately equal to the number of available CPUS)

4. The advantages and disadvantages

Concurrency has low pauses, generates large amounts of space debris, and concurrency phases reduce throughput

Serial Old collector

An older version of the Serial collector, the single-threaded collector, uses a mark-collation algorithm

Global collector

G1 Collection (-xx :+UseG1GC)

  1. Spatial integration (based on mark-collation), predictable pauses (building predictable pause time models)
  2. The collector divides the Heap into multiple regions (2048) of the same size (1 to 32m), so that the Cenozoic and the old are no longer physically separated
  3. G1 tracks the value of garbage accumulation in each Region, maintains a priority list in the background, and collects garbage from the Region with the highest value according to the allowed collection time

ZGC (XX: + UseZGC)

  1. The pause time does not exceed 10ms. The pause time does not increase as the heap grows. 4T heap size is supported
  2. CMS and G1 mark objects in their object headers, while ZGC is a pointer to mark objects
  3. There is no concept of new generation and old generation in ZGC, only a piece of memory area page, in page units for object allocation and recycling
  4. The ZGC supports the NUMA architecture by default. When creating an object, it executes on the number of cpus in the current thread and allocates the memory closest to that CPU first