Backend Development 9 min read

Why G1 Is the Future Garbage Collector for High‑Throughput Java Services

This article examines how Oracle's G1 garbage collector, the default since JDK 9, outperforms the traditional CMS collector in multi‑core, large‑memory environments through parallelism, space integration, predictive pause models, and real‑world performance testing on Yuewen's licensing service.

Yuewen Technology
Yuewen Technology
Yuewen Technology
Why G1 Is the Future Garbage Collector for High‑Throughput Java Services

Core Viewpoint

Oracle switched to the G1 collector as the default garbage collector starting with Java JDK 9, and its algorithm is considered the best choice for multi‑core and large‑memory Java applications. Based on Yuewen's production usage, we explore how G1 delivers impressive performance and stability under high‑traffic services.

Typical Scenarios for Using G1

Performance : Does G1 meet the expected performance after switching?

Compatibility : Is service compatibility guaranteed after the switch?

Online Debugging : How can GC issues be diagnosed from logs in production?

Parallelism and Concurrency

G1 fully utilizes CPU and multi‑core hardware advantages. On servers with only 2‑4 cores, G1’s benefits are limited.

Space Integration

Unlike CMS’s "mark‑clean" algorithm, G1 implements a "mark‑compact" approach, greatly reducing memory fragmentation.

Predictive Pause Model

G1 can build a predictable pause‑time model, allowing users to specify a target pause window (M ms) and let the collector optimize runtime efficiency accordingly.

G1 Collector Phases

Initial Mark

Concurrent Mark

Final Mark

Sweep and Compact

Experimental Design

To control variables, the high‑request YuewenLicenseServer service was selected as the test target. One server ran CMS (with long‑term usage history) and another ran G1. Data were collected over a 7‑day window for performance comparison.

Results

Throughput: CMS achieved 99.78% utilization, while G1 reached 99.928%. The 0.2% difference is barely perceptible in practice, indicating comparable throughput.

Other Dimension Comparisons

Across metrics such as average, median, and pause times, G1 consistently outperformed CMS by an order of magnitude over long periods.

Analysis shows G1’s algorithm avoids memory fragmentation, eliminating stop‑the‑world (STW) pauses associated with CMS.

G1 Memory Layout

G1 divides the heap into regions; large objects occupy whole regions, reducing fragmentation.

Online GC Log Analysis

Typical Young G1 GC logs were examined, highlighting the four phases of memory processing: marking live objects, calculating new address spaces, updating pointers, and moving objects to new locations.

Source code such as MarkSweep.hpp implements these steps.

Dynamic Young Generation Sizing

G1 can adjust the ratio of young to old generations based on target pause time, using parameters like -XX:G1MaxNewSizePercent and -XX:G1NewSizePercent . However, in cases with large cached objects or heavy memory movement, manual tuning may be required.

Conclusion

Since JDK 9, G1 is the default collector and represents the new standard for Java memory management. It excels in large‑memory, multi‑core environments and can surpass CMS when appropriately tuned for specific workloads.

References

The Garbage Collection Handbook – Richard Jones, Antony Hosking, Eliot Moss

https://openjdk.java.net/jeps/248

https://openjdk.java.net/jeps/8230187

https://docs.oracle.com/en/java/javase/11/gctuning/garbage-first-garbage-collector.html#GUID-ED3AB6D3-FD9B-4447-9EDF-983ED2F7A573

backendjavaJVMperformanceGarbage CollectionG1GC
Yuewen Technology
Written by

Yuewen Technology

The Yuewen Group tech team supports and powers services like QQ Reading, Qidian Books, and Hongxiu Reading. This account targets internet developers, sharing high‑quality original technical content. Follow us for the latest Yuewen tech updates.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.