system property to keep application environment alive across multiple compilations
(cherry picked from commit a6b269c)
This commit is contained in:
committed by
Ilya Chernikov
parent
f9399f0510
commit
56735b3302
@@ -239,15 +239,20 @@ public class KotlinCoreEnvironment private constructor(
|
|||||||
): KotlinCoreEnvironment {
|
): KotlinCoreEnvironment {
|
||||||
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
// 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
|
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
||||||
Disposer.register(parentDisposable, object : Disposable {
|
if (System.getProperty("kotlin.environment.keepalive") == null) {
|
||||||
override fun dispose() {
|
Disposer.register(parentDisposable, object : Disposable {
|
||||||
synchronized (APPLICATION_LOCK) {
|
override fun dispose() {
|
||||||
if (--ourProjectCount <= 0) {
|
synchronized (APPLICATION_LOCK) {
|
||||||
disposeApplicationEnvironment()
|
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)
|
val environment = KotlinCoreEnvironment(parentDisposable, getOrCreateApplicationEnvironmentForProduction(configuration, configFilePaths), configuration)
|
||||||
|
|
||||||
synchronized (APPLICATION_LOCK) {
|
synchronized (APPLICATION_LOCK) {
|
||||||
@@ -267,8 +272,14 @@ public class KotlinCoreEnvironment private constructor(
|
|||||||
|
|
||||||
private fun getOrCreateApplicationEnvironmentForProduction(configuration: CompilerConfiguration, configFilePaths: List<String>): JavaCoreApplicationEnvironment {
|
private fun getOrCreateApplicationEnvironmentForProduction(configuration: CompilerConfiguration, configFilePaths: List<String>): JavaCoreApplicationEnvironment {
|
||||||
synchronized (APPLICATION_LOCK) {
|
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()
|
val parentDisposable = Disposer.newDisposable()
|
||||||
ourApplicationEnvironment = createApplicationEnvironment(parentDisposable, configuration, configFilePaths)
|
ourApplicationEnvironment = createApplicationEnvironment(parentDisposable, configuration, configFilePaths)
|
||||||
ourProjectCount = 0
|
ourProjectCount = 0
|
||||||
@@ -293,6 +304,7 @@ public class KotlinCoreEnvironment private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createApplicationEnvironment(parentDisposable: Disposable, configuration: CompilerConfiguration, configFilePaths: List<String>): JavaCoreApplicationEnvironment {
|
private fun createApplicationEnvironment(parentDisposable: Disposable, configuration: CompilerConfiguration, configFilePaths: List<String>): JavaCoreApplicationEnvironment {
|
||||||
|
|
||||||
Extensions.cleanRootArea(parentDisposable)
|
Extensions.cleanRootArea(parentDisposable)
|
||||||
registerAppExtensionPoints()
|
registerAppExtensionPoints()
|
||||||
val applicationEnvironment = JavaCoreApplicationEnvironment(parentDisposable)
|
val applicationEnvironment = JavaCoreApplicationEnvironment(parentDisposable)
|
||||||
|
|||||||
@@ -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\"" ) }
|
System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.let { opts.jvmParams.add("D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"$it\"" ) }
|
||||||
opts.jvmParams.addAll(additionalParams)
|
opts.jvmParams.addAll(additionalParams)
|
||||||
System.getProperty(COMPILE_DAEMON_FORCE_SHUTDOWN_PROPERTY)?.let { opts.jvmParams.add(COMPILE_DAEMON_FORCE_SHUTDOWN_PROPERTY) }
|
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
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user