Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin daemon JVM args - clearing up inheritance and defaults #4454

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions docs/topics/gradle/gradle-compilation-and-caches.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,23 @@ Each of the following ways to set arguments overrides the ones that came before

#### Gradle daemon arguments inheritance

If nothing is specified, the Kotlin daemon inherits arguments from the Gradle daemon. For example, in the `gradle.properties` file:
By default, the Kotlin daemon inherits a specific set of arguments from the Gradle daemon but overwrites them with any
JVM arguments specified directly for the Kotlin daemon. For example, if you add the following JVM arguments in the `gradle.properties` file:

```none
org.gradle.jvmargs=-Xmx1500m -Xms500m
org.gradle.jvmargs=-Xmx1500m -Xms500m -XX:MaxMetaspaceSize=1g
```

These arguments are then added to the Kotlin daemon's JVM arguments:

```none
-Xmx1500m -XX:ReservedCodeCacheSize=320m -XX:MaxMetaspaceSize=1g -XX:UseParallelGC -ea -XX:+UseCodeCacheFlushing -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 --add-exports=java.base/sun.nio.ch=ALL-UNNAMED
```

> To learn more about the Kotlin daemon's default behavior with JVM arguments, see [Kotlin daemon's behavior with JVM arguments](#kotlin-daemon-s-behavior-with-jvm-arguments).
>
{style="note"}

#### kotlin.daemon.jvm.options system property

If the Gradle daemon's JVM arguments have the `kotlin.daemon.jvm.options` system property – use it in the `gradle.properties` file:
Expand Down Expand Up @@ -199,6 +210,12 @@ You can add the `kotlin.daemon.jvmargs` property in the `gradle.properties` file
kotlin.daemon.jvmargs=-Xmx1500m -Xms500m
```

Note that if you don't specify the `ReservedCodeCacheSize` argument here or in Gradle's JVM arguments, the Kotlin Gradle plugin applies a default value of `320m`:

```none
kaeawc marked this conversation as resolved.
Show resolved Hide resolved
-Xmx1500m -XX:ReservedCodeCacheSize=320m -Xms500m
```

#### kotlin extension

You can specify arguments in the `kotlin` extension:
Expand Down Expand Up @@ -265,7 +282,24 @@ When configuring the Kotlin daemon's JVM arguments, note that:
> even if other requested JVM arguments are different, this daemon will be reused instead of starting a new one.
>
{style="note"}
* If the `Xmx` argument is not specified, the Kotlin daemon will inherit it from the Gradle daemon.

If the following arguments aren't specified, the Kotlin daemon inherits them from the Gradle daemon:

* `-Xmx`
* `-XX:MaxMetaspaceSize`
* `-XX:ReservedCodeCacheSize`. If not specified or inherited, the default value is `320m`.

The Kotlin daemon has the following default JVM arguments:
* `-XX:UseParallelGC`. This argument is only applied if no other garbage collector is specified.
* `-ea`
* `-XX:+UseCodeCacheFlushing`
* `-Djava.awt.headless=true`
* `-D{java.servername.property}={localhostip}`
* `--add-exports=java.base/sun.nio.ch=ALL-UNNAMED`. This argument is only applied for JDK versions 16 or higher.

> The list of default JVM arguments for the Kotlin daemon may vary between versions. You can use a tool like [VisualVM](https://visualvm.github.io/) to check the actual settings of a running JVM process, like the Kotlin daemon.
>
{style="note"}

## Rolling back to the previous compiler

Expand Down
Loading