Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does G1 GC have a max size of region or max amount of region?

when i studied G1 GC, I found this article: http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html. In that article, there is something says as follow:

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.

Does that mean the max size of java heap memory that G1 GC can deal with is 2048 * 32M, and if the size exceeds it, what will happen?

like image 940
ho yoje Avatar asked Mar 03 '17 02:03

ho yoje


People also ask

How does G1 GC work?

G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multi-processors, to decrease pause times and increase throughput.

What is G1 humongous allocation?

Humongous allocations are allocations over 50% of the G1 region size (the region size is another statistic printed in the GC log at the end of each collection). If your app uses humongous allocations heavily it can lead to excessive memory fragmentation and OutOfMemoryError exceptions.

Is G1 GC stop the world?

G1GC (Garbage First Garbage Collector) is the low latency garbage collection algorithm included in recent versions of both OpenJDK and Oracle Java. Like other Java GC algorithms, to reclaim heap space G1GC must halt all application threads, a process referred to as stopping-the-world (STW) or pausing (a GC pause).

What is G1 old gen heap?

G1 is a generational, incremental, parallel, mostly concurrent, stop-the-world, and evacuating garbage collector which monitors pause-time goals in each of the stop-the-world pauses. Similar to other collectors, G1 splits the heap into (virtual) young and old generations.


1 Answers

From 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) and MAX_REGION_SIZE (32MB) are hard limits;
  • TARGET_REGION_NUMBER is just a hint that is used to calculate default region size if it is not specified among JVM options. The actual number may exceed this value.
like image 171
apangin Avatar answered Sep 28 '22 09:09

apangin