为什么 G1 是 Java 9 的默认垃圾收集器?

Why G1 is default garbage collector for Java 9?

直到 Java 8,我们已经看到 Parallel GC 作为默认垃圾收集器,但最近发布的 Java (Java 9)想出了 G1 GC 作为默认垃圾收集器。

为什么 Java 移至 G1 GC? 是否有任何性能改进?

来自 JEP 248(JEP - JDK 增强提案)

Summary

Make G1 the default garbage collector on 32- and 64-bit server configurations.

Motivation

Limiting GC pause times is, in general, more important than maximizing throughput. Switching to a low-pause collector such as G1 should provide a better overall experience, for most users, than a throughput-oriented collector such as the Parallel GC, which is currently the default.

Many performance improvements were made to G1 in JDK 8 and its update releases, and further improvements are planned for JDK 9. The introduction of concurrent class unloading (JEP 156) in JDK 8u40 made G1 a fully-featured garbage collector, ready to be the default.

总而言之,这是他们努力了很长时间的东西,Java9 他们终于决定将其设为默认值。

答案 does state the motivation behind the introduction of (有用的标签信息)准确无误。

Why Java moved to G1 GC? Is their any performance improvement?

要列出我从 中引入的最近更改中学到的一些关键改进,将是:

Parallel GC 相比,在 Java 8 之前用作默认 GC 的主要改进之一是避免 Full GC。

The goal of G1 is to minimize pause times without constraining the heap size or the amount of live data. This is achieved by doing a large part of the GC work concurrently and also doing partial compaction. Avoiding doing full GCs (_i.e., stop-the-world GCs) is one of the major benefits of G1.

这段时间 G1 的主要功能改进之一是引入并发 class 卸载。以前 G1 将所有 classes 视为活动的,除了在 full GC 期间。这主要伴随着 removal of the permanent generation.

  • String Deduplication in G1

    从消费应用程序的角度来看,另一个功能是 在 G1 GC 中实现自动和连续的字符串重复数据删除,以避免浪费内存并减少内存占用。这一变化是随着 String class 的内部表示从 UTF-16 字符数组到 byte 数组加上提议的编码标志字段 compact strings.

尽管如此,G1 的资源使用与并行 GC 不同,它还指出,当 需要最小化资源使用开销时,应使用 G1 以外的收集器 ,并且在此更改之后,必须明确指定备用收集器。