JAVA OOM – A troubleshooting runbook
This post is completely about out of memory(OOM) issues that causes app crashes , request failures for any java based applications including spring-boot, vert.x, spark .
Let us first understand how JVM process that is running our application acquires memory from the Hardware using the Operating System.
Every Java application is nothing but a single process for Operating System with Java Virtual Machine as additional executable code .
So to put it in simple terms,
A process for operating system to execute our code with java virtual machine support
.
While any process can have it’s own logic to acquire required memory for execution or rely on operating system , the java based processes use the former one using some arguments which can be overridden by the user .
Here are the list of such arguments from Java .
-Xms set initial Java heap size
-Xmx set maximum Java heap size
As java mainly uses heap for object management, we will focus more on this in this post.
Now let’s focus on the main issue , So What Causes JAVA OOM ?
Before we dive into it, let us first recall the facts from few memory management capabilities of JVM .
- Any java process has it’s own logic to cleanup the unused heap memory frequently using Garbage collector.
- Heap memory internally has areas like Younger Generation, Old Generation, Eden etc…
During the runtime of a java application , there are various ways java heap memory can go beyond the limits set by above parameters .
- Total heap usage is higher than the -Xmx value passed during the submission.
- Gradual increase of heap memory usage due to pile up of referenced objects that garbage collector cannot cleanup.
- Sudden increase in the number of object creations at a faster pace than garbage collector frequency .
- Single object loading something bigger than the actual heap memory available.
- Some java in-built object like ArrayList unable to acquire memory that needs continuous slot within the heap space.
