Z Garbage Collector (ZGC)
Z Garbage Collector (ZGC) is one of Java 11's excellent features. The Z Garbage Collector, or ZGC, is a low latency scalable garbage collector intended to accomplish the following objectives.
- Pause times must not take more than 10 milliseconds.
- Manage heaps varying in size from a few hundred megabytes to multiple terabytes.
- The size of the heap or survive has no effect on pause times.
- Concurrent
- Region-based
- Compacting
- NUMA-aware
- Using colored pointers
- Using load barriers
In order to understand how ZGC fits into existing Garbage Collector, will first touch base the Garbage Collector Concepts.
ZGC uses two new techniques for Hotspot Garbage Collectors to achieve its goals: colored pointers and load barriers.
-
Pointer colouring
Pointer colouring is a technique which store metadata in unused bits of reference address.
It needs 42 bits for addressing (4TB).
4 bits for metadata as shown in below diagram.- Marked0
- Marked1
- Remapped
- Finalizable
- Multi-mapping : The operating system is responsible for maintaining mappings between virtual memory and physical memory, using a page table and the Memory Management Unit (MMU) and Translation Lookaside Buffer (TLB) of the processor, which translates the addresses needed by applications.
-
Load barriers
Load barriers are code that run when application thread loads a reference from the heap (i.e accesses a non-primitive field on an object)void getEmployee( Employee emp ) { String emp_name = emp.name; // would trigger the load barrier because we have loaded a reference from the heap System.out.println(emp_name); // no load barrier directly }