Quick revision
The short answer
Each step answered the limits of the last as heaps grew. Serial and Parallel suited small heaps but their pauses grew with the heap; CMS marked concurrently but never compacted, so fragmentation caused long full GCs, and it was deprecated in JDK 9 and removed in JDK 14; G1 brought regions and pause targets as a balanced default; ZGC and Shenandoah made compaction concurrent, and generational modes then won back throughput. The lesson is that we keep trading CPU and memory for latency while defaults improve every release, so we stay on JDK defaults, adopt low-pause collectors where budgets require them, and revisit at every LTS.
What to remember
In this answer, we followed HotSpot's collectors from Serial and Parallel, whose pauses grew with the heap, through CMS, which marked concurrently but never compacted and was removed in JDK 14, to G1's regions and pause targets as the JDK 9 default, and on to ZGC and Shenandoah with concurrent compaction and their generational modes. The pattern is a steady trade of CPU and memory for latency, with defaults improving every release. The policy that follows is to stay on JDK defaults, adopt low-pause collectors where budgets require them, upgrade steadily, and revisit at every LTS.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Each step answered the limits of the last as heaps grew. Serial and Parallel suited small heaps but their pauses grew with the heap; CMS marked concurrently but never compacted, so fragmentation caused long full GCs, and it was deprecated in JDK 9 and removed in JDK 14; G1 brought regions and pause targets as a balanced default; ZGC and Shenandoah made compaction concurrent, and generational modes then won back throughput. The lesson is that we keep trading CPU and memory for latency while defaults improve every release, so we stay on JDK defaults, adopt low-pause collectors where budgets require them, and revisit at every LTS.
Why this question is asked
Collector choices made today will live for years, across several JDK upgrades and many hardware generations. History is a good guide to what will change, because the same forces have driven every step: heaps got bigger, latency expectations got stricter, and CPU and memory got cheaper relative to engineers' time. Interviewers ask this of senior candidates to see whether they can turn technical history into policy. In this answer, we will walk through each stage, look at what drove the next one, find the pattern, and then turn it into a five-year policy.
1Serial and Parallel: Simple and Fast, While Heaps Were Small
The first HotSpot collectors stopped the application for every collection. Serial used one thread; Parallel, the throughput collector, used many threads for the same stop-the-world work. Both are generational: a young generation collected often and cheaply, and an old generation collected by a full mark and compaction.
This works very well while heaps are small. A full collection of a 200 MB heap takes a fraction of a second. The problem is that pause time grows with the amount of live data, and live data grew with the heap. At several gigabytes, a full collection took seconds, which became unacceptable as Java moved into interactive web services.
2CMS: Concurrent Marking Without Compaction
Concurrent Mark Sweep, CMS, attacked the old-generation pause. It marked live objects concurrently, while the application ran, and then swept dead objects into free lists, also concurrently. Old-generation pauses became short.
But CMS never compacted. Over time the old generation turned into a patchwork of free gaps, and eventually a promotion could not find a large enough gap. Then CMS fell back to a full, single-threaded, stop-the-world compaction, the infamous concurrent mode failure, which could take many seconds on a big heap. CMS was also hard to tune, with dozens of flags. It was deprecated in JDK 9 (JEP 291) and removed in JDK 14 (JEP 363).
3G1: Regions and Pause Targets
G1 changed the layout of the heap. Instead of two large contiguous generations, it uses many equal regions and collects by evacuating chosen regions, which compacts as it goes. It marks concurrently, then picks the regions with the most garbage, and it sizes its work to meet a pause time target, MaxGCPauseMillis, 200 ms by default.
That made G1 a balanced default for medium to large heaps: compaction without very long full collections, predictable pauses of tens of milliseconds, and few flags to set. It became the default in JDK 9 (JEP 248), and its full collection was made parallel in JDK 10. Its limit is that evacuation still happens in stop-the-world pauses, so pauses still grow with the amount of live data copied.
4ZGC and Shenandoah: Concurrent Compaction
The next step removed copying from the pause. ZGC (experimental in JDK 11, production in JDK 15) and Shenandoah (upstream in JDK 12, production in JDK 15) move objects while the application runs, using barriers on reference loads so the application always sees the current copy. Pauses became roughly constant, around a millisecond or less, whatever the heap size.
The first versions were not generational: every cycle traced the whole heap, which costs CPU and needs headroom under high allocation rates. So the latest step added generations back: generational ZGC in JDK 21, default in JDK 23 and the only ZGC mode from JDK 24, and generational Shenandoah, a product feature in JDK 25. Generational modes win back much of the throughput and memory efficiency that early concurrent collectors gave up.
| Stage | Solved | Left unsolved |
|---|---|---|
| Serial / Parallel | simple, high throughput on small heaps | pauses grow with heap and live data |
| CMS (removed JDK 14) | short old-gen pauses via concurrent marking | no compaction: fragmentation, long full GCs |
| G1 (default JDK 9) | regions, compaction, pause targets | evacuation still stop-the-world |
| ZGC, Shenandoah | concurrent compaction: pauses independent of heap | CPU and headroom without generations |
| Generational ZGC/Shenandoah | low pauses with better throughput | still more CPU than G1 or Parallel |
5The Pattern Behind the History
Three things stand out. First, every step trades CPU and memory for latency. Concurrent collectors do their work while the application runs, so they use more CPU in total, and they need headroom for allocation during a cycle. That trade became more attractive as hardware got cheaper and latency targets got stricter.
Second, defaults improve every release. G1 in JDK 25 is much better than G1 in JDK 9, with years of work on remembered sets, region selection and pause prediction. A service that simply upgrades its JDK gets those gains for free. Very often the cheapest GC improvement available is a JDK upgrade.
Third, hand tuning ages badly. Flags tuned for CMS or early G1 are now neutral at best and harmful at worst, and some stop the JVM from starting after their removal. The configuration that aged best is the one with the fewest flags.
6A Policy for the Next Five Years
From this, the policy follows. Stay on JDK defaults, which today means G1 with only the heap size set, because the default is where OpenJDK invests most, and it improves at every upgrade. Adopt low-pause collectors, today generational ZGC, where a service's latency budget requires them, backed by measurements, and accept their CPU and memory cost knowingly. Keep Serial for tiny processes and Parallel for throughput batch jobs.
Upgrade the JDK steadily, at least to each LTS, and treat each upgrade as a GC review: re-measure the services on exceptions, remove flags that no longer help, and check whether the default now meets budgets that once required a special collector. Over five years, it is likely that low-pause collectors become cheaper and possibly the better default for more services; a policy that revisits at every LTS will catch that change instead of freezing today's choice.
7Follow-up questions
How should cloud cost models influence the CPU-for-latency trade?
In the cloud, extra CPU and memory turn directly into money per hour, so the trade becomes a price. If generational ZGC needs 10 percent more CPU and 30 percent more memory for a service, that might mean two more instances out of twenty, which has a known monthly cost. We compare that with what the latency gain is worth: missed service objectives, lost conversions, or penalties. For services with clear latency value the trade is easy; for internal services with loose targets, G1's efficiency usually wins. Pricing models matter too: if memory is cheap relative to CPU on our instance types, headroom-hungry collectors cost less than they appear.
Why was CMS removed rather than fixed?
Its core design, mark and sweep without compaction, made fragmentation unavoidable, and fixing that would have meant building a new collector. Its code was also complex and costly to maintain alongside G1. Once G1 covered its use cases and ZGC and Shenandoah offered lower pauses, OpenJDK deprecated it in JDK 9 and removed it in JDK 14.
Will G1 stay the default?
For now, yes, and OpenJDK keeps investing in it, including proposals to use it even on small machines. But the history suggests defaults change when the trade-offs shift, so the policy should not assume G1 forever; it should re-check at each LTS.
8Conclusion
In this answer, we followed HotSpot's collectors from Serial and Parallel, whose pauses grew with the heap, through CMS, which marked concurrently but never compacted and was removed in JDK 14, to G1's regions and pause targets as the JDK 9 default, and on to ZGC and Shenandoah with concurrent compaction and their generational modes. The pattern is a steady trade of CPU and memory for latency, with defaults improving every release. The policy that follows is to stay on JDK defaults, adopt low-pause collectors where budgets require them, upgrade steadily, and revisit at every LTS.
Open with
Every step was a response to heaps getting bigger and latency expectations getting stricter. Serial and Parallel stop the application for all their work; that is simple and very efficient on small heaps, but pauses grow with live data, and at several gigabytes full GCs took seconds.
Then, if they want more
CMS marked the old generation concurrently so old pauses got short, but it never compacted, so fragmentation eventually forced long single-threaded full GCs, and it was hard to tune; it was deprecated in JDK 9 and removed in 14.
G1 introduced regions and evacuation, so it compacts as it goes, plus a pause target, which made it a balanced default from JDK 9. But it still copies in stop-the-world pauses.
ZGC and Shenandoah made compaction concurrent with load barriers, so pauses stopped depending on heap size, and the generational modes in JDK 21 to 25 recovered much of the throughput.
The lesson for me is that each step trades CPU and memory headroom for latency, and that defaults improve every release, so upgrading the JDK is often the cheapest GC win and old hand tuning ages badly.
So for the next five years I would stay on JDK defaults with minimal flags, use generational ZGC where latency budgets need it with the cost measured, and revisit at every LTS.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9, Java 14, Java 15, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- HotSpot Garbage Collection Tuning Guide, JDK 21
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "HotSpot's collectors evolved from Serial and Parallel to CMS, then G1 as default in JDK...": https://scrivio-interview-library.netlify.app/java/garbage-collection/00905cdd3c/