美文网首页
G1重要参数说明

G1重要参数说明

作者: allanYan | 来源:发表于2022-09-07 17:16 被阅读0次

G1MixedGCCountTarget

G1 mixed GC在计算每次需要回收多少个region时使用,G1 通过并发标记计数出每个region的使用情况,然后通过1-N次mixed gc来进行垃圾回收,那么每次垃圾回收需要回收多少个region呢,其中最小值通过如下逻辑来计算:

uint G1CollectorPolicy::calc_min_old_cset_length() {
  // The min old CSet region bound is based on the maximum desired
  // number of mixed GCs after a cycle. I.e., even if some old regions
  // look expensive, we should add them to the CSet anyway to make
  // sure we go through the available old regions in no more than the
  // maximum desired number of mixed GCs.
  //
  // The calculation is based on the number of marked regions we added
  // to the CSet chooser in the first place, not how many remain, so
  // that the result is the same during all mixed GCs that follow a cycle.

  const size_t region_num = (size_t) _collectionSetChooser->length();
  const size_t gc_num = (size_t) MAX2(G1MixedGCCountTarget, (uintx) 1);
  size_t result = region_num / gc_num;
  // emulate ceiling
  if (result * gc_num < region_num) {
    result += 1;
  }
  return (uint) result;
}

G1OldCSetRegionThresholdPercent

如上所述,计算每次回收的最大region个数逻辑如下,其中使用到了 G1OldCSetRegionThresholdPercent:

uint G1CollectorPolicy::calc_max_old_cset_length() {
  // The max old CSet region bound is based on the threshold expressed
  // as a percentage of the heap size. I.e., it should bound the
  // number of old regions added to the CSet irrespective of how many
  // of them are available.

  G1CollectedHeap* g1h = G1CollectedHeap::heap();
  const size_t region_num = g1h->num_regions();
  const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
  size_t result = region_num * perc / 100;
  // emulate ceiling
  if (100 * result < region_num * perc) {
    result += 1;
  }
  return (uint) result;
}

G1HeapWastePercent

mixed GC时,如果发现待回收region的可回收内存不大,那么会放弃执行mixed gc,逻辑如下:

 size_t reclaimable_bytes = cset_chooser->remaining_reclaimable_bytes();
  double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes);
  double threshold = (double) G1HeapWastePercent;
  if (reclaimable_perc <= threshold) {
    ergo_verbose4(ErgoMixedGCs,
              false_action_str,
              ergo_format_reason("reclaimable percentage not over threshold")
              ergo_format_region("candidate old regions")
              ergo_format_byte_perc("reclaimable")
              ergo_format_perc("threshold"),
              cset_chooser->remaining_regions(),
              reclaimable_bytes,
              reclaimable_perc, threshold);
    return false;
  }

InitiatingHeapOccupancyPercent

老年代使用的内存占整个堆的比例超过InitiatingHeapOccupancyPercent时,才会进行并发标记,默认值为45%;

PrintAdaptiveSizePolicy

打印关于自适应大小调整相关的信息,例如GC时如何选择要回收的region日志

总结

Concurrent Marking Cycle 和Mixed GC是两个不同的阶段:

  1. Concurrent Marking Cycle是发生在yong gc之后,当老年代使用达到一定比例时,yong gc之后会跟随一次Concurrent Marking Cycle; Concurrent Marking Cycle阶段的清理操作并不会清理垃圾对象,也不会执行存活对象的拷贝。也就是说,在极端情况下,该阶段结束之后,空闲分区列表将毫无变化,JVM的内存使用情况也毫无变化;
  2. mixed gc实际上与YGC是一样的:第一个步骤是从分区中选出若干个分区进行回收,这些被选中的分区称为Collect Set(简称CSet);第二个步骤是把这些分区中存活的对象复制到空闲的分区中去,同时把这些已经被回收的分区放到空闲分区列表中。垃圾回收总是要在一次新的YGC开始才会发生;

相关文章

  • G1重要参数说明

    G1MixedGCCountTarget G1 mixed GC在计算每次需要回收多少个region时使用,G1 ...

  • Mac下IDEA卡顿问题解决

    修改前: 修改后: 主要参数及说明 这里我保留了G1的垃圾回收方式。 -XX:+UseG1GC 据说G1垃圾回收是...

  • jvm GC参数调优

    (本篇主要以CMS-GC为主,如果对G1感兴趣的我后面也可以补充) 一、GC参数说明与介绍 1.1 jvm启动参数...

  • JVM参数

    垃圾回收机制 CMS组合 G1组合 UseParallelOldGC组合 参数说明 -Xms:最小堆内存空间 -X...

  • 机器学习|实例演示DecisionTreeClassifier和

    1 重要参数说明 DecisionTreeClassifier和DecisionTreeClassifier 重要...

  • 3.JVM系列-G1垃圾收集器

    目录 一、背景 二、G1垃圾收集器特性 三、G1执行步骤 四、G1基本参数 四、G1日志解释 六、基本原理 七、...

  • G1垃圾收集器

    G1垃圾收集器在JDK1.7中投入使用,并作为JDK1.9默认的垃圾收集器。 JVM配置开启G1参数: 一、G1与...

  • 深入理解Java虚拟机(三)--G1垃圾回收器

    G1 GC,全称Garbage-First Garbage Collector,从官网的描述中说明G1是一种服务器...

  • G1垃圾回收器实战

    目录 参数配置 G1回收器对应jvm和tomcat参数配置[https://www.jianshu.com/p/7...

  • awk

    参数说明 特殊标识符 awk中重要的方法

网友评论

      本文标题:G1重要参数说明

      本文链接:https://www.haomeiwen.com/subject/bebgnrtx.html