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.
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

    July 2010
    M T W T F S S
    « Nov    
     1234
    567891011
    12131415161718
    19202122232425
    262728293031