Inherit max metaspace size of client VM for Kotlin compile daemon
#KT-32521 In Progress
#KT-32950 Fixed
This commit is contained in:
+10
-7
@@ -187,13 +187,14 @@ fun Iterable<String>.filterExtractProps(vararg groups: OptionsGroup, prefix: Str
|
|||||||
data class DaemonJVMOptions(
|
data class DaemonJVMOptions(
|
||||||
var maxMemory: String = "",
|
var maxMemory: String = "",
|
||||||
var maxPermSize: String = "",
|
var maxPermSize: String = "",
|
||||||
|
var maxMetaspaceSize: String = "",
|
||||||
var reservedCodeCacheSize: String = "",
|
var reservedCodeCacheSize: String = "",
|
||||||
var jvmParams: MutableCollection<String> = arrayListOf()
|
var jvmParams: MutableCollection<String> = arrayListOf()
|
||||||
) : OptionsGroup {
|
) : OptionsGroup {
|
||||||
|
|
||||||
override val mappers: List<PropMapper<*, *, *>>
|
override val mappers: List<PropMapper<*, *, *>>
|
||||||
get() = listOf(StringPropMapper(this, DaemonJVMOptions::maxMemory, listOf("Xmx"), mergeDelimiter = ""),
|
get() = listOf(StringPropMapper(this, DaemonJVMOptions::maxMemory, listOf("Xmx"), mergeDelimiter = ""),
|
||||||
StringPropMapper(this, DaemonJVMOptions::maxPermSize, listOf("XX:MaxPermSize"), mergeDelimiter = "="),
|
StringPropMapper(this, DaemonJVMOptions::maxPermSize, listOf("XX:MaxPermSize"), mergeDelimiter = "="),
|
||||||
|
StringPropMapper(this, DaemonJVMOptions::maxMetaspaceSize, listOf("XX:MaxMetaspaceSize"), mergeDelimiter = "="),
|
||||||
StringPropMapper(this, DaemonJVMOptions::reservedCodeCacheSize, listOf("XX:ReservedCodeCacheSize"), mergeDelimiter = "="),
|
StringPropMapper(this, DaemonJVMOptions::reservedCodeCacheSize, listOf("XX:ReservedCodeCacheSize"), mergeDelimiter = "="),
|
||||||
restMapper)
|
restMapper)
|
||||||
|
|
||||||
@@ -279,11 +280,13 @@ fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
|||||||
val targetOptions = if (inheritMemoryLimits) opts else DaemonJVMOptions()
|
val targetOptions = if (inheritMemoryLimits) opts else DaemonJVMOptions()
|
||||||
val otherArgs = jvmArguments.filterExtractProps(targetOptions.mappers, prefix = "-")
|
val otherArgs = jvmArguments.filterExtractProps(targetOptions.mappers, prefix = "-")
|
||||||
|
|
||||||
if (inheritMemoryLimits && opts.maxMemory.isBlank()) {
|
if (inheritMemoryLimits) {
|
||||||
val maxMemBytes = Runtime.getRuntime().maxMemory()
|
if (opts.maxMemory.isBlank()) {
|
||||||
// rounding up
|
val maxMemBytes = Runtime.getRuntime().maxMemory()
|
||||||
val maxMemMegabytes = maxMemBytes / (1024 * 1024) + if (maxMemBytes % (1024 * 1024) == 0L) 0 else 1
|
// rounding up
|
||||||
opts.maxMemory = "${maxMemMegabytes}m"
|
val maxMemMegabytes = maxMemBytes / (1024 * 1024) + if (maxMemBytes % (1024 * 1024) == 0L) 0 else 1
|
||||||
|
opts.maxMemory = "${maxMemMegabytes}m"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inheritOtherJvmOptions) {
|
if (inheritOtherJvmOptions) {
|
||||||
@@ -365,7 +368,7 @@ private fun String.memToBytes(): Long? =
|
|||||||
|
|
||||||
|
|
||||||
private val daemonJVMOptionsMemoryProps =
|
private val daemonJVMOptionsMemoryProps =
|
||||||
listOf(DaemonJVMOptions::maxMemory, DaemonJVMOptions::maxPermSize, DaemonJVMOptions::reservedCodeCacheSize)
|
listOf(DaemonJVMOptions::maxMemory, DaemonJVMOptions::maxPermSize, DaemonJVMOptions::maxMetaspaceSize, DaemonJVMOptions::reservedCodeCacheSize)
|
||||||
|
|
||||||
infix fun DaemonJVMOptions.memorywiseFitsInto(other: DaemonJVMOptions): Boolean =
|
infix fun DaemonJVMOptions.memorywiseFitsInto(other: DaemonJVMOptions): Boolean =
|
||||||
daemonJVMOptionsMemoryProps
|
daemonJVMOptionsMemoryProps
|
||||||
|
|||||||
+15
@@ -1,8 +1,10 @@
|
|||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
||||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
import org.jetbrains.kotlin.gradle.util.modify
|
||||||
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -64,11 +66,24 @@ abstract class ExecutionStrategyIT : BaseGradleIT() {
|
|||||||
val strategyCLIArg = "-Dkotlin.compiler.execution.strategy=$executionStrategy"
|
val strategyCLIArg = "-Dkotlin.compiler.execution.strategy=$executionStrategy"
|
||||||
val finishMessage = "Finished executing kotlin compiler using $executionStrategy strategy"
|
val finishMessage = "Finished executing kotlin compiler using $executionStrategy strategy"
|
||||||
|
|
||||||
|
val isGradleAtLeast50 = project.testGradleVersionAtLeast("5.0")
|
||||||
|
|
||||||
project.build("build", strategyCLIArg) {
|
project.build("build", strategyCLIArg) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertContains(finishMessage)
|
assertContains(finishMessage)
|
||||||
checkOutput()
|
checkOutput()
|
||||||
assertNoWarnings()
|
assertNoWarnings()
|
||||||
|
|
||||||
|
if (executionStrategy == "daemon" && isGradleAtLeast50) {
|
||||||
|
val m = "Kotlin compile daemon JVM options: \\[(.*?)\\]".toRegex().find(output)
|
||||||
|
?: error("Could not find Kotlin compile daemon JVM options in Gradle's output")
|
||||||
|
val kotlinDaemonJvmArgs = m.groupValues[1].split(",").map { it.trim() }
|
||||||
|
val maxMetaspaceArg = "-XX:MaxMetaspaceSize=256m"
|
||||||
|
Assert.assertTrue(
|
||||||
|
"Kotlin daemon JVM args do not contain '$maxMetaspaceArg': $kotlinDaemonJvmArgs",
|
||||||
|
maxMetaspaceArg in kotlinDaemonJvmArgs
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val classesKt = project.projectDir.getFileByName("classes.kt")
|
val classesKt = project.projectDir.getFileByName("classes.kt")
|
||||||
|
|||||||
-1
@@ -1 +0,0 @@
|
|||||||
org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m
|
|
||||||
+6
@@ -179,6 +179,12 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val (daemon, sessionId) = connection
|
val (daemon, sessionId) = connection
|
||||||
|
|
||||||
|
if (log.isDebugEnabled) {
|
||||||
|
daemon.getDaemonJVMOptions().takeIf { it.isGood }?.let { jvmOpts ->
|
||||||
|
log.debug("Kotlin compile daemon JVM options: ${jvmOpts.get().mappers.flatMap { it.toArgs("-") }}")
|
||||||
|
}
|
||||||
|
}
|
||||||
val targetPlatform = when (compilerClassName) {
|
val targetPlatform = when (compilerClassName) {
|
||||||
KotlinCompilerClass.JVM -> CompileService.TargetPlatform.JVM
|
KotlinCompilerClass.JVM -> CompileService.TargetPlatform.JVM
|
||||||
KotlinCompilerClass.JS -> CompileService.TargetPlatform.JS
|
KotlinCompilerClass.JS -> CompileService.TargetPlatform.JS
|
||||||
|
|||||||
Reference in New Issue
Block a user