Question 9 · Section 3

What is Young Generation?

4. Eden is cleared

Language versions: English Russian Ukrainian

Junior Level

Young Generation — Heap area where all new objects are allocated.

Why a separate Young Gen: ~90-98% of objects die quickly. A copying collector is efficient for this pattern: copy only live objects (2%), dead ones are simply ignored.

Simple analogy: “Kindergarten” for objects. Most objects “die” here very quickly.

Structure:

  • Eden — where new objects are created
  • Survivor 0 and Survivor 1 — where survivors go after GC

Minor GC (young generation collection):

  1. Eden is full → GC is triggered
  2. Dead objects are removed
  3. Live objects are copied to Survivor
  4. Eden is cleared

Why it’s fast: 98% of objects are dead → only 2% are copied


Middle Level

Allocation: TLAB

Each thread → its own TLAB in Eden
  TLAB = 64 KB of exclusive memory

Allocation:
  pointer += object_size  // Bump-the-pointer
  → Faster than malloc() in C++!

Lifecycle

new Object() → Eden
  ↓ Minor GC
Survivor (age +1)
  ↓ Minor GC (age +1)
Survivor (age +2)
  ↓ ... (until age = 15)
Old Generation

Premature Promotion

Problem: Survivor overflow
  → Objects pushed to Old Gen
  → Old Gen fills with garbage
  → Full GC!

Solution: increase SurvivorRatio or Young Gen

Tuning

-Xmn2g                     # Fixed Young Gen
-XX:SurvivorRatio=8        # Eden:Survivor = 8:1
-XX:MaxTenuringThreshold=15  # Age before Old Gen

Senior Level

PLAB (Promotion Local Allocation Buffer)

During Minor GC: survivors copied to Survivor/Old
  → PLAB = TLAB for copying
  → Each GC thread has its own PLAB
  → Avoids contention during evacuation

PLAB (Promotion Local Allocation Buffer) — analog of TLAB for Old Gen.
Thread copies objects from Survivor to Old Gen via its private buffer,
without synchronization.

G1 Humongous Regions

Object > 50% of region → Humongous
  → Directly to Old Gen (not Eden!)
  → Not copied in Minor GC
  → Saves resources on useless copying

Humongous Regions — G1 regions for objects > 50% of region size.
Allocated directly in Old Gen.

PrintTenuringDistribution

-XX:+PrintTenuringDistribution

# Output:
 Desired survivor size: 10 MB
 Age 1: 5000 objects, 40000 bytes
 Age 2: 2000 objects, 16000 bytes
 ...
 Age 15: 100 objects, 800 bytes

→ Helps tune MaxTenuringThreshold

Best Practices

  1. TLAB — allocation is almost free
  2. Avoid Premature Promotion
  3. G1 Humongous → increase G1HeapRegionSize
  4. For G1: do not fix -Xmn — G1 adaptively changes Young Gen size. For Serial/Parallel GC, fixing -Xmn may be useful.
  5. Monitor tenuring distribution

Senior Summary

  • Young Gen = copying collector, O(live objects)
  • TLAB/PLAB = lock-free allocation/evacuation
  • Premature Promotion = main enemy of performance
  • Humongous Objects = directly to Old Gen
  • G1 adaptively changes Young Gen size

Interview Cheat Sheet

Must know:

  • Young Gen = Eden (80%) + Survivor S0 (10%) + Survivor S1 (10%)
  • All new objects created in Eden; Minor GC copies live to Survivor, Eden cleared
  • TLAB (Thread Local Allocation Buffer) — thread-private buffer in Eden, allocation = pointer bumping (0 synchronization)
  • PLAB (Promotion Local Allocation Buffer) — analog of TLAB for Old Gen during survivor evacuation
  • MaxTenuringThreshold = 15 (default); object goes to Old Gen after 15 collections
  • Premature Promotion: Survivor overflows → objects pushed to Old Gen → Full GC
  • Humongous Objects (G1): object > 50% of region → directly to Old Gen, not copied in Minor GC

Common follow-up questions:

  • Why is Minor GC so fast? — 98% of objects in Eden are dead; only 2% live are copied (O(live), not O(all))
  • What does -XX:+PrintTenuringDistribution do? — Shows object distribution by age; helps tune MaxTenuringThreshold
  • Why shouldn’t -Xmn be fixed for G1? — G1 adaptively changes Young Gen to achieve MaxGCPauseMillis; fixing breaks adaptivity
  • What is SurvivorRatio? — Eden:Survivor ratio (default 8:1); too small → Premature Promotion

Red flags (DO NOT say):

  • “All objects live long, Young Gen is useless” — Weak Generational Hypothesis holds for most applications
  • “I fix -Xmn for G1 to control memory” — G1 loses adaptivity, pauses become unpredictable
  • “Minor GC scans Old Gen” — Card Table optimization: only Dirty cards are scanned

Related topics:

  • [[8. What are generations in GC]]
  • [[10. What is Old Generation (Tenured)]]
  • [[13. What is G1 GC]]
  • [[2. What is stored in Heap]]
  • [[12. What GC algorithms exist]]