Need help trying to stop daemon and re-use launcher JVM

Hello,

I’m trying to reduce memory consumption of the CI. Each build is isolated from each other so my assumption is the daemon isn’t useful in my case.

I’ve been trying to disable the daemon with no success.

Found a number of GitHub issues that explain what I need todo but I’ve had no success.

Here is my understanding.

To use the same launcher as the JVM running the build, several arguments including memory need to be set and matching.

If JAVA_OPTS and GRADLE_OPTS match org.gradle.jvmargs, the Daemon will not be used at all since the build happens inside the Gradle client JVM.

I ran my build with --debug flag and saw messages like this.

[DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Using daemon args: [/usr/lib/jvm/java-17-openjdk-amd64/bin/java, -XX:+HeapDumpOnOutOfMemoryError, -XX:+UseParallelGC, -XX:MaxMetaspaceSize=1g, --add-opens=java.base/java.util=ALL-UNNAMED, --add-opens=java.base/java.lang=ALL-UNNAMED, --add-opens=java.base/java.lang.invoke=ALL-UNNAMED, --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED, --add-opens=java.base/java.nio.charset=ALL-UNNAMED, --add-opens=java.base/java.net=ALL-UNNAMED, --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED, -Xmx6g, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, /home/circleci/.gradle/wrapper/dists/gradle-8.2-bin/5v5k04i8j0lvh6qn6n4ieidm0e/gradle-8.2/lib/gradle-launcher-8.2.jar, -javaagent:/home/circleci/.gradle/wrapper/dists/gradle-8.2-bin/5v5k04i8j0lvh6qn6n4ieidm0e/gradle-8.2/lib/agents/gradle-instrumentation-agent-8.2.jar]

And this

[INFO] [org.gradle.launcher.daemon.configuration.BuildProcess] Checking if the launcher JVM can be re-used for build. To be re-used, the launcher JVM needs to match the parameters required for the build process: -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx6g -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant

Based on that I need to set these options so they match.

  • -XX:+HeapDumpOnOutOfMemoryError
  • -XX:+UseParallelGC
  • -XX:MaxMetaspaceSize=1g
  • –add-opens=java.base/java.util=ALL-UNNAMED
  • –add-opens=java.base/java.lang=ALL-UNNAMED
  • –add-opens=java.base/java.lang.invoke=ALL-UNNAMED
  • –add-opens=java.prefs/java.util.prefs=ALL-UNNAMED
  • –add-opens=java.base/java.nio.charset=ALL-UNNAMED
  • –add-opens=java.base/java.net=ALL-UNNAMED
  • –add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED
  • -Xmx6g
  • -Dfile.encoding=UTF-8
  • -Duser.country=US
  • -Duser.language=en
  • -Duser.variant

I have attempted to set these options but I still see the daemon created.

Attempt 1

      GRADLE_OPTS: "-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g"

      JAVA_OPTS: "-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g"

Attempt 2

      GRADLE_OPTS: "-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant"

      JAVA_OPTS: "-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant"

I run gradle properties to see the properties are set and I see the same org.gradle.jvmargs

I still see this message in the build log

To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.2/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.

Thank you for reading. Please help me understand if I missed something.

GitHub Reference Links

Usually, it is not worth to try disabling the daemon.
Especially as the client JVM you start has only 64 MiB max heap by default.
Some JVM arguments are considered unchangeable so could not be set in the already started VM.
Those arguments you have to make sure are set in GRADLE_OPTS. (Setting both GRADLE_OPTS and JAVA_OPTS is useless, either-or is fine).
The arguments affected should usually be the heap settings, and since some versions (which was not the case in the old threads you probably found) the instrumentation agent.
You did not add the instrumentation agent in your tries, so it cannot reuse the existing JVM.

1 Like