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(
|
||||
var maxMemory: String = "",
|
||||
var maxPermSize: String = "",
|
||||
var maxMetaspaceSize: String = "",
|
||||
var reservedCodeCacheSize: String = "",
|
||||
var jvmParams: MutableCollection<String> = arrayListOf()
|
||||
) : OptionsGroup {
|
||||
|
||||
override val mappers: List<PropMapper<*, *, *>>
|
||||
get() = listOf(StringPropMapper(this, DaemonJVMOptions::maxMemory, listOf("Xmx"), 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 = "="),
|
||||
restMapper)
|
||||
|
||||
@@ -279,11 +280,13 @@ fun configureDaemonJVMOptions(opts: DaemonJVMOptions,
|
||||
val targetOptions = if (inheritMemoryLimits) opts else DaemonJVMOptions()
|
||||
val otherArgs = jvmArguments.filterExtractProps(targetOptions.mappers, prefix = "-")
|
||||
|
||||
if (inheritMemoryLimits && opts.maxMemory.isBlank()) {
|
||||
val maxMemBytes = Runtime.getRuntime().maxMemory()
|
||||
// rounding up
|
||||
val maxMemMegabytes = maxMemBytes / (1024 * 1024) + if (maxMemBytes % (1024 * 1024) == 0L) 0 else 1
|
||||
opts.maxMemory = "${maxMemMegabytes}m"
|
||||
if (inheritMemoryLimits) {
|
||||
if (opts.maxMemory.isBlank()) {
|
||||
val maxMemBytes = Runtime.getRuntime().maxMemory()
|
||||
// rounding up
|
||||
val maxMemMegabytes = maxMemBytes / (1024 * 1024) + if (maxMemBytes % (1024 * 1024) == 0L) 0 else 1
|
||||
opts.maxMemory = "${maxMemMegabytes}m"
|
||||
}
|
||||
}
|
||||
|
||||
if (inheritOtherJvmOptions) {
|
||||
@@ -365,7 +368,7 @@ private fun String.memToBytes(): Long? =
|
||||
|
||||
|
||||
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 =
|
||||
daemonJVMOptionsMemoryProps
|
||||
|
||||
+15
@@ -1,8 +1,10 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
@@ -64,11 +66,24 @@ abstract class ExecutionStrategyIT : BaseGradleIT() {
|
||||
val strategyCLIArg = "-Dkotlin.compiler.execution.strategy=$executionStrategy"
|
||||
val finishMessage = "Finished executing kotlin compiler using $executionStrategy strategy"
|
||||
|
||||
val isGradleAtLeast50 = project.testGradleVersionAtLeast("5.0")
|
||||
|
||||
project.build("build", strategyCLIArg) {
|
||||
assertSuccessful()
|
||||
assertContains(finishMessage)
|
||||
checkOutput()
|
||||
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")
|
||||
|
||||
-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
|
||||
|
||||
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) {
|
||||
KotlinCompilerClass.JVM -> CompileService.TargetPlatform.JVM
|
||||
KotlinCompilerClass.JS -> CompileService.TargetPlatform.JS
|
||||
|
||||
Reference in New Issue
Block a user