gpt4 book ai didi

java - HotSpot JVM 中的动态 tenuring 阈值调整是如何工作的?

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

到目前为止我知道:

  • 对象分配在 eden 空间 中,如果它们在次要集合中幸存下来,它们将被提升到 幸存者空间 之一
  • 对于进一步的次要集合,在次要集合中幸存下来的对象将在两个幸存者空间之间交换。在此期间,对象的个体年龄随着每次小收集而增加。
  • 达到特定tenured threshold 的对象被提升到tenured space(老年代)。
  • 您可以设置 InitialTenuringThreshold(因为它说的是“初始”而不是“最小”)和 MaxTenuringThreshold(最大值:15)。然而,JVM 会根据实际使用的幸存者空间和期望的幸存者空间调整实际任期阈值(我认为每次主要收集之后)。
  • 可以使用“TargetSurvivorRatio”JVM 参数更改所需空间,默认情况下为最大幸存者空间的 50%。

我的问题是:

  • 关于 jvm 调整实际 tenurig 阈值的具体内容。
  • 在 jvm 更改实际的期限阈值后,所有对象年龄队列会发生什么情况。例如:
    • timeStamp1:jvm设置的当前实际tenuring为15,每个age都有对象分布。
    • timeStamp2:jvm 已将实际任期阈值调整为 5。现在 timeStamp1 中年龄为 n > 5 的所有对象会发生什么情况?

尚未找到任何关于此的文档。

最佳答案

我远不是 JDK 代码库的专家,但我相信您的大部分答案都与我提到的类有关。我是粗略阅读后胡乱猜测的,很高兴听到更正。

问题一:

根据 http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/gc_implementation/shared/ageTable.cpp L81 和下一个 (compute_tenuring_threshold) JVM 将遍历每个年龄并将具有该年龄的对象的大小相加。一旦它超过 desired_survivor_size 它将停止并假定它到达的最后一个年龄作为候选新阈值。选择的新阈值为 min(candidateAge, MaxTenuringThreshold)

compute_tenuring_threshold 在 G1 中从 http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/gc_implementation/shared/g1CollectorPolicy.cpp 调用它根据 ceil(_young_list_target_length/SurvivorRatio) 选择一个 _max_survivor_regions,然后调用上面的 compute_.. 方法。

young_list_target_length 在 g1CollectorPolicy.hpp 中更新,如解释的那样:

587   // Update the young list target length either by setting it to the
588 // desired fixed value or by calculating it using G1's pause
589 // prediction model. If no rs_lengths parameter is passed, predict
590 // the RS lengths using the prediction model, otherwise use the
591 // given rs_lengths as the prediction.
592 void update_young_list_target_length(size_t rs_lengths = (size_t) -1);

我没有研究模型,但我想这会回答你的问题:在较少的年龄足以保持 desired_survivor_size(AFAIK 在这里解释 http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html )后触发阈值变化。新阈值是根据给定/预测的 RS 长度选择的。

问题二:

在 g1CollectorPolicy.cpp 中检查这个,就在新的收集暂停开始时:

839   // We only need to do this here as the policy will only be applied
840 // to the GC we're about to start. so, no point is calculating this
841 // every time we calculate / recalculate the target young length.
842 update_survivors_policy();

据我所知,阈值将因此在 GC 运行之前更新。如果是这种情况,当访问幸存者区域中的 Activity 对象时,所有具有 object.age > newAge 的对象都将被保留(包括那些在 timestamp1 时具有 age < threshold 但现在超过它的对象)。

我希望这有点道理。

关于java - HotSpot JVM 中的动态 tenuring 阈值调整是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22350002/

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