Validate -Xbackend-threads CLI argument value

#KT-51846 Fixed
This commit is contained in:
Alexander Udalov
2022-04-06 00:13:07 +02:00
parent d69df1898d
commit 6402c3908c
10 changed files with 54 additions and 6 deletions
@@ -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" }
+3 -3
View File
@@ -16,6 +16,9 @@ where advanced options include:
-Xassertions=jvm: enable, depend on jvm assertion settings;
-Xassertions=legacy: calculate condition on each call, check depends on jvm assertion settings in the kotlin package;
default: legacy
-Xbackend-threads=<N> When using the IR backend, run lowerings by file in N parallel threads.
0 means use a thread per processor core.
Default value is 1
-Xbuild-file=<path> Path to the .xml build file to compile
-Xcompile-java Reuse javac analysis and compile Java source files
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
@@ -99,9 +102,6 @@ where advanced options include:
* ignore
* strict
* warn (report a warning)
-Xbackend-threads=<N> When using the IR backend, run lowerings by file in N parallel threads.
0 means use a thread per processor core.
Default value is 1
-Xprofile=<profilerPath:command:outputDir>
Debug option: Run compiler with async profiler and save snapshots to `outputDir`; `command` is passed to async-profiler on start.
`profilerPath` is a path to libasyncProfiler.so; async-profiler.jar should be on the compiler classpath.
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/simple.kt
-d
$TEMP_DIR$
-Xbackend-threads=2
@@ -0,0 +1 @@
OK
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/simple.kt
-d
$TEMP_DIR$
-Xbackend-threads=abcd
@@ -0,0 +1,2 @@
error: cannot parse -Xbackend-threads value: "abcd". Please use an integer number
COMPILATION_ERROR
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/simple.kt
-d
$TEMP_DIR$
-Xbackend-threads=-3
@@ -0,0 +1,2 @@
error: -Xbackend-threads value cannot be negative
COMPILATION_ERROR
@@ -689,6 +689,21 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/kt49209.args");
}
@TestMetadata("kt51846_backendThreadsValidation1.args")
public void testKt51846_backendThreadsValidation1() throws Exception {
runTest("compiler/testData/cli/jvm/kt51846_backendThreadsValidation1.args");
}
@TestMetadata("kt51846_backendThreadsValidation2.args")
public void testKt51846_backendThreadsValidation2() throws Exception {
runTest("compiler/testData/cli/jvm/kt51846_backendThreadsValidation2.args");
}
@TestMetadata("kt51846_backendThreadsValidation3.args")
public void testKt51846_backendThreadsValidation3() throws Exception {
runTest("compiler/testData/cli/jvm/kt51846_backendThreadsValidation3.args");
}
@TestMetadata("languageVersion.args")
public void testLanguageVersion() throws Exception {
runTest("compiler/testData/cli/jvm/languageVersion.args");