JVM PermGen Space OutOfMemoryError

5 years ago by in Error, JVM, Tomcat Tagged: , , , ,

Error

Virgo (built on Tomcat) fails to deploy a module or execute anything due to a PermGen space error.

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: PermGen space
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:949)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
root cause java.lang.OutOfMemoryError: PermGen space
	java.lang.ClassLoader.defineClass1(Native Method)
	java.lang.ClassLoader.defineClass(ClassLoader.java:791)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
	org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.defineClass(KernelBundleClassLoader.java:240)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:607)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
	org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:464)
	org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:135)
	java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	java.lang.ClassLoader.defineClass1(Native Method)
	java.lang.ClassLoader.defineClass(ClassLoader.java:791)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
	org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.defineClass(KernelBundleClassLoader.java:240)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:607)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
	org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
	org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:464)
	org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)

Solution

Add the flag -XX:+CMSClassUnloadingEnabled to Virgo’s (or Tomcat) JVM arguments list. Following is a simple start script used to start Virgo, located at: C:\work\virgo.

SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_17
SET JAVA_OPTS= -XX:+CMSClassUnloadingEnabled
SET SERVER_HOME=C:\work\virgo

C:\work\virgo\bin\startup.bat %1

Here we are setting the -XX:+CMSClassUnloadingEnabled through the JAVA_OPTS.

Albert Attard

Albert Attard is a Java passionate and technical lead at a research group. You can find him on . Over the past years Albert worked on various Java projects including traditional server/client applications, modular applications, large data handling applications and concurrent data manipulation applications to name a few. He has a BSc degree from the University of London (Homepage) and an MSc Information Security with the same university. His MSc thesis (Book) received the 2012 SearchSecurity.co.UK award (Website).

Leave a Comment


Time limit is exhausted. Please reload the CAPTCHA.