161

Why always "GC (Allocation Failure)"?

Java HotSpot(TM) 64-Bit Server VM (25.25-b02) for linux-amd64 JRE (1.8.0_25-b17),

CommandLine flags: 
-XX:CMSInitiatingOccupancyFraction=60 
-XX:GCLogFileSize=10485760 
-XX:+HeapDumpOnOutOfMemoryError 
-XX:InitialHeapSize=32212254720 
-XX:MaxHeapSize=32212254720 
-XX:NewRatio=10 
-XX:OldPLABSize=16 
-XX:ParallelGCThreads=4 
-XX:+PrintGC 
-XX:+PrintGCDetails 
-XX:+PrintGCTimeStamps 
-XX:+PrintStringTableStatistics 
-XX:+PrintTenuringDistribution 
-XX:StringTableSize=1000003 
-XX:SurvivorRatio=4 
-XX:TargetSurvivorRatio=50 
-XX:+UseCompressedClassPointers 
-XX:+UseCompressedOops
-XX:+UseParNewGC 
-XX:+UseConcMarkSweepGC
27.329: [GC (Allocation Failure) 27.329: [ParNew
Desired survivor size 44728320 bytes, new threshold 15 (max 15)
- age   1:   16885304 bytes,   16885304 total
: 349568K->16618K(436928K), 0.2069129 secs] 349568K->16618K(31369920K), 0.2070712 secs] [Times: user=0.78 sys=0.04, real=0.21 secs]


28.210: [GC (Allocation Failure) 28.210: [ParNew
Desired survivor size 44728320 bytes, new threshold 15 (max 15)
- age   1:   28866504 bytes,   28866504 total
- age   2:   12582536 bytes,   41449040 total
: 366186K->47987K(436928K), 0.2144807 secs] 366186K->47987K(31369920K), 0.2146024 secs] [Times: user=0.84 sys=0.01, real=0.22 secs]


29.037: [GC (Allocation Failure) 29.038: [ParNew
Desired survivor size 44728320 bytes, new threshold 2 (max 15)
- age   1:   28443488 bytes,   28443488 total
- age   2:   28386624 bytes,   56830112 total
- age   3:   12579928 bytes,   69410040 total
: 397555K->76018K(436928K), 0.2357352 secs] 397555K->76018K(31369920K), 0.2358535 secs] [Times: user=0.93 sys=0.01, real=0.23 secs]
Hearen
  • 7,420
  • 4
  • 53
  • 63
user3644708
  • 2,466
  • 2
  • 16
  • 32

3 Answers3

239

"Allocation Failure" is a cause of GC cycle to kick in.

"Allocation Failure" means that no more space left in Eden to allocate object. So, it is normal cause of young GC.

Older JVM were not printing GC cause for minor GC cycles.

"Allocation Failure" is almost only possible cause for minor GC. Another reason for minor GC to kick could be CMS remark phase (if +XX:+ScavengeBeforeRemark is enabled).

Hearen
  • 7,420
  • 4
  • 53
  • 63
Alexey Ragozin
  • 8,081
  • 1
  • 23
  • 23
  • 1
    Thanks. Just find that the old JVM don't print Allocation Failure. – user3644708 Feb 06 '15 at 15:41
  • 5
    I do not get this answer fully, so is to be avoided or not? "it is normal cause of young GC". Is the young GC the wrong choice then? – Thomas Oct 28 '16 at 20:11
  • 8
    Yes, this is normal behaviour – Alexey Ragozin Oct 29 '16 at 14:01
  • 263
    GC (Allocation Failure) is a poor choice of words for an event that will occur normally many times a day. Those JVM engineers should go out more often and try to socialize in the real world so they can learn more friendly terms that people understand. – Salvador Valencia Feb 16 '17 at 20:29
  • 132
    @SalvadorValencia It's okay, people who read GC logs on a regular basis aren't exactly "normal" either. :) – biziclop Jul 11 '17 at 14:37
  • I've similar question related to GC allocation failure, we have JVM heap size set to 4GB(min and max) and planning to add option for new gen heap. What is the percentage of new gen to be allocated for the heap size of 4GB? – Saravanan G Jan 19 '18 at 17:57
  • 8
    @SalvadorValencia , believe it or not. If they could socialize they would have never touched GC. – Turkhan Badalov Jul 31 '19 at 16:40
  • How can we understand this allocation failure better and make sure our program doesn't have it anymore? Is it always memory leaks? How can this help us to trace the memory leaks? When is the allocation failure fatal (aka When will it kill the program?)? – Yannick Mussche Nov 09 '22 at 15:33
  • oh @SalvadorValencia how do you get away with it (sarcasm) when I never can – Gerry Apr 06 '23 at 16:45
14

"Allocation Failure" is cause of GC to kick

is not correct. It is an outcome of GC operation.

GC kicks in when there is no space to allocate( depending on region minor or major GC is performed). Once GC is performed, if space is freed all is good, but if there is not enough contiguous space there is still an issue. This is reported as "Allocation failure". Below document have good explanation https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc.html

symcbean
  • 47,736
  • 6
  • 59
  • 94
Kamal Rathod
  • 151
  • 1
  • 4
  • 2
    "(...) then an allocation failure occurs (because there is no space to allocate the live objects from the region being evacuated) and a stop-the-world (STW) full collection is done." - In java 1.8, server mode, I have reproduced a brief pause and both of these traces are printed together: [GC (Allocation Failure) 2287742K->1148645K(2633216K), 0.4571912 secs] [Full GC (Ergonomics) 1148645K->1112141K(3184128K), 2.8563984 secs]. So I upvote your answer ;-) – Jose Manuel Gomez Alvarez Jun 06 '19 at 17:58
  • So this message comes up because there is no enough space in the old generation or the new generation? – Amol Kshirsagar Oct 09 '22 at 14:22
  • I'm not sure, but I think both answers are true - looks to me like what you are talking about is a `Full GC (Allocation Failure)`, and what the other answer is referring to is a `GC (Allocation Failure)` (notice the `Full` in the first one). Couldn't find any solid references to this, so if someone can that would be amazing. – Aldahunter Jun 11 '23 at 17:50
-6

When use CMS GC in jdk1.8 will appeare this error, i change the G1 Gc solve this problem.

 -Xss512k -Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=70 -XX:NewRatio=1 -XX:SurvivorRatio=6 -XX:G1ReservePercent=10 -XX:G1HeapRegionSize=32m -XX:ConcGCThreads=6 -Xloggc:gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps 
Hatter Bush
  • 215
  • 1
  • 3
  • 15