Update inline incremental compilation for compile daemon

This commit is contained in:
Alexey Tsvetkov
2015-09-02 14:43:33 +03:00
parent f25c10c4a1
commit 06bfc5a16b
10 changed files with 40 additions and 15 deletions
+1
View File
@@ -10,5 +10,6 @@
<orderEntry type="library" name="kotlin-runtime" level="project" /> <orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="rmi-interface" /> <orderEntry type="module" module-name="rmi-interface" />
<orderEntry type="module" module-name="frontend.java" /> <orderEntry type="module" module-name="frontend.java" />
<orderEntry type="module" module-name="util" />
</component> </component>
</module> </module>
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.rmi.kotlinr package org.jetbrains.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.modules.Module
import org.jetbrains.kotlin.rmi.* import org.jetbrains.kotlin.rmi.*
import java.io.File import java.io.File
import java.io.OutputStream import java.io.OutputStream
@@ -175,10 +176,10 @@ public class KotlinCompilerClient {
} }
} }
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<String, IncrementalCache>, out: OutputStream): Int { public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<Module, IncrementalCache>, out: OutputStream): Int {
val outStrm = RemoteOutputStreamServer(out) val outStrm = RemoteOutputStreamServer(out)
val cacheServers = hashMapOf<String, RemoteIncrementalCacheServer>() val cacheServers = hashMapOf<Module, RemoteIncrementalCacheServer>()
try { try {
caches.mapValuesTo(cacheServers, { RemoteIncrementalCacheServer( it.getValue()) }) caches.mapValuesTo(cacheServers, { RemoteIncrementalCacheServer( it.getValue()) })
return compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompileService.OutputFormat.XML) return compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompileService.OutputFormat.XML)
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.rmi.kotlinr package org.jetbrains.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering
import org.jetbrains.kotlin.rmi.CompileService import org.jetbrains.kotlin.rmi.CompileService
import java.rmi.server.UnicastRemoteObject import java.rmi.server.UnicastRemoteObject
@@ -33,6 +34,10 @@ public class RemoteIncrementalCacheServer(val cache: IncrementalCache) : Compile
override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData() override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData()
override fun getInlineRegistering(): InlineRegistering = cache.getInlineRegistering()
override fun getClassFilePath(internalClassName: String): String = cache.getClassFilePath(internalClassName)
override fun close() { override fun close() {
cache.close() cache.close()
} }
@@ -10,5 +10,6 @@
<orderEntry type="library" name="kotlin-runtime" level="project" /> <orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="cli-common" /> <orderEntry type="module" module-name="cli-common" />
<orderEntry type="module" module-name="frontend.java" /> <orderEntry type="module" module-name="frontend.java" />
<orderEntry type="module" module-name="util" />
</component> </component>
</module> </module>
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.rmi package org.jetbrains.kotlin.rmi
import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering
import org.jetbrains.kotlin.modules.Module
import java.rmi.Remote import java.rmi.Remote
import java.rmi.RemoteException import java.rmi.RemoteException
@@ -36,6 +38,12 @@ public interface CompileService : Remote {
throws(RemoteException::class) throws(RemoteException::class)
public fun getModuleMappingData(): ByteArray? public fun getModuleMappingData(): ByteArray?
throws(RemoteException::class)
public fun getInlineRegistering(): InlineRegistering
throws(RemoteException::class)
fun getClassFilePath(internalClassName: String): String
throws(RemoteException::class) throws(RemoteException::class)
public fun close() public fun close()
} }
@@ -55,7 +63,7 @@ public interface CompileService : Remote {
throws(RemoteException::class) throws(RemoteException::class)
public fun remoteIncrementalCompile( public fun remoteIncrementalCompile(
args: Array<out String>, args: Array<out String>,
caches: Map<String, RemoteIncrementalCache>, caches: Map<Module, RemoteIncrementalCache>,
outputStream: RemoteOutputStream, outputStream: RemoteOutputStream,
outputFormat: OutputFormat): Int outputFormat: OutputFormat): Int
} }
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.Module
import org.jetbrains.kotlin.rmi.* import org.jetbrains.kotlin.rmi.*
import org.jetbrains.kotlin.rmi.service.RemoteIncrementalCacheClient import org.jetbrains.kotlin.rmi.service.RemoteIncrementalCacheClient
import org.jetbrains.kotlin.rmi.service.RemoteOutputStreamClient import org.jetbrains.kotlin.rmi.service.RemoteOutputStreamClient
@@ -80,14 +81,14 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
alive = true alive = true
} }
public class IncrementalCompilationComponentsImpl(val idToCache: Map<String, CompileService.RemoteIncrementalCache>): IncrementalCompilationComponents { public class IncrementalCompilationComponentsImpl(val targetToCache: Map<Module, CompileService.RemoteIncrementalCache>): IncrementalCompilationComponents {
// perf: cheap object, but still the pattern may be costly if there are too many calls to cache with the same id (which seems not to be the case now) // perf: cheap object, but still the pattern may be costly if there are too many calls to cache with the same id (which seems not to be the case now)
override fun getIncrementalCache(moduleId: String): IncrementalCache = RemoteIncrementalCacheClient(idToCache[moduleId]!!) override fun getIncrementalCache(target: Module): IncrementalCache = RemoteIncrementalCacheClient(targetToCache[target]!!)
// TODO: add appropriate proxy into interaction when lookup tracker is needed // TODO: add appropriate proxy into interaction when lookup tracker is needed
override fun getLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING override fun getLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
} }
private fun createCompileServices(incrementalCaches: Map<String, CompileService.RemoteIncrementalCache>): Services = private fun createCompileServices(incrementalCaches: Map<Module, CompileService.RemoteIncrementalCache>): Services =
Services.Builder() Services.Builder()
.register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches)) .register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches))
// TODO: add remote proxy for cancellation status tracking // TODO: add remote proxy for cancellation status tracking
@@ -186,7 +187,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
} }
} }
override fun remoteIncrementalCompile(args: Array<out String>, caches: Map<String, CompileService.RemoteIncrementalCache>, outputStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int = override fun remoteIncrementalCompile(args: Array<out String>, caches: Map<Module, CompileService.RemoteIncrementalCache>, outputStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int =
doCompile(args, outputStream) { printStream -> doCompile(args, outputStream) { printStream ->
when (outputFormat) { when (outputFormat) {
CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation") CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation")
@@ -17,14 +17,19 @@
package org.jetbrains.kotlin.rmi.service package org.jetbrains.kotlin.rmi.service
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering
import org.jetbrains.kotlin.rmi.CompileService import org.jetbrains.kotlin.rmi.CompileService
public class RemoteIncrementalCacheClient(val cache: CompileService.RemoteIncrementalCache): IncrementalCache { public class RemoteIncrementalCacheClient(val cache: CompileService.RemoteIncrementalCache): IncrementalCache {
override fun getInlineRegistering(): InlineRegistering = cache.getInlineRegistering()
override fun getObsoletePackageParts(): Collection<String> = cache.getObsoletePackageParts() override fun getObsoletePackageParts(): Collection<String> = cache.getObsoletePackageParts()
override fun getPackagePartData(fqName: String): ByteArray? = cache.getPackagePartData(fqName) override fun getPackagePartData(fqName: String): ByteArray? = cache.getPackagePartData(fqName)
override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData() override fun getModuleMappingData(): ByteArray? = cache.getModuleMappingData()
override fun getClassFilePath(internalClassName: String): String = cache.getClassFilePath(internalClassName)
override fun close(): Unit = cache.close() override fun close(): Unit = cache.close()
} }
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil; import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
import org.jetbrains.kotlin.config.CompilerSettings; import org.jetbrains.kotlin.config.CompilerSettings;
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache; import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
import org.jetbrains.kotlin.modules.Module;
import org.jetbrains.kotlin.rmi.*; import org.jetbrains.kotlin.rmi.*;
import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient; import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient;
import org.jetbrains.kotlin.utils.UtilsPackage; import org.jetbrains.kotlin.utils.UtilsPackage;
@@ -58,7 +59,7 @@ public class KotlinCompilerRunner {
CompilerSettings compilerSettings, CompilerSettings compilerSettings,
MessageCollector messageCollector, MessageCollector messageCollector,
CompilerEnvironment environment, CompilerEnvironment environment,
Map<String, IncrementalCache> incrementalCaches, Map<Module, IncrementalCache> incrementalCaches,
File moduleFile, File moduleFile,
OutputItemsCollector collector OutputItemsCollector collector
) { ) {
@@ -75,7 +76,7 @@ public class KotlinCompilerRunner {
@NotNull CompilerSettings compilerSettings, @NotNull CompilerSettings compilerSettings,
@NotNull MessageCollector messageCollector, @NotNull MessageCollector messageCollector,
@NotNull CompilerEnvironment environment, @NotNull CompilerEnvironment environment,
Map<String, IncrementalCache> incrementalCaches, Map<Module, IncrementalCache> incrementalCaches,
@NotNull OutputItemsCollector collector, @NotNull OutputItemsCollector collector,
@NotNull Collection<File> sourceFiles, @NotNull Collection<File> sourceFiles,
@NotNull List<String> libraryFiles, @NotNull List<String> libraryFiles,
@@ -95,7 +96,7 @@ public class KotlinCompilerRunner {
MessageCollector messageCollector, MessageCollector messageCollector,
OutputItemsCollector collector, OutputItemsCollector collector,
CompilerEnvironment environment, CompilerEnvironment environment,
Map<String, IncrementalCache> incrementalCaches Map<Module, IncrementalCache> incrementalCaches
) { ) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintStream out = new PrintStream(stream); PrintStream out = new PrintStream(stream);
@@ -116,7 +117,7 @@ public class KotlinCompilerRunner {
CommonCompilerArguments arguments, CommonCompilerArguments arguments,
String additionalArguments, String additionalArguments,
CompilerEnvironment environment, CompilerEnvironment environment,
Map<String, IncrementalCache> incrementalCaches, Map<Module, IncrementalCache> incrementalCaches,
PrintStream out, PrintStream out,
MessageCollector messageCollector MessageCollector messageCollector
) { ) {
@@ -62,6 +62,7 @@ import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.Module
import org.jetbrains.kotlin.progress.CompilationCanceledException import org.jetbrains.kotlin.progress.CompilationCanceledException
import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.JvmClassName
@@ -319,7 +320,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
} }
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment,
incrementalCaches.mapKeysTo(HashMap<String, IncrementalCache>(incrementalCaches.size()), { it.getKey().id }), incrementalCaches.mapKeysTo(HashMap<Module, IncrementalCache>(incrementalCaches.size()),
{ ModuleToModuleBuildTargetAdapter(it.getKey()) }),
filesToCompile, messageCollector) filesToCompile, messageCollector)
} }
@@ -486,7 +488,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
private fun compileToJs(chunk: ModuleChunk, private fun compileToJs(chunk: ModuleChunk,
commonArguments: CommonCompilerArguments, commonArguments: CommonCompilerArguments,
environment: CompilerEnvironment, environment: CompilerEnvironment,
incrementalCaches: MutableMap<String, IncrementalCache>?, incrementalCaches: MutableMap<Module, IncrementalCache>?,
messageCollector: MessageCollectorAdapter, project: JpsProject messageCollector: MessageCollectorAdapter, project: JpsProject
): OutputItemsCollectorImpl? { ): OutputItemsCollectorImpl? {
val outputItemCollector = OutputItemsCollectorImpl() val outputItemCollector = OutputItemsCollectorImpl()
@@ -541,7 +543,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
context: CompileContext, context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>, dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>,
environment: CompilerEnvironment, environment: CompilerEnvironment,
incrementalCaches: MutableMap<String, IncrementalCache>?, incrementalCaches: MutableMap<Module, IncrementalCache>?,
filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter filesToCompile: MultiMap<ModuleBuildTarget, File>, messageCollector: MessageCollectorAdapter
): OutputItemsCollectorImpl? { ): OutputItemsCollectorImpl? {
val outputItemCollector = OutputItemsCollectorImpl() val outputItemCollector = OutputItemsCollectorImpl()
@@ -34,7 +34,7 @@ public class IncrementalCompilationComponentsImpl(
override fun getLookupTracker(): LookupTracker = lookupTracker override fun getLookupTracker(): LookupTracker = lookupTracker
} }
private class ModuleToModuleBuildTargetAdapter( public class ModuleToModuleBuildTargetAdapter(
private val moduleBuildTarget: ModuleBuildTarget private val moduleBuildTarget: ModuleBuildTarget
) : Module { ) : Module {