scala 如何防止 java.lang.OutOfMemoryError: PermGen space?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15957183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent java.lang.OutOfMemoryError: PermGen space?
提问by missingfaktor
I am frequently getting an OutOfMemoryErrorfrom SBT.
我经常收到OutOfMemoryError来自 SBT 的邮件。
> test
[error] java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
[error] Use 'last' for the full log.
> last
[debug] Running task... Cancelable: false, check cycles: false
[debug]
[debug] Initial source changes:
[debug] removed:Set()
[debug] added: Set()
[debug] modified: Set()
[debug] Removed products: Set()
[debug] Modified external sources: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated sources: Set()
[debug]
[debug] Sources indirectly invalidated by:
[debug] product: Set()
[debug] binary dep: Set()
[debug] external source: Set()
[debug] Initially invalidated: Set()
[debug] Copy resource mappings:
[debug]
[debug]
[debug] Initial source changes:
[debug] removed:Set()
[debug] added: Set()
[debug] modified: Set()
[debug] Removed products: Set()
[debug] Modified external sources: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated sources: Set()
[debug]
[debug] Sources indirectly invalidated by:
[debug] product: Set()
[debug] binary dep: Set()
[debug] external source: Set()
[debug] Initially invalidated: Set()
[debug] Copy resource mappings:
[debug]
[debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present.
[debug] Framework implementation 'org.specs.runner.SpecsFramework' not present.
[debug] Framework implementation 'org.scalatest.tools.ScalaTestFramework' not present.
[debug] Framework implementation 'com.novocode.junit.JUnitFramework' not present.
[debug] Subclass fingerprints: Stream((org.specs2.specification.SpecificationStructure,false,org.specs2.runner.Fingerprints$$anon@34d6488c), ?)
[debug] Annotation fingerprints: Stream()
[debug] Running Test ExpandoObjectTest : subclass(false, org.specs2.specification.SpecificationStructure) with arguments
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at sbt.ConcurrentRestrictions$$anon.take(ConcurrentRestrictions.scala:196)
at sbt.Execute.next(Execute.scala:85)
at sbt.Execute.processAll(Execute.scala:88)
at sbt.Execute.runKeep(Execute.scala:68)
at sbt.EvaluateTask$.run(EvaluateTask.scala:162)
at sbt.EvaluateTask$.runTask(EvaluateTask.scala:177)
at sbt.Aggregation$$anonfun.apply(Aggregation.scala:46)
at sbt.Aggregation$$anonfun.apply(Aggregation.scala:44)
at sbt.EvaluateTask$.withStreams(EvaluateTask.scala:137)
at sbt.Aggregation$.runTasksWithResult(Aggregation.scala:44)
at sbt.Aggregation$.runTasks(Aggregation.scala:59)
at sbt.Aggregation$$anonfun$applyTasks.apply(Aggregation.scala:31)
at sbt.Aggregation$$anonfun$applyTasks.apply(Aggregation.scala:30)
at sbt.Command$$anonfun$applyEffect$$anonfun$apply.apply(Command.scala:62)
at sbt.Command$$anonfun$applyEffect$$anonfun$apply.apply(Command.scala:62)
at sbt.Command$.process(Command.scala:90)
at sbt.MainLoop$$anonfun$next$$anonfun$apply.apply(MainLoop.scala:71)
at sbt.MainLoop$$anonfun$next$$anonfun$apply.apply(MainLoop.scala:71)
at sbt.State$$anon.process(State.scala:170)
at sbt.MainLoop$$anonfun$next.apply(MainLoop.scala:71)
at sbt.MainLoop$$anonfun$next.apply(MainLoop.scala:71)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.MainLoop$.next(MainLoop.scala:71)
at sbt.MainLoop$.run(MainLoop.scala:64)
at sbt.MainLoop$$anonfun$runWithNewLog.apply(MainLoop.scala:53)
at sbt.MainLoop$$anonfun$runWithNewLog.apply(MainLoop.scala:50)
at sbt.Using.apply(Using.scala:25)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:50)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:33)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:17)
at sbt.MainLoop$.runLogged(MainLoop.scala:13)
at sbt.xMain.run(Main.scala:26)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sbt.Project$$anon.apply(Project.scala:130)
at sbt.Project$$anon.apply(Project.scala:128)
at sbt.LogManager$.commandBase(LogManager.scala:59)
at sbt.LogManager$.command(LogManager.scala:60)
at sbt.LogManager$$anonfun$suppressedMessage.apply(LogManager.scala:61)
at sbt.LogManager$$anonfun$suppressedMessage.apply(LogManager.scala:61)
at sbt.ConsoleLogger.trace(ConsoleLogger.scala:163)
at sbt.AbstractLogger.log(Logger.scala:32)
at sbt.MultiLogger$$anonfun$dispatch.apply(MultiLogger.scala:40)
at sbt.MultiLogger$$anonfun$dispatch.apply(MultiLogger.scala:38)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at sbt.MultiLogger.dispatch(MultiLogger.scala:38)
at sbt.MultiLogger.trace(MultiLogger.scala:30)
at sbt.TestLogger$$anon.trace(TestReportListener.scala:71)
at sbt.TestLogger.endGroup(TestReportListener.scala:88)
at sbt.TestRunner$$anonfun$run.apply(TestFramework.scala:87)
at sbt.TestRunner$$anonfun$run.apply(TestFramework.scala:87)
at sbt.TestFramework$$anonfun$safeForeach.apply(TestFramework.scala:112)
at sbt.TestFramework$$anonfun$safeForeach.apply(TestFramework.scala:112)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
[error] java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
[error] Use 'last' for the full log.
Sometimes it also exits abruptly with:
有时它也会突然退出:
sbt appears to be exiting abnormally.
The log file for this session is at /var/folders/vf/3khb58091wd0_1rz1yh6knb00000gp/T/sbt3242766352271599341.log
java.lang.OutOfMemoryError: PermGen space
Error during sbt execution: java.lang.OutOfMemoryError: PermGen space
Any solutions?
任何解决方案?
回答by axel22
This sometimes happens if you compile huge codebases - a lot of classes get loaded into the VM running sbt.
如果您编译庞大的代码库,有时会发生这种情况 - 许多类被加载到运行 sbt 的 VM 中。
You need to increase the PermGenspace for sbt - use the flag -XX:MaxPermSize=256m, where 256you can change with the desired size of the permanent generation.
您需要增加PermGensbt的空间 - 使用标志-XX:MaxPermSize=256m,256您可以在其中更改永久代的所需大小。
Run:
跑:
cat `which sbt`
to locate you sbt startup script. Then edit it to include the flag with the javacommand that runs the sbt launcher in the similar way as it is described herefor modifying -Xmxand -Xms.
找到你的 sbt 启动脚本。然后编辑它以包含java运行 sbt 启动器的命令的标志,其方式与此处描述的修改-Xmx和-Xms.
Adding the -XX:+CMSClassUnloadingEnabledflag should also enable sbt to unload the classloaders with classes from the previous compilation runs that are no longer being used.
添加该-XX:+CMSClassUnloadingEnabled标志还应该使 sbt 能够卸载带有不再使用的先前编译运行的类的类加载器。
EDIT:
编辑:
Alternatively, you can set these options in the SBT_OPTSenvironment variable if you are using the extended script for running sbt.
或者,SBT_OPTS如果您使用扩展脚本来运行 sbt,则可以在环境变量中设置这些选项。

