Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GradleWorkerMain OutOfMemoryError

Tags:

gradle

I'm trying to gradling ant based (Netbeans RCP) project and finding the strange gradle behavior. I made some observation with profiler and get the next results.

Environment configuration

Gradle 1.9
Build time:   2013-11-19 08:20:02 UTC
Build number: none
Revision:     7970ec3503b4f5767ee1c1c69f8b4186c4763e3d

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_45 (Oracle Corporation 24.45-b08)
OS:           Linux 2.6.32-431.el6.x86_64 amd64

$ echo $GRADLE_OPTS
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Xms256m -Xmx2048m
$ echo $ANT_OPTS
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Xms256m -Xmx2048m
  • build.gradle - contains import for ant tasks (clean, build, unit tests)

  • settings.gradle

Running imported ant junit test tasks with gradle

Gradle fork separate jvm for this and run JUnitTestRunner with different Xmx value, ignoring $GRADLE_OPTS and $ANT_OPTS values

No idea how gradle define Xmx size for each JUnitTestRunner ant task. It works fine, as a GC during each tasks. All unit tests for all modules passed without errors.

Running gradle build tasks for the same modules

Gradle knows previous build results and immediately starting junit tests for untested module. You may see the output here! Gradle fork separate jvm (ignoring $GRADLE_OPTS value) for this and run GradleWorkerMain. And this jvm has 1.42GB Xmx and 500 MB immediately occupied! Then used memory size reaches 1.5GB. Then GC for unknown reason can't free memory and throw

-java.lang.OutOfMemoryError: GC overhead limit exceeded

-console log

Questions

  • why ant task max Xmx size in 540 MB enough for testing while for GradleWorkerMain 1.5GB is not enough?

  • I'm new to gradle so may be my build.gradle contains errors that result in such GradleWorkerMain strange behavior. Is it true? What possible solution is?

  • how to provide for GradleWorkerMain jvm more Xmx?

like image 684
senleft Avatar asked Dec 10 '13 09:12

senleft


1 Answers

To control how much memory is available to Gradle test JVMs, configure the corresponding Test tasks. For example:

test {
    maxHeapSize = "1024m"
    jvmArgs "-XX:MaxPermSize=256m"
}
like image 152
Peter Niederwieser Avatar answered Nov 05 '22 16:11

Peter Niederwieser