7 Things About JVM ZGC (Z Garbage Collection)
- What:
- Since Java 11 (Linux/x64), macOS/Windows: Java 14.
- Goals:
- Max pause times (1) of a few milliseconds.
- Pause times do not increase with the heap or live-set (2) size.
- Handle heaps ranging from a 8MB to 16TB in size.
- Features:
- Concurrent
- Region-based (3)
- Compacting (4)
- NUMA-aware (5)
- Using colored pointers (6)
- Using load barriers (7)
- When:
- You meet the java version / platform conditions.
- Notes:
-
Pause time The pause time is the duration during which the garbage collector
stops the application and recovers space that is no longer in use. -
The live set It’s the amount of Java heap that is used after an Old Collection (all objects that are not live have been garbage collected).
-
Region-based It’s a type of memory management in which each allocated object is assigned to a region. A region, also called a zone, arena, area, or memory context, is a collection of allocated objects that can be efficiently deallocated all at once.
-
Compacting Compaction means moving objects in RAM so that some objects are removed (the dead objects, that the GC is supposed to reclaim) and all remaining objects become contiguous in RAM.
-
NUMA Non-uniform memory access (NUMA): is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory
-
Colored pointers It’s the core concepts of ZGC. It enables ZGC to find, mark, locate, and remap the objects. It doesn’t support x32 platforms.
-
Load barrier Applied when loading an object reference from the heap, prevents contention between the GC phase and any application’s activity.
- Examples:
- Use the -XX:+UnlockExperimentalVMOptions -XX:+UseZGC for the Java options to enable ZGC.
- References:
http://cr.openjdk.java.net/~pliden/slides/ZGC-FOSDEM-2018.pdf https://wiki.openjdk.java.net/display/zgc/Main https://stackoverflow.com/questions/33803788/java-garbage-collection-fine-tuning-maximum-pause-time-goal https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks001.html https://en.m.wikipedia.org/wiki/Region-based_memory_management https://en.m.wikipedia.org/wiki/Non-uniform_memory_access http://docs.adaptivecomputing.com/torque/6-0-0/Content/topics/torque/11-Using%20NUMA/NUMAawareTorque.htm#about https://subscription.packtpub.com/book/application_development/9781789133271/8/ch08lvl1sec45/colored-pointers https://stackoverflow.com/questions/2663292/how-does-heap-compaction-work-quickly https://www.baeldung.com/jvm-zgc-garbage-collector