gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:09 25 4
gpt4 key购买 nike

我对可能控制 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com