如果您使用的是 G1 GC,为什么建议 Java 10?

Why is Java 10 recommended if you're using the G1 GC?

Java 10 通过迭代改进其现有算法来减少 Full GC 暂停时间。

-XX:ParallelGCThreads

据我了解,G1 不会 运行 它的收集周期与我们的应用程序同时进行。它仍然会定期暂停应用程序,并且 Full GC 暂停会随着堆大小的增加而增加。

那它是如何提高性能的呢?谁能解释一下?

因为直到 Java 10 G1GC 才在 stop-the-world full GC 循环中完全并行。根据 JEP 307: Parallel Full GC for G1 这改善了最坏情况下的延迟:

The G1 garbage collector is designed to avoid full collections, but when the concurrent collections can't reclaim memory fast enough a fall back full GC will occur. The current implementation of the full GC for G1 uses a single threaded mark-sweep-compact algorithm. We intend to parallelize the mark-sweep-compact algorithm and use the same number of threads as the Young and Mixed collections do. The number of threads can be controlled by the -XX:ParallelGCThreads option, but this will also affect the number of threads used for Young and Mixed collections.

事实上,如果您使用 G1GC,建议使用 Java 11,因为在它上面做了很多工作 减少它的占用空间并降低与 10

相比,它的暂停

在 hotspot-gc-use 邮件列表上总结了 11、10 和 9 对 G1GC 所做的各种改进,您可以在此处找到它 link: http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2018-June/002759.html

列表中 post 的快速摘要:

[...] I would like to point out that overall, with G1, compared to JDK8 it is possible to get 60% lower pause times "for free" on x64 processors (probably more on ARM/PPC due to mentioned specific changes), at a highly reduced memory footprint.