Saturday, August 05, 2006

Eclipse was hanging my machine regularly -- solution -XX:MaxPermSize=128m

I have quite some plugins installed in my eclipse installation. Since a few weeks, eclipse was running mad from time to time, my XP laptop was totally starving, I was not even able to get to the task manager to kill eclipse (keyboard and mouse barley reacted). The only solution was to kill my machine :-(.

Well, but how to find out who is the bad guy? Which of the many plugins I have installed "killing me"? I was using Stack Trace, a cool application that lets you attach to eclipse and get a stack trace.

Most of the time the stack traces of the wild application ended in:
 at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:160)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:498)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:468)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl

Hmm, the class loader puts the class files in a special area of the garbage collector, (perm generation). The starving (100 % CPU and being really bad) seemed to be caused by not enough memory in the perm space. To fix this, I added -vmargs -XX:MaxPermSize=128m to the shortcut that starts eclipse. That solved the problem! The sun default seems to be 64MB (I could not find information for java1.5).

But how much is the perm size really? How to find this out? Today, I found a blog entry by Igor Shabalov describing a cool tool called jconsole, that comes with jdk1.5.0, that allows you to inspect memory related information of your java applications life. All you have to do, it to add -Dcom.sun.management.jmxremote to the eclipse -vmargs. Then you can attach to eclipse and see life the different garbage collection pools and the loaded classes and threads -- pretty cool...

4 comments:

  1. Great info. AS it is Eclipse does not use much system resources anyway despite me using a whole bunch of open source and free Eclipse plugins. But more than afew times has Eclipse crashed on me when messing around with JSPs. Frustrating yes but it is probably because of a lot of plugins in my setup. What plugins do you use?

    ReplyDelete
  2. Also is it not possible to add the XX:MaxPermSize switch to the eclipse.ini file to make the safe effect?

    ReplyDelete
  3. Very useful tip about JConsole!

    Eclipse 3.2 is more hungry for PermGen space than 3.1 was, but if you're using Sun's JDK < 1.5.0_07, there's a PermGen leak which makes it worse - a known issue likely to burden Eclipse users.

    ReplyDelete
  4. FYI, forgetting the final 'm' in '128m' has a very different effect...

    ReplyDelete