G1 GC的回收区域有最大的大小限制还是最大数量限制?

6
当我学习G1 GC时,我发现了这篇文章:http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html。在这篇文章中,有一段话如下所述:
G1 GC是一个分区和分代垃圾收集器,这意味着Java对象堆(heap)被分成许多大小相等的区域。在启动时,Java虚拟机(JVM)设置区域大小。根据堆的大小,区域大小可以从1 MB到32 MB不等。目标是不超过2048个区域。
这是否意味着G1 GC可以处理的java堆内存的最大大小为2048 * 32M?如果超过了这个大小会发生什么呢?
1个回答

10

以下内容来自HotSpot 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选项中未指定)。实际数量可能超过此值。

有没有关于何时/为什么要使用“-XX:G1HeapRegionSize”调整区域大小的智慧?例如,我注意到在Minecraft发行版中,默认设置为32MB - 远高于JVM的默认值。 - jocull
例如,增加区域大小有助于减少大量的分配。 - apangin
G1在内存方面有上限吗?还是即使堆大小达到1TB也能正常工作? - samshers
@samshers 这完全取决于应用程序、其分配率和模式。G1 可能可以处理大堆,但在您的情况下 GC 暂停是否可接受 - 我无法知道。 - apangin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接