OutOfMemoryError
VM Perm Out of memory fix
With Coldfusion and Railo applications making Java so easy it is not unusual that you can have 1,000′s of underlying java classes created and this can cause jvm OutOfMemoryError issues relating to the permanent generation space. The perm is like a big database of classes that are loaded in the JVM. Recently we have seen this happen on Railo a number of times, the problem is that by default a JVM garbage collection cycle does not collect permanent generation so it just keeps growing and eventually runs out of memory.
The Fix:
We need to add some arguments to the jvm.config file of the application server.
The standard garbage collector can’t collect in the permanent generation, but the concurrent collector can. So the first thing we need to do is to make sure that the jvm uses the concurrent garbage collector
-XX:+UseConcMarkSweepGC
But this is not enough.
We must also specifically tell it to collect in the permanent generation, and this is done with this command line argument:
-XX:+CMSPermGenSweepingEnabled
Good, now the concurrent collector will take the permantent generation under its wings.
But wait! Classes are special, and the jvm is reluctant to let go of them, so we must also explicitly allow classes to be unloaded:
-XX:+CMSClassUnloadingEnabled
Don’t forget to also give your perm memory a decent allocation of memory
-XX:MaxPermSize=256m
Thanks to Christian Vest Hansen for figuring this out.

I was recently involved in migrating all applications at my work from Coldfusion7 (running on JRUN with Windows) to Railo (running on JBoss within a Linux environment).

There were several teething issues, as can be expected. Most of them were minor except for one which kept giving us grief. This issue would cause our JBoss instances to drop dead, with a ‘Perm Gen OutOfMemory’ error being logged. After much research I found that this issue relates to the ‘permanent generation space’. (The what?!?).

Apparently, the perm is a storage area of classes that are loaded in the JVM.  It seems that the default garbage collection cycle we had configured within our jvm config file did not clear up permanent generation memory. Hence it just kept growing and growing, eventually running out of allocated memory.

This issue is quite common, but finding a cure was quite a pain in the A#@$!  All we had to do was add some arguments to the jvm.config file of the application server.

  1. Add ‘-XX:+UseConcMarkSweepGC’. This is specifing to use the concurrent collector instead of the standard one, which can’t collect in the permanent generation.
  2. Now add ‘-XX:+CMSPermGenSweepingEnabled’. This tells the collector to collect the perm gen.
  3. Finally add ‘-XX:+CMSClassUnloadingEnabled’. This tells the collector to allows Java classes to be unloaded.
  4. Ensure that you give your perm memory a decent allocation by adding the following line in your config file: ‘-XX:MaxPermSize=256m’.

This should, in theory, solve your Perm Gen OutOfMemory error. (Fingers crossed) :-)

Category: Java, Railo
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
6 Responses
  1. Wonderful post, numerous interesting points. I recall five of days ago, I have viewed a similar blog.

  2. Pretty great post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I am going to be subscribing for ones feed and I hope you post again soon.

  3. Thanks for the useful info. It’s so interesting.

  4. conveyancing says:

    Sorry, but I don’t agree with you here. I do not like that approach. But it’s a good start off. Perhaps with some increased information I could manage to understand it healthier?

  5. By the way… hardly awhile back I viewed this exact post on a different website. I have reason to believe someone pinched your article!

  6. Roneel says:

    @Chiropractor Scranton PA Info : Thanks for your confidence. I’ve always been meaning to start blogging consistently, but never had a chance. Your comments have encouraged me to get serious! :-)

    @conveyancing: I’m by no means an expert. What I’ve blogged is what I managed to find out via Google. I am open to the best approach and look forward to more comments from you.

    @Seo Techniques: Hmmm…damn buggers! Ah well, I shall take that as a compliment…I must have written something worth pinching :-)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Categories

  • Archives

  • Calendar

    September 2010
    M T W T F S S
    « Nov    
     12345
    6789101112
    13141516171819
    20212223242526
    27282930