g1gc有最大区域大小还是最大区域数量?

zf9nrax1  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(460)

当我研究g1 gc时,我发现这篇文章:http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html. 在那篇文章中,有这样一句话:
g1gc是一个区域化和分代的垃圾收集器,这意味着java对象堆(heap)被划分为许多大小相等的区域。在启动时,java虚拟机(jvm)设置区域大小。根据堆大小,区域大小可以从1 mb到32 mb不等。目标是不超过2048个地区。
这是否意味着g1gc可以处理的java堆内存的最大大小是2048*32m,如果超过这个大小,会发生什么?

iswrvxsc

iswrvxsc1#

从热点jvm源:

// Minimum region size; we won't go lower than that.
  // We might want to decrease this in the future, to deal with small
  // heaps a bit more efficiently.
  static const size_t MIN_REGION_SIZE = 1024 * 1024;

  // Maximum region size; we don't go higher than that. There's a good
  // reason for having an upper bound. We don't want regions to get too
  // large, otherwise cleanup's effectiveness would decrease as there
  // will be fewer opportunities to find totally empty regions after
  // marking.
  static const size_t MAX_REGION_SIZE = 32 * 1024 * 1024;

  // The automatic region size calculation will try to have around this
  // many regions in the heap (based on the min heap size).
  static const size_t TARGET_REGION_NUMBER = 2048;
``` `MIN_REGION_SIZE` (1mb)和 `MAX_REGION_SIZE` (32mb)是硬限制; `TARGET_REGION_NUMBER` 只是一个提示,如果在jvm选项中没有指定,则用于计算默认区域大小。实际数字可能超过此值。

相关问题