Add possibility to change Kotlin daemon VM options

Introduce -XdaemonVmOptions in compiler settings. This allows for the specification of JVM options for the Kotlin compiler daemon. These options are extracted from additional arguments and registered accordingly in the compiler workspace settings.

^KTIJ-28798 Fixed

GitOrigin-RevId: b47c6dba0cc96ee25cd34677fa830263e308c967
This commit is contained in:
Aleksei.Cherepanov
2024-03-04 17:40:03 +01:00
committed by intellij-monorepo-bot
parent 6d2c3deec6
commit 7ee152603b
3 changed files with 30 additions and 0 deletions

View File

@@ -59,6 +59,8 @@ import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.intellij.openapi.options.Configurable.isCheckboxModified;
import static com.intellij.openapi.options.Configurable.isFieldModified;
@@ -701,6 +703,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
if (compilerWorkspaceSettings != null) {
compilerWorkspaceSettings.setPreciseIncrementalEnabled(enableIncrementalCompilationForJvmCheckBox.isSelected());
compilerWorkspaceSettings.setIncrementalCompilationForJsEnabled(enableIncrementalCompilationForJsCheckBox.isSelected());
extractAndRegisterDaemonVmOptions();
boolean oldEnableDaemon = compilerWorkspaceSettings.getEnableDaemon();
compilerWorkspaceSettings.setEnableDaemon(keepAliveCheckBox.isSelected());
@@ -949,4 +952,26 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable {
}).installOn(component);
component.addActionListener(e -> ComponentValidator.getInstance(component).ifPresent(ComponentValidator::revalidate));
}
// Expected format is
// -XdaemonVmOptions=-Xmx2288m for one argument
// and
// -XdaemonVmOptions=\"-Xmx2288m -XX:HeapDumpPath=kotlin-build-process-heap-dump.hprof -XX:+HeapDumpOnOutOfMemoryError\"
// for multiple
private void extractAndRegisterDaemonVmOptions() {
String additionalOptions = getAdditionalArgsOptionsField().getText();
if (additionalOptions.contains("-XdaemonVmOptions")) {
Pattern pattern = Pattern.compile("-XdaemonVmOptions=(?:\"([^\"]*)\"|([^\\s]*))");
Matcher matcher = pattern.matcher(additionalOptions);
if (matcher.find()) {
String daemonArguments = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
if (daemonArguments != null) {
if (compilerWorkspaceSettings != null) {
compilerWorkspaceSettings.setDaemonVmOptions(daemonArguments);
}
}
}
}
}
}

View File

@@ -16,6 +16,7 @@ class KotlinCompilerWorkspaceSettings : PersistentStateComponent<KotlinCompilerW
var preciseIncrementalEnabled: Boolean = true
var incrementalCompilationForJsEnabled: Boolean = true
var enableDaemon: Boolean = true
var daemonVmOptions: String = ""
override fun getState(): KotlinCompilerWorkspaceSettings {
return this

View File

@@ -24,6 +24,10 @@ class KotlinBuildProcessParametersProvider(private val project: Project) : Build
arguments += "-Dkotlin.daemon.enabled"
}
if (compilerWorkspaceSettings.daemonVmOptions.isNotEmpty()) {
arguments += compilerWorkspaceSettings.daemonVmOptions
}
PluginStartupApplicationService.getInstance().getAliveFlagPath().let {
if (!it.isBlank()) {
// TODO: consider taking the property name from compiler/daemon/common (check whether dependency will be not too heavy)