Validate -Xbackend-threads CLI argument value
#KT-51846 Fixed
This commit is contained in:
+2
-2
@@ -124,7 +124,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
"0 means use a thread per processor core.\n" +
|
||||
"Default value is 1"
|
||||
)
|
||||
var parallelBackendThreads: String by FreezableVar("1")
|
||||
var backendThreads: String by FreezableVar("1")
|
||||
|
||||
@Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules")
|
||||
var javaModulePath: String? by NullableStringFreezableVar(null)
|
||||
@@ -505,7 +505,7 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
|
||||
|
||||
@Argument(
|
||||
value = "-Xlink-via-signatures",
|
||||
description = "Link JVM IR symbols via signatures, instead of descriptors. \n" +
|
||||
description = "Link JVM IR symbols via signatures, instead of descriptors.\n" +
|
||||
"This mode is slower, but can be useful in troubleshooting problems with the JVM IR backend"
|
||||
)
|
||||
var linkViaSignatures: Boolean by FreezableVar(false)
|
||||
|
||||
@@ -321,11 +321,27 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
|
||||
arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
|
||||
|
||||
val nThreadsRaw = arguments.parallelBackendThreads.toIntOrNull() ?: 1
|
||||
val nThreadsRaw = parseBackendThreads(arguments.backendThreads, messageCollector)
|
||||
val nThreads = if (nThreadsRaw == 0) Runtime.getRuntime().availableProcessors() else nThreadsRaw
|
||||
if (nThreads > 1) {
|
||||
messageCollector.report(LOGGING, "Running backend in parallel with $nThreads threads")
|
||||
}
|
||||
put(CommonConfigurationKeys.PARALLEL_BACKEND_THREADS, nThreads)
|
||||
}
|
||||
|
||||
private fun parseBackendThreads(stringValue: String, messageCollector: MessageCollector): Int {
|
||||
val value = stringValue.toIntOrNull()
|
||||
if (value == null) {
|
||||
messageCollector.report(ERROR, "Cannot parse -Xbackend-threads value: \"$stringValue\". Please use an integer number")
|
||||
return 1
|
||||
}
|
||||
if (value < 0) {
|
||||
messageCollector.report(ERROR, "-Xbackend-threads value cannot be negative")
|
||||
return 1
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) {
|
||||
val libraries = arguments.klibLibraries ?: return
|
||||
assert(arguments.useIR && !arguments.useOldBackend) { "Klib libraries can only be used with IR backend" }
|
||||
|
||||
Reference in New Issue
Block a user