diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index 5c5e91ecf43..510d6f4623d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -239,15 +239,20 @@ public class KotlinCoreEnvironment private constructor( ): KotlinCoreEnvironment { // JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ) // All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well - Disposer.register(parentDisposable, object : Disposable { - override fun dispose() { - synchronized (APPLICATION_LOCK) { - if (--ourProjectCount <= 0) { - disposeApplicationEnvironment() + if (System.getProperty("kotlin.environment.keepalive") == null) { + Disposer.register(parentDisposable, object : Disposable { + override fun dispose() { + synchronized (APPLICATION_LOCK) { + if (--ourProjectCount <= 0) { + disposeApplicationEnvironment() + } } } - } - }) + }) + } else { + configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)?.report(CompilerMessageSeverity.INFO, + "App environment reuse enabled", CompilerMessageLocation.NO_LOCATION) + } val environment = KotlinCoreEnvironment(parentDisposable, getOrCreateApplicationEnvironmentForProduction(configuration, configFilePaths), configuration) synchronized (APPLICATION_LOCK) { @@ -267,8 +272,14 @@ public class KotlinCoreEnvironment private constructor( private fun getOrCreateApplicationEnvironmentForProduction(configuration: CompilerConfiguration, configFilePaths: List): JavaCoreApplicationEnvironment { synchronized (APPLICATION_LOCK) { - if (ourApplicationEnvironment != null) return ourApplicationEnvironment!! + if (ourApplicationEnvironment != null) { + configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)?.report(CompilerMessageSeverity.INFO, + "Using existing app environment", CompilerMessageLocation.NO_LOCATION) + return ourApplicationEnvironment!! + } + configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)?.report(CompilerMessageSeverity.INFO, + "Creating new app environment", CompilerMessageLocation.NO_LOCATION) val parentDisposable = Disposer.newDisposable() ourApplicationEnvironment = createApplicationEnvironment(parentDisposable, configuration, configFilePaths) ourProjectCount = 0 @@ -293,6 +304,7 @@ public class KotlinCoreEnvironment private constructor( } private fun createApplicationEnvironment(parentDisposable: Disposable, configuration: CompilerConfiguration, configFilePaths: List): JavaCoreApplicationEnvironment { + Extensions.cleanRootArea(parentDisposable) registerAppExtensionPoints() val applicationEnvironment = JavaCoreApplicationEnvironment(parentDisposable) diff --git a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt index 8722653b84f..be1bc159d55 100644 --- a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt +++ b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt @@ -306,6 +306,7 @@ public fun configureDaemonJVMOptions(opts: DaemonJVMOptions, inheritMemoryLimits System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.let { opts.jvmParams.add("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"$it\"" ) } opts.jvmParams.addAll(additionalParams) System.getProperty(COMPILE_DAEMON_FORCE_SHUTDOWN_PROPERTY)?.let { opts.jvmParams.add(COMPILE_DAEMON_FORCE_SHUTDOWN_PROPERTY) } + System.getProperty("kotlin.environment.keepalive")?.let { opts.jvmParams.add("Dkotlin.environment.keepalive=true") } return opts }