gpt4 book ai didi

java - JVM GC 的大对象是什么

转载 作者:搜寻专家 更新时间:2023-11-01 02:49:26 24 4
gpt4 key购买 nike

Charlie Hunt 在他的 presentation 中说大对象对 JVM GC 不利。 .因为:

  1. 大型对象的分配和初始化成本很高。

  2. 不同大小的大对象会导致 Java 堆碎片化。

如何定义大对象?我怎么知道对象是否是大对象?谢谢

最佳答案

定义取决于平台、JVM 和 JVM 配置。例如,这里摘自 How Garbage Collection differs in the three big JVMs Michael Kopp 的博文:

Large and small objects

The JRockit differentiates between large and small objects during allocation. The limit for when an object is considered large depends on the JVM version, the heap size, the garbage collection strategy and the platform used. (italics mine - DL.) It is usually somewhere between 2 and 128 KB. Large objects are allocated outside thread local area in in case of a generational heap directly in the old generation. This makes a lot of sense when you start thinking about it. The young generation uses a copy ccollection. At some point copying an object becomes more expensive than traversing it in ever garbage collection.

对于你的第二个问题,我不确定如何获得该阈值,但特别是在 HotSpot 中你可以设置它:

-XX:PretenureSizeThreshold=2m

引用HotSpot JVM garbage collection options cheat sheet由 Alexey Ragozin 提供有关此选项和许多其他 -XX 选项的详细信息。

关于java - JVM GC 的大对象是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14190280/

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