Search code examples
javagarbage-collectiongarbage

explanation for Garbage Collector - Allocation Failure


I am currently investigating a performance bug in the game Minecraft (original post). The last thing I needed to check was the output of the Garbage Collector. When I did, I noticed that 99% of all outputs were [GC (Allocation Failure).... Here is a small sample of the output:

13.238: [GC (Allocation Failure)  805728K->167001K(1601024K), 0.0251328 secs]
13.907: [GC (Allocation Failure)  805977K->167208K(1618432K), 0.0257168 secs]
14.559: [GC (Allocation Failure)  802088K->167520K(1597440K), 0.0262393 secs]
15.257: [GC (Allocation Failure)  802400K->168597K(1622016K), 0.0281692 secs]
15.925: [GC (Allocation Failure)  805525K->170531K(1618944K), 0.0202619 secs]
27.474: [GC (Allocation Failure)  807459K->178239K(1626624K), 0.0239986 secs]
27.884: [GC (System.gc())  215249K->179128K(1624576K), 0.0286153 secs]
27.913: [Full GC (System.gc())  179128K->167443K(1624576K), 0.4367059 secs]

What exactly does this mean? I found an another post that was talking about it but I couldn't quite understand what they meant. Could anyone explain this to me in 'baby language'?


Solution

  • As question suggest I would try to rephrase answer to Java GC (Allocation Failure) in baby language.

    JVM always maintain large chunk of free memory within heap for new allocations.

    Normally, when you execute new Something(), a portion of memory is chipped off from that free memory chunk. That is normal allocations.

    Though, eventually free chunk got exhausted, and next attempt to chip some memory would fail - allocation failure.

    This is a signal for Garbage Collection to kick in. Garbage Collection does its magic, finds dead objects, compacts reclaimed memory into large free chunk and cycle continues.

    In other words allocation failure - is totally normal situation for JVM.

    In really, things are slightly more complicated. There are two parts of heap (young and old spaces), thread local allocation buffers etc.