Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.OutOfMemoryError GC overhead limit exceeded vs Java heap space?

What java.lang.OutOfMemoryError: Java heap space means That message means when the application just requires more Java heap space than available to it to operate normally.

What java.lang.OutOfMemoryError: GC overhead limit exceeded means This message means that for some reason the garbage collector is taking an excessive amount of time (by default 98% of all CPU time of the process) and recovers very little memory in each run (by default 2% of the heap). This internally also mean that when the application just requires more Java heap space than available to it to operate normally.

So my question is which scenario out of the above two will be triggered?

So here is my understanding when a specific exception will be thrown based on a scenario:-

Say I have allocated 1GB of heap size. Currently in use heap memory is 970 MB. A thread started(JVM does not know upfront how much memory it will be consuming). Now there GC can take one of the below steps

1) JVM starts allocating the memory and then at one point of time it exhaust 1GB of mem and throws java.lang.OutOfMemoryError: Java heap space

2) GC runs in advance and tries to free some memory as it knows currently in use memory is close to 1 GB allocated, Heap. But it's not able to free more than 2% of space in each subsequent run. Then it will throw java.lang.OutOfMemoryError: GC overhead limit exceeded

Is my understanding correct in the context of my question?

like image 210
M Sach Avatar asked Dec 17 '15 08:12

M Sach


1 Answers

OutOfMemoryError: Java heap space

There is no way for the JVM to satisfy an allocation request, even after performing all last-ditch efforts at its disposal.

OutOfMemoryError GC overhead limit exceeded

Means that the JVM might be able to satisfy an allocation request, but in the recent past it has to GC so often that the amount of CPU time spent on GCing exceeded a (configurable) fraction of overall CPU time used by the java process.

The JVM self-terminates instead of lingering in a half-working, highly inefficient state that might only get worse over time.

Often disabling the GC overhead OOM would just result in a Java heap space OOM a few minutes later.

It's basically a fail-fast mechanism.

like image 179
the8472 Avatar answered Oct 20 '22 02:10

the8472