OutOfMemoryError: PermGen space

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

Running a build with Clover results in OutOfMemory error (usually during test execution):

java.lang.OutOfMemoryError: PermGen space

Cause

Possible causes are:

1) Insufficient memory allocation for PermGen

PermGen space keeps class definitions. Due to a fact that:

  • Clover generates one helper class for every top-level class being instrumented and
  • Clover adds extra method call for every method, statement and branch in your original code

the memory requirement for PermGen space grows up. How much? It's roughly:

  • for helper classes - 3kB * number of classes in your app
  • for instrumented classes - 2 * original class size

Therefore, doubling PermGen size is usually sufficient.

 

2) Memory leak in PermGen space

This can happen when you have a long running process (such us an application server) and you deploy multiple times a new version of an application into it (without restarting the process). It can happen that classes from old application will not be deallocated. See this article for more details: http://plumbr.eu/blog/what-is-a-permgen-leak.

Resolution

The required memory can be increased by setting the -XX:MaxPermSize setting on the JVM. Add proper toggle for 'java' command call or set JAVA_OPTS, ANT_OPTS, MAVEN_OPTS depending on the build tool you use.

Forking Processes

It's important to note that some Maven plugins (such as Surefire or Failsafe) will fork the JVM process and MAVEN_OPTS may not take effect. If you are experiencing issues using Maven plugins even after you've set MAVEN_OPTS for your build, you will likely need to set the -XX:MaxPermSize setting in the respective plugin configurations.

 

Example for maven-surefire-plugin

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Xmx512m -XX:MaxPermSize=256m</argLine>
  </configuration>
</plugin>

 

Example for maven-cargo-plugin

If you are using the Maven Cargo plugin, add the following in the <systemProperties/> element of the Maven Cargo plugin:

<cargo.jvmargs>-Xmx512m -XX:MaxPermSize=256m</cargo.jvmargs>

 

 

Last modified on Sep 2, 2015

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.