GC Algorithm
Parallel GC
Applied as the default GC in Java 8
Performs minor collection in
parallelCan significantly reduce GC overhead
A GC designed for applications that handle
medium to large-scale datasetsrunning on multi-processor or multi-thread hardwareParallel CompactionA feature that allows the Parallel Collector to perform major collection in
parallelWhen the
-XX:+UseParallelGCoption is specified, Parallel Compaction is used by default
However, the use of multi-threaded collection is limited to the
Younggeneration onlyYoung Generation Collection algorithm:
Parallel ScavengeOld Generation Collection algorithm:
Serial Mark-Sweep-Compact
G1 (Garbage First Collector)
Applied as the default GC in Java 11
A Collector designed for multi-processor machines with large memory
The G1 Collector can be enabled with the
-XX:+UseG1GCoptionNote that G1 GC is the only one that is not a Generational GC
The G1 collector is a unique collector that does not divide the heap into Young and Old regions
G1 eliminates the physical generation distinction and treats the entire heap as 1MB-sized regions
It is organized in a
grid patternand uses approximately2000 regions
The name G1 means that collection starts from the region most filled with garbage
When a region full of garbage is found, the collector runs immediately
Live objects in Old regions are moved to other Old regions, and compaction occurs
In G1, the concepts of Young and Old generations are
not fixedThe set of regions where objects are
newly allocatedis theYounggenerationThe set of regions where
promotionoccurs is theOldgeneration
ZGC
Applied as the default GC in Java 17
ZGC is a scalable low-latency GC that can handle heaps ranging from 8MB to 16TB in size, and can be enabled using the -XX:+UseZGC option
Low-latencyZGC increases responsiveness by minimizing pauses for memory collection
It is a concurrent GC where application threads continue to run during collection operations, and pause times are very short
This allows maintaining high responsiveness even in large-scale memory environments
Maximum latency is less than 1 millisecond
Very Large Heap SupportZGC can handle heaps as large as 16TB
This makes it suitable for applications that perform large-scale data processing or memory-intensive tasks
Non-contiguous CollectionInstead of collecting the entire heap at once, ZGC divides it into small region units and performs garbage collection
By processing only portions of the collection work, it can distribute pause times
Parallel ProcessingZGC utilizes multi-threads to process GC operations in parallel
This efficiently distributes GC operations and reduces overall collection time
EfficiencyIt is efficient because there is no need to clean up the heap during collection
Typical GCs trigger
stop-the-worldevents to perform memory collection operationsDuring this time, all application threads are paused for GC operations
These pause times can affect application responsiveness and performance
In contrast, ZGC maintains very short pause times during the heap cleanup process
ZGC continues to run application threads during collection operations and only triggers very short pauses when necessary
ZGC focuses on increasing application responsiveness by minimizing pause times
Last updated