Java / Java 17 Garbage Collection Interview Questions
When should you choose Shenandoah over G1 GC?
Shenandoah targets the same goal as ZGC - pause times that don't scale with heap size - but reaches it through a different mechanism: concurrent compaction using per-object forwarding (Brooks) pointers rather than colored pointers and load barriers on every reference read.
It's a strong choice when you need ZGC-like low, heap-size-independent pauses but are on a build or platform where Shenandoah is the more mature or better-supported option for your JDK distribution, or when you want to compare its indirection-based approach against ZGC's barrier-based approach empirically for your specific allocation pattern.
As with ZGC, the concurrency comes at a cost: extra memory per object for the forwarding pointer and CPU overhead from the read/write barriers needed to keep mutators and the collector consistent during concurrent evacuation, so high-throughput batch workloads without strict latency needs may still be better served by G1 or Parallel GC.
More Related questions...