G1gc compaction algorithm

Thomas Schatzl thomas.schatzl at oracle.com
Wed Jul 16 06:30:50 UTC 2014


Hi Martin,

On Wed, 2014-07-16 at 06:45 +0300, Martin Makundi wrote:
> Hi!
> 
> 
> Humongous allocation fails when there is not enough contiguous free
> space in memory. 
> 
> 
> How does g1gc compaction algorithm work, does it compact only within a
> region or does it attempt to compact in a whole-heap-defragmentation
> way? The latter would reduce the probability of "humongous allocation
> failure". And if this is possible, is there a parameter/s that can be
> changed to tune this?

Full GC compaction algorithm works by compacting on a whole-heap basis
ignoring humongous objects. Humongous objects are never moved at this
time.

There is a recently discovered bug with that that does not consider
humongous objects freed in the same collection
(https://bugs.openjdk.java.net/browse/JDK-8049332) but leaves that space
empty. This may actually be an advantage if the humongous object size is
regular.

Minor GC only ever evacuates, no compaction. There is no consideration
to free memory so that it is contiguous after GC at this point.

There are some patches in 8u20 (maybe 8?) that reduce fragmentation by
playing around with object distribution per type.

If you have quite short-living humongous objects of a particular type,
there is https://bugs.openjdk.java.net/browse/JDK-8027959 which will
likely be in 8u40.

There are no particular knobs to turn to impact compaction density at
this time except indirectly via heap region size (G1HeapRegionSize).

You can get current region distribution information by eg. -XX:
+PrintHeapAtGC -XX:+PrintHeapAtGCExtended .

Thanks,
  Thomas





More information about the hotspot-gc-use mailing list