Java OutOfMemoryError – A tragedy in seven acts

12 Comments

One day every professional Java programmer will suffer from this exception thrown by his Java application: java.lang.OutOfMemoryError.

With a little luck this error will occur during development of the application – if not and it happens in a production environment, you will quickly get a lot of unintentional attention by your management, as a Java OutOfMemoryError normally means that you had an application crash! The reasons for these memory problems in the Java Virtual Maschine are versatile and in many cases not easys to analyze. In our troubleshooting services we see workarounds for these errors every day: Servers are preventevly restarted every night as the heap gets closer and closer to its limits or – even worse – the application regulary crashes with an java.lang.OutOfMemoryError indicating that the hunger of the JVM for more memory was bigger than the available heap.

As 64bit JVMs are getting more and more available in production environments, this seems as a perfect solution for theses kind of problems, as more adressable memory means bigger heaps and less frequent crashes. This is why I see that heaps in production are moving to the GB-area without thinking about the consequences: Less performance and troughput, because of more Garbage Collection overhead and pause times. Even worse if the Java OutOfMemoryError had nothing to do with the heap size…

Our performamce study has shown that memory problems are under the most critical problems with regard to stability and performance of Java applications. Almost 50% of the 250 questioned Java specialists answered, that Java Memory Management is critical for the performance and stability of their application. I think that it is time to write a comprehensive guide to the Java Memory Model inclusing tools and methods for anlyzing Java OutOfMemory errors and this is what this blog series is about.

I am calling this series “Java OutOfMemoryError – A tragedy in seven acts”, as I liked the definition of “tragic” in the German Wikipedia entry for “tragedy”, as it says that in the context of a tradegy the word “tragic” is not used in the sense of “sad” but in the sense that somebody gets blameless guilty.

In my opinion this is often true for developers that are responsible for Java OutOfMemoryError – they get blameless guilty. In my troubleshooting sessions I often see that managers are more interested in finding the person who is responsible for the problem than in finding the reason for the problem – this is sad and I hope that I will help the readers of this blog to better understand the reasons for OutOfMemory errors and give them the right knowledge to avoid them or if they have already occured, to quickly find and resolve them.

This is an overview of my Java Memory Tragedy:

1. Act – The Java Memory Architecture.
The first part of this series will introduce the memory architecture inside the Java Virtual Maschine in detail and will explain where and when java.lang.OutOfMemoryError can occur.

2. Act – Java Memory Leaks et al.

The second part of the series will cover the reasons for java.lang.OutOfMemoryError in detail – especially Java Memory Leaks and high, temporary memory consumption.

3. Act – JVM Monitoring and Configuration

The third part of the series will describe the parameters to configure the JVMs memory areas and show tools to monitore these parameters at runtime. As the parameter are different between JVM vendors and implementation, this blog entry will focus on the Sun HotSpot JVM.

4. Act – Creating and understanding Java Heapdumps

The fourth part of the series will show how to generate Heapdumps with the Sun HotSpot JVM and how to analyze these dumps.

5. Act – Runtime Analyzis of the Java Heap.

The fifth part of the series will cover tools and methods to analyze objects on the Java Heap at runtime, especially to find high memory allocation hotspots and slow growing memory leaks.

6. Act – Typical Java Memory problems

The sixth part of the series will show you typical Java OutOfMemoryError scenarios in practise. I will show you real examples and describe how to analyze and fix these problems by applying the tools and rules of the last 5 parts of this series.

7. Act – Summary and Outlook

 

 

The last part of the series will summarize the whole series and will give you an outlook to the next tragedy I am planning to write: The Java Garbage Collector.

Author

Mirko Novakovic

Share on FacebookGoogle+Share on LinkedInTweet about this on TwitterShare on RedditDigg thisShare on StumbleUpon

Kommentare

  • Here is some examples I wrote for OOM,u can download these examples from http://blog.bluedavy.com/jvm/cases/oom/OOMCases.zip

  • October 11, 2010 von Rohit M

    Hi Mirko,

    I’ve read your first act of the series. What about the rest of them? Do pen them down when you get time. Would be great to have such knowledge shared.

    Thanks.

  • October 11, 2010 von Mirko Novakovic

    Hi Rohit,

    have this on my list for month now, but thank you for the reminder. Will try to publish the second and third part soon, as they are already there as a “draft”.

    Mirko

  • December 28, 2010 von Nuwan Arambage

    Hi Mirko,

    superb article, it clears most of the things what not clear to me.Looking forward to see other articles in future

  • March 14, 2011 von Peter W

    Very good series. If you publish a book about all of this, I absolutely buy it.

  • Now that you made it to DZone and Twitter you really need to finish up this series :)

    May be you didn’t noticed: http://dzone.com/RN9v

    • July 27, 2011 von Mirko Novakovic

      Your are right – the 4th entry is already in a draft and Fabian and I are ready to finish the series in the next weeks :-)

  • July 28, 2011 von Theo Stauffer

    This is nitpicking, but you wrote “even worth” twice in that article where you meant “even worse”. I presume this was a spelling checker?

    • July 28, 2011 von Mirko Novakovic

      Theo, thank you – just corrected it. Was not a spelling checker but my bad English :-)

  • so how does the tragedy ends? 😛 when are the last two articles due?

  • March 18, 2014 von rohan

    When are the last two articles due?..
    feels like novel is complete and please upload those too

Comment

Your email address will not be published. Required fields are marked *