java - G1 GC 是否有最大区域大小或最大区域数量?

标签 java garbage-collection jvm g1gc

我在研究G1 GC的时候,发现了这篇文章:http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html .在那篇文章中,有一段话是这样说的:

The G1 GC is a regionalized and generational garbage collector, which means that the Java object heap (heap) is divided into a number of equally sized regions. Upon startup, the Java Virtual Machine (JVM) sets the region size. The region sizes can vary from 1 MB to 32 MB depending on the heap size. The goal is to have no more than 2048 regions.

那是不是说G1 GC可以处理的java堆内存的最大大小是2048 * 32M,如果超过了会怎样?

最佳答案

来自 HotSpot JVM sources :

  // 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 选项中指定,则用于计算默认区域大小。实际数量可能超过这个值。

关于java - G1 GC 是否有最大区域大小或最大区域数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42569821/

相关文章:

Java 8 元空间垃圾回收

Java垃圾收集日志输出

java - 执行器不返回 10 个 future 对象

garbage-collection - 我用带有垃圾收集器的语言构建了一个解释器。我需要一个用于解释器的垃圾收集器吗?

java - 为什么Java不支持自动堆扩容?

java - 什么是 Java 中的 'single-generation' 垃圾收集器?

java - 带有嵌入式tomcat的Spring引导+带有身份验证用户的访问日志

java - 运算符优先级

java - 写入 android USB 端口并将其发送到 RS232 微型机器人端口

c# - 字符串、引用和垃圾收集