简体   繁体   English

声纳java.lang.OutOfMemoryError:PermGen空间

[英]Sonar java.lang.OutOfMemoryError: PermGen space

I'm getting the following error when running a build in ant 在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 ie is it the sonar server or the client etc ? 有没有办法让我确切地知道此错误的出处,即声纳服务器或客户端等?

Here is line 39 of my buildcallbanks.xml 这是我的buildcallbanks.xml的第39行

<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. 编辑:我尝试从Sonar中的wrapper.conf增加permsize,无论我将其设置多高,我仍然会遇到相同的问题。 I must still be missing something? 我一定还想念什么吗?

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 您使用的是JAVA_OPTS而不是ANT_OPTS
  2. CMSClassUnloadingEnabled is only used if you also use UseConcMarkSweepGC. 仅当您还使用UseConcMarkSweepGC时,才使用CMSClassUnloadingEnabled。 See here: CMSPermGenSweepingEnabled vs CMSClassUnloadingEnabled 参见此处: CMSPermGenSweepingEnabled与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. 实际上,您不需要弄乱GC设置,而只需弄乱内存。 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. 希望这对其他人有帮助。

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. 您只需要重新配置ant使用的Java运行时,就可以增加对PermGen空间的限制。 This wiki page documents how to achieve this. Wiki页面记录了如何实现此目的。 Basically, you set the ANT_OPTS environment variable. 基本上,您可以设置ANT_OPTS环境变量。

Instead of increasing the heap size, try increasing the permgen size. 与其增加堆大小,不如尝试增加permgen大小。 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. 默认大小为64 MB,因此此设置应将最大可用内存增加一倍。

The PermGen memory is used for things that don't change often while running the JVM, like class definitions. PermGen内存用于运行JVM时不经常更改的内容,例如类定义。

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. 这个问题似乎是由于在Bamboo的“汇编”阶段运行了太多的蚂蚁目标引起的。 I am now running 'clean all production' followed by a call to the ant sonar plugin .jar. 我现在正在运行“清理所有产品”,然后调用蚂蚁声纳插件.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 此问题已通过以下JVM参数修复:-XX:+ CMSClassUnloadingEnabled

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM