Java -XX:+UseG1GC 是 -Xincgc 的正确替代品吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33919213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:08:52  来源:igfitidea点击:

Is -XX:+UseG1GC the correct replacement for -Xincgc?

javajava-8garbage-collectiong1gc

提问by BetaRide

Currently, we are using the incremental garbage collector by adding -Xincgcto the java command. In JDK 8this switch is deprecated. So what's the equivalent replacement for it? -XX:+UseG1GC?

目前,我们正在通过添加-Xincgc到 java 命令来使用增量垃圾收集器。在JDK 8中,不推荐使用此开关。那么它的等效替代品是什么?-XX:+UseG1GC?

Background: The application has a heap of 8GBand creates a lot of short living objects. I noticed that it often paused for some seconds to do garbage collection. Out of curiosity I added the -Xincgcand found that the pauses were gone and overall performance improved ~4 times.

背景:该应用程序有8GB的堆,并创建了许多短寿命对象。我注意到它经常暂停几秒钟来进行垃圾收集。出于好奇,我添加了-Xincgc,发现停顿消失了,整体性能提高了大约 4 倍。

Unfortunately, I did not find any information about what type of garbage collector the -Xincgctriggers. There's the CMS(Concurrent mark and sweep) and the new G1(Garbage first). But what do I get with -Xincgc?

不幸的是,我没有找到关于-Xincgc触发器是什么类型的垃圾收集器的任何信息。有CMS(并发标记和扫描)和新的G1(垃圾优先)。但我能得到-Xincgc什么?

回答by the8472

For Oracle/OpenJDK 8 the default collector on most machines is the Parallel Throughput Collector, except for some 32bit windows machines where it can be the Serial GC.

对于 Oracle/OpenJDK 8,大多数机器上的默认收集器是并行吞吐量收集器,除了一些 32 位 Windows 机器,它可以是串行 GC。

Xincgc is CMS in incremental mode. The main benefit you're seeing probably is caused by switching from the Throughput Collector to CMS, not from the incremental mode, which is designed for single-core CPUs.

Xincgc 是增量模式的 CMS。您看到的主要好处可能是从吞吐量收集器切换到 CMS,而不是从专为单核 CPU 设计的增量模式。

Incremental Mode is also deprecated, so simply enable CMS via -XX:+UseConcMarkSweepGCand see if that works for you.

增量模式也已弃用,因此只需通过启用 CMS-XX:+UseConcMarkSweepGC并查看它是否适合您。

Of course you can also try G1GC, which is also designed to reach low pause time goals and has the advantage that it does not suffer from fragmentation like CMS does and thus is less likely to experience concurrent mode failures which result in a single-threaded stop the world collection.

当然你也可以尝试 G1GC,它也是为了达到低暂停时间目标而设计的,它的优点是它不像 CMS 那样受到碎片化的影响,因此不太可能遇到导致单线程停止的并发模式故障世界收藏。

So, try both and measure.

因此,请尝试两者并进行测量。

See also: Oracle's Java 8 GC Tuning Guides

另请参阅:Oracle 的 Java 8 GC 调优指南

回答by Tim Long

Until this option completely deprecated by Oracle in the newer version. We could still use this, by applying the following jvm params:

直到 Oracle 在较新版本中完全弃用此选项。我们仍然可以通过应用以下 jvm 参数来使用它:

-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

The later 2 params are for logging on GC activities.

后面的 2 个参数用于记录 GC 活动。