Skip to content

Commit 75732a9

Browse files
kaeawcALikhachevsarahhaggarty
authored
Kotlin daemon JVM args - clearing up inheritance and defaults (#4454)
* add notes about jvm inheritance and defaults for kotlin daemon * Update docs/topics/gradle/gradle-compilation-and-caches.md Co-authored-by: Alex Likhachev <[email protected]> * Update docs/topics/gradle/gradle-compilation-and-caches.md Co-authored-by: Alex Likhachev <[email protected]> * remove arg that is not actually a default * apply Writerside update for callouts * Apply suggestions from code review Co-authored-by: Sarah Haggarty <[email protected]> --------- Co-authored-by: Alex Likhachev <[email protected]> Co-authored-by: Sarah Haggarty <[email protected]>
1 parent 263f279 commit 75732a9

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

docs/topics/gradle/gradle-compilation-and-caches.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,23 @@ Each of the following ways to set arguments overrides the ones that came before
163163

164164
#### Gradle daemon arguments inheritance
165165

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

168169
```none
169-
org.gradle.jvmargs=-Xmx1500m -Xms500m
170+
org.gradle.jvmargs=-Xmx1500m -Xms500m -XX:MaxMetaspaceSize=1g
170171
```
171172

173+
These arguments are then added to the Kotlin daemon's JVM arguments:
174+
175+
```none
176+
-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
177+
```
178+
179+
> 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).
180+
>
181+
{style="note"}
182+
172183
#### kotlin.daemon.jvm.options system property
173184

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

213+
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`:
214+
215+
```none
216+
-Xmx1500m -XX:ReservedCodeCacheSize=320m -Xms500m
217+
```
218+
202219
#### kotlin extension
203220

204221
You can specify arguments in the `kotlin` extension:
@@ -265,7 +282,24 @@ When configuring the Kotlin daemon's JVM arguments, note that:
265282
> even if other requested JVM arguments are different, this daemon will be reused instead of starting a new one.
266283
>
267284
{style="note"}
268-
* If the `Xmx` argument is not specified, the Kotlin daemon will inherit it from the Gradle daemon.
285+
286+
If the following arguments aren't specified, the Kotlin daemon inherits them from the Gradle daemon:
287+
288+
* `-Xmx`
289+
* `-XX:MaxMetaspaceSize`
290+
* `-XX:ReservedCodeCacheSize`. If not specified or inherited, the default value is `320m`.
291+
292+
The Kotlin daemon has the following default JVM arguments:
293+
* `-XX:UseParallelGC`. This argument is only applied if no other garbage collector is specified.
294+
* `-ea`
295+
* `-XX:+UseCodeCacheFlushing`
296+
* `-Djava.awt.headless=true`
297+
* `-D{java.servername.property}={localhostip}`
298+
* `--add-exports=java.base/sun.nio.ch=ALL-UNNAMED`. This argument is only applied for JDK versions 16 or higher.
299+
300+
> 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.
301+
>
302+
{style="note"}
269303

270304
## Rolling back to the previous compiler
271305

0 commit comments

Comments
 (0)