HardExperience level: 8-15 years1 min read

How do ZGC and Shenandoah achieve sub-millisecond pauses on huge heaps?

Reviewed by Gurusankar M.

Asked inGoogleAmazonMicrosoft
#zgc#shenandoah#concurrent gc#colored pointers#load barriers
Report issue

Short Answer

They do nearly all GC work — marking, relocation/compaction — concurrently with the application, using load/read barriers (and ZGC's colored pointers) so objects can move while threads run. Pause times stay sub-millisecond and roughly independent of heap size, at the cost of extra CPU/barrier overhead.

On this page

Concept Made Simple

Coffee Chat Question

“How do ZGC and Shenandoah achieve sub-millisecond pauses on huge heaps?”

Remember It Faster

Mind Map Answer

Concurrent
mark + relocate while app runs
Barriers
load/read barriers fix up references
ZGC
colored pointers track relocation state
Trade-off
low pause, higher CPU/barrier cost

Think Beyond the Expected

What If?

Why are ZGC's pauses 'independent of heap size' while G1's grow with it?

G1 still does significant STW work proportional to live data in a collection. ZGC moves marking and relocation into concurrent phases, leaving only tiny fixed STW operations (like root scanning), so a 16 GB and a 16 TB heap have similar (sub-ms) pauses.

Real World

Latency-critical, large-heap systems (real-time bidding, big caches) adopt ZGC for predictable tail latency, accepting some throughput/CPU cost; it's production-ready and non-experimental in recent JDKs.

Interviewer's Expectation

Keywords they're listening for:

  • concurrent mark + relocate
  • load/read barriers
  • colored pointers (ZGC)
  • pause independent of heap
  • CPU/throughput trade-off

Common Mistakes

  • Assuming ZGC is free (it costs CPU/throughput)
  • Using it for small heaps where G1 is simpler
  • Expecting zero pauses (it's sub-ms, not none)

Best Practices

  • Use ZGC/Shenandoah for large-heap low-latency needs
  • Benchmark throughput cost before adopting
  • Keep G1 for general workloads

Follow-up Questions

  1. What are colored pointers and load barriers?
  2. What does ZGC trade away for low pauses?
  3. When is G1 still the better choice?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Garbage Collection (JVM)
Interview question: "How do ZGC and Shenandoah achieve sub-millisecond pauses on huge heaps?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.