性能问答>jvm新生代分配问题,为何不是2:8>
5回复

jvm新生代分配问题,为何不是2:8



jvm.pngjvm1.png
新生代100多M ,s0 s1 edu区分配比例应该是2:8,为何s0 和 s1 才分配到2M ,看了jvm参数设置好像也没啥问题,求助!

4525 阅读
请先登录,再评论

因为使用的是PS的GC算法,默认情况下PS是会做自适应的,也就是默认会开启AdaptiveSizePolicy的策略,这种情况下,各个分代的Size其实是会动态变化的,具体变化发生在GC之后,会根据之前分代的使用情况来重新设置当前分代的大小,具体逻辑如下:

PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(){
...
  // The padded average also maintains a deviation from the average;
  // we use this to see how good of an estimate we have of what survived.
  // We're trying to pad the survivor size as little as possible without
  // overflowing the survivor spaces.
  size_t target_size = align_size_up((size_t)_avg_survived->padded_average(),
                                     _space_alignment);
  target_size = MAX2(target_size, _space_alignment);
...
  set_survivor_size(target_size);
}

因此在经过N次GC之后,你可能会看到上面的情况,当然第一次还没有发生任何GC的情况下,是按照SurvivorRatio来计算的,逻辑如下:

void PSYoungGen::compute_initial_space_boundaries() {
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");

  // Compute sizes
  size_t alignment = heap->space_alignment();
  size_t size = virtual_space()->committed_size();
  assert(size >= 3 * alignment, "Young space is not large enough for eden + 2 survivors");

  size_t survivor_size = size / InitialSurvivorRatio;
  survivor_size = align_size_down(survivor_size, alignment);
  // ... but never less than an alignment
  survivor_size = MAX2(survivor_size, alignment);

  // Young generation is eden + 2 survivor spaces
  size_t eden_size = size - (2 * survivor_size);

  // Now go ahead and set 'em.
  set_space_boundaries(eden_size, survivor_size);
  space_invariants();

  if (UsePerfData) {
    _eden_counters->update_capacity();
    _from_counters->update_capacity();
    _to_counters->update_capacity();
  }
}

因此如果不想让它动态变化,可以加上-XX:-UseAdaptiveSizePolicy即可

32年前

15730315201.png这个young GC 回收是不是太过于频繁了,该如何处理,找问题

2年前
回复 你假笨:

牛🐮

2年前回复
回复 你假笨:

👍🏻👍🏻👍🏻👍🏻👍🏻

2年前回复
回复 생각하다:

从gc日志来看,问题并不大,因为gc暂停时间非常短,如果存在频繁创建对象,gc频繁是省不了的

2年前回复