system property to keep application environment alive across multiple compilations

(cherry picked from commit a6b269c)
This commit is contained in:
Dmitry Jemerov
2015-09-03 15:29:07 +02:00
committed by Ilya Chernikov
parent f9399f0510
commit 56735b3302
2 changed files with 21 additions and 8 deletions
@@ -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<String>): 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<String>): JavaCoreApplicationEnvironment {
Extensions.cleanRootArea(parentDisposable)
registerAppExtensionPoints()
val applicationEnvironment = JavaCoreApplicationEnvironment(parentDisposable)