csilk
csilk

Reputation: 188

Sonar java.lang.OutOfMemoryError: PermGen space

I'm getting the following error when running a build in ant

buildcallbacks.xml:39: org.sonar.runner.RunnerException: java.lang.OutOfMemoryError: PermGen space

It's the part of the build where sonar runs over our code.

Is there a way for me to know exactly where this error is coming from i.e is it the sonar server or the client etc ?

Here is line 39 of my buildcallbanks.xml

<sonar:sonar />

EDIT: I've tried increasing the permsize from the wrapper.conf within Sonar and I still get the same issue no matter how high I set it. I must still be missing something?

Upvotes: 1

Views: 8681

Answers (4)

kabadisha
kabadisha

Reputation: 720

I actually went back to look at this after you - it was still failing. You were nearly there but I found two things:

  1. You had used JAVA_OPTS instead of ANT_OPTS
  2. CMSClassUnloadingEnabled is only used if you also use UseConcMarkSweepGC. See here: CMSPermGenSweepingEnabled vs CMSClassUnloadingEnabled

So the settings that seem to be working a treat now are:

ANT_OPTS="-Xmx1024m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=512m"

UPDATE: Years later I have actually re-visited this again as the problem reoccurred. You don't actually need to mess with the GC settings, just the memory. The correct options to use are in fact:

ANT_OPTS="-Xmx2G -XX:MaxPermSize=1G"

Obviously you can tweak the memory values to suit your machine.

Hope this helps others.

Upvotes: 7

csilk
csilk

Reputation: 188

Increasing the permspace on the sonar server didn't seem to have any effect.

This issue seems to have been caused by running too many ant targets at the 'assembly' stage in Bamboo. I am now running 'clean all production' followed by a call to the ant sonar plugin .jar.

It also seems that classes weren't being unloaded when they should have been. This was fixed with the following JVM parameter: -XX:+CMSClassUnloadingEnabled

Upvotes: 0

Gijs Overvliet
Gijs Overvliet

Reputation: 2691

Instead of increasing the heap size, try increasing the permgen size. You can do this with

ANT_OPTS=-XX:MaxPermSize=128m

The default size is 64 MB, so this setting should double the maximum memory available.

The PermGen memory is used for things that don't change often while running the JVM, like class definitions.

Upvotes: 0

Marko Topolnik
Marko Topolnik

Reputation: 200148

This error is not caused by any specific line of code, so there would be no point in trying to locate it. You'll just have to reconfigure the Java runtime that ant uses so that the limit on the PermGen space is increased. This wiki page documents how to achieve this. Basically, you set the ANT_OPTS environment variable.

Upvotes: 1

Related Questions