java - CMS 垃圾收集器——它什么时候运行?

标签 java garbage-collection concurrent-mark-sweep

我对可能控制 CMS 收集器何时启动的两个参数感到困惑:

MaxHeapFreeRatio(默认为 70%)

CMSInitiatingOccupancyFraction(默认超过 90%)

这些参数中的每一个究竟意味着什么?收集器什么时候开始(标记阶段),收集(清理阶段)?

最佳答案

CMSInitiatingOccupancyFraction决定 CMS 何时启动(为了使此选项生效,您还必须设置 -XX:+UseCMSInitiatingOccupancyOnly )。 MaxHeapFreeRatio是调整世代空间大小的一个选项。

例如参见...

http://java.sun.com/docs/hotspot/gc1.4.2/faq.html

The concurrent collection generally cannot be sped up but it can be started earlier. A concurrent collection starts running when the percentage of allocated space in the old generation crosses a threshold. This threshold is calculated based on general experience with the concurrent collector. If full collections are occurring, the concurrent collections may need to be started earlier. The command line flag CMSInitiatingOccupancyFraction can be used to set the level at which the collection is started. Its default value is approximately 68%. The command line to adjust the value is -XX:CMSInitiatingOccupancyFraction=<percent>

http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio=<minimum> and -XX:MaxHeapFreeRatio=<maximum>, and the total size is bounded below by -Xms and above by -Xmx.

.. 或..

http://www.petefreitag.com/articles/gctuning/

-XX:MaxHeapFreeRatio - when the percentage of free space in a generation exceeded this value the generation will shrink to meet this value. Default is 70

编辑:我用一个测试程序运行了一些模拟,该程序只是随机创建字节数组的映射并将它们复制到周围。我注意到 a) 分数值没有得到尊重——特别是在保守值(比如 50)下,CMS 初始标记阶段的占用率远远超过 50%,通常约为 70-80% 和 b)尽管如此,较小的分数值使 CMS初始阶段发生较早 (程序使用 -Xmx1536m -Xmx1536m -XX:NewSize=512m -XX:+UseConcMarkSweepGc + gc 日志记录和两个测试参数)

我还发现了一个关于此的旧错误报告:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486089

关于java - CMS 垃圾收集器——它什么时候运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9697754/

相关文章:

java - 如何在 Java 中将 double 字四舍五入为所需的 1 位小数

c# - 如何手动编程 Int.Parse()

android - 应用同步时出现奇怪的滞后

android - onReceive 异步操作和垃圾回收

c# - 委托(delegate)变量未被垃圾收集

java - 我应该如何针对我的应用程序调整 CMS?

java - 使用两个线程顺序调用两个不同函数时的通知/等待问题

java - RabbitListener 不是注释类型

java - 可以假设 Java Concurrent Mark Sweep Garbage Collector 在 Linux 和 Mac 以及 Windows 上同样出色吗?

java - 连续 CMS 收集后并发模式失败