0

We are running Junits in linux server. All of the sudden we started getting permGen space issue. Below are the parameters we are using to set space. Default value of max perm size is 174063616

ANT_OPTS=-Xmx4098m
export ANT_OPTS

JAVA_OPTS=-Xmx16392m
export JAVA_OPTS

After getting permgen space issue, I have changed the value of parameters as mentioned below. But still no luck.

ANT_OPTS=-Xmx4098m
export ANT_OPTS

JAVA_OPTS=-Xmx32784m
export JAVA_OPTS
jon
  • 213
  • 1
  • 5
  • 18
  • Not sure about this but Xmx is for memory of instances. PermGen is memory about classes. You should increase MaxPermSize instead – Laurent Duvergé Nov 20 '19 at 18:40
  • You might want to look at [this answer](https://stackoverflow.com/a/3003986/524900) – Lolo Nov 21 '19 at 06:35
  • And also look at if the units tests are launched in a forked jvm. If forked, you should look at configuring the junit task in your build.xml – Nicolas Lalevée Nov 21 '19 at 11:38
  • yes Unit tests are launched in forked jvm. Can you help me with the command to configure PermGen size – jon Nov 21 '19 at 11:56

1 Answers1

1

If you have memory allocation errors related to the "permGen" space, it means you run with a Java 7 or inferior. So, as a side note, if you run a Java 8 or superior, you shouldn't see this error anymore since that space doesn't exist per se anymore and is only limited to the available native memory.

The JVM option to manage the PermGen space is XX:MaxPermSize. So you should add to the JVM with runs your unit tests this command line argument: -XX:MaxPermSize=256m.

The ANT_OPTS environement variable will configure the JVM used by Ant itself. You should use this environement variable if the unit tests are not ran as forked.

If you run your unit tests in a JVM forked by Ant, then you should tell Ant to start the Junit task with some additionnal JVM arguments. The parameter you need to use is jvmarg.

See the official Ant documentation about the task: https://ant.apache.org/manual/Tasks/junit.html

Thus, here is the piece of XML to set the proper property:

<junit fork="yes">
    <jvmarg value="-XX:MaxPermSize=256m" />
</junit>
Nicolas Lalevée
  • 2,014
  • 1
  • 15
  • 14