Govind Singh
Govind Singh

Reputation: 15490

java.lang.OutOfMemoryError: PermGen space in play framework

Edit:- play ~run to run my project

how to remove this problem, my project is in testing phase. daily after 5-6 hour it stops suddenly and giving the below error. what to do to remove this error?
i am developing this project in scala 2.1 with playframework 2.2

    java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
Caused by: java.lang.OutOfMemoryError: PermGen space
    at sun.misc.Unsafe.defineClass(Native Method)
    at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
    at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
    at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:396)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:395)
    at sun.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:113)
    at sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:331)
    at java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1376)
    at java.io.ObjectStreamClass.access$1500(ObjectStreamClass.java:72)
    at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:493)
    at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:468)
    at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365)
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:602)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1706)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1344)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
[error] Total time: 11065 s, completed 8 Feb, 2014 6:12:52 PM
1. Waiting for source changes... (press enter to interrupt)

java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 4 s, completed 8 Feb, 2014 6:12:57 PM
2. Waiting for source changes... (press enter to interrupt)

java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 4 s, completed 8 Feb, 2014 6:13:08 PM
3. Waiting for source changes... (press enter to interrupt)

java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 6 s, completed 8 Feb, 2014 6:13:54 PM
4. Waiting for source changes... (press enter to interrupt)
[error] Expected letter
[error] Expected symbol
[error] Expected '!'
[error] Expected '+'
[error] Expected '++'
[error] Expected ';'
[error] Expected end of input.
[error] Expected 'show'
[error] Expected '*'
[error] Expected '{'
[error] Expected project ID
[error] Expected configuration
[error] Expected key
[error] 9000
[error] ^
sbt appears to be exiting abnormally.
  The log file for this session is at /tmp/sbt7580663022166474466.log
java.lang.OutOfMemoryError: PermGen space
Error during sbt execution: java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-125" java.lang.OutOfMemoryError: PermGen space

Upvotes: 8

Views: 9589

Answers (5)

eliasah
eliasah

Reputation: 40360

I had the same problem so I exported the SBT_OPTS as followed :

export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:PermSize=512M -XX:MaxPermSize=1024M"

Upvotes: 9

Alex Kartishev
Alex Kartishev

Reputation: 1856

You can use jconsole.exe, that is part of JDK, to see the tendency, how PermGen size is increasing. May be it increases at certain time intervals, thus it will be easier for you to debug. Also, try increasing PermGen size: Increase permgen space . But if the problem is in code, it won't help for a long time...

Upvotes: -1

helderdarocha
helderdarocha

Reputation: 23637

Your code generates many classes. Classes are stored in the PermGen space and are never garbage collected (prior to Java 8). You can increase your PermGen space using the -XXMaxPermSize option when you run the JVM, for example:

-XX:MaxPermSize=512M

Using -Xmx or -Xms (heap space) don't work because this is a different space.

You can also use a Java 8 JVM because it doesn't use PermGen anymore.

Upvotes: 2

yǝsʞǝla
yǝsʞǝla

Reputation: 16412

In general it means you didn't give enough memory to your JVM or you have a memory leak. See how people address such problems here: Dealing with "java.lang.OutOfMemoryError: PermGen space" error or search for non-play specific error: "java.lang.OutOfMemoryError: PermGen".

Looking at your log I noticed that you are probably running it from SBT or some other build tool like Maven ("Waiting for source changes..."). To help SBT prevent memory leaks you can add these arguments when you lunch it:

java -Xms128M -Xmx1200M -Xss20M -XX:MaxPermSize=1200m -XX:+CMSClassUnloadingEnabled -jar `dirname $0`/sbt-launch.jar "$@"

Note the class unloading command line arg. In general I noticed that apps running in SBT still manage to leak resources no matter what you do, but in production it does not happen. You could try to run in a forked JVM mode to help SBT - see SBT-Revolver plugin for example. If you want to really know how your application consumes memory and whether it has memory leaks run it outside of a build tool, i.e. deploy it to container like Tomcat or run a jar or what have you. You can attach tools like jconsole to observe memory usage.

Upvotes: 3

duffymo
duffymo

Reputation: 308733

Start by increasing your perm gen size when you start the JVM.

Profile your code and find out why perm gen is being consumed.

Look for collections that never release references, deeply recursive tasks, etc.

Upvotes: 2

Related Questions