17

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

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?

3
  • The follow up of this question is here Commented Dec 17, 2013 at 7:16
  • The link in your comment is broken. Commented Mar 17, 2021 at 17:30
  • I removed broken links as I don't have these pictures anymore. Commented Mar 17, 2021 at 23:04

2 Answers 2

36

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"
}
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you Peter! It's not a memory problem. I set Xmx to 2048 flight record. Now tne max used heap size during test is about 1.6GB, perm gen size is 512MB and during test it not more 70MB. I still get OutOfMemory error and can't locate it. In this tests I used H2 inmemory DB. Running unit tests via ant task for this module don't throw this error, all tests passed.
Also I see that for each test class ant run another JUnitRunner
4076 Xmx solved issue. However 540Mb max for ant JUninRunner vs 2.31Gb gradle JUnitRunner it's a little strange result.
For those using Java 8, XX:MaxPermSize was removed.
To be more specific: -XX:MaxPermSize turned into -XX:MaxMetaspaceSize
|
0

Basically, Gradle runs all test classes parallelly. Java11 default heap memory size is 256MB. This is not enough to run all the test classes parallelly. This causes “Java Out of Memory ” error. We can fix this by increasing heap memory in test run by adding the below code. If test case are more, we need to increase heap size more that what I have given.

We won't face this issue when we upgrade to JAVA17. Because , java17 will take 1/4 of the physical memory as heap memory

dependencies.gradle

test {
      minHeapSize = "256m" // initial heap size
      maxHeapSize = "1024m" // maximum heap size
      useJUnitPlatform()
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.