Deriving callback server classes from UnicastRemoteObject instead of manual registration, magically solves the problems with parallel builds; modifying and refactoring usage places accordingly
This commit is contained in:
+3
-11
@@ -25,23 +25,15 @@ import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.rmi.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
|
||||
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
|
||||
|
||||
public class CompilerCallbackServicesFacadeServer(
|
||||
val incrementalCompilationComponents: IncrementalCompilationComponents? = null,
|
||||
val compilationCancelledStatus: CompilationCanceledStatus? = null,
|
||||
port: Int = SOCKET_ANY_FREE_PORT
|
||||
) : CompilerCallbackServicesFacade {
|
||||
|
||||
init {
|
||||
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
|
||||
}
|
||||
|
||||
public fun disconnect() {
|
||||
UnicastRemoteObject.unexportObject(this, true)
|
||||
}
|
||||
|
||||
) : CompilerCallbackServicesFacade,
|
||||
java.rmi.server.UnicastRemoteObject(port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
|
||||
{
|
||||
override fun hasIncrementalCaches(): Boolean = incrementalCompilationComponents != null
|
||||
|
||||
override fun hasLookupTracker(): Boolean = incrementalCompilationComponents != null
|
||||
|
||||
@@ -114,14 +114,7 @@ public object KotlinCompilerClient {
|
||||
public fun compile(compilerService: CompileService, targetPlatform: CompileService.TargetPlatform, args: Array<out String>, out: OutputStream): Int {
|
||||
|
||||
val outStrm = RemoteOutputStreamServer(out)
|
||||
val servicesFacade = CompilerCallbackServicesFacadeServer()
|
||||
try {
|
||||
return compilerService.remoteCompile(targetPlatform, args, servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm)
|
||||
}
|
||||
finally {
|
||||
servicesFacade.disconnect()
|
||||
outStrm.disconnect()
|
||||
}
|
||||
return compilerService.remoteCompile(targetPlatform, args, CompilerCallbackServicesFacadeServer(), outStrm, CompileService.OutputFormat.PLAIN, outStrm)
|
||||
}
|
||||
|
||||
|
||||
@@ -132,22 +125,15 @@ public object KotlinCompilerClient {
|
||||
compilerOut: OutputStream,
|
||||
daemonOut: OutputStream,
|
||||
profiler: Profiler = DummyProfiler()
|
||||
): Int {
|
||||
|
||||
val compilerOutStreamServer = RemoteOutputStreamServer(compilerOut)
|
||||
val daemonOutStreamServer = RemoteOutputStreamServer(daemonOut)
|
||||
val servicesFacade = CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents,
|
||||
compilationCancelledStatus = callbackServices.compilationCanceledStatus)
|
||||
try {
|
||||
return profiler.withMeasure(this) {
|
||||
compileService.remoteIncrementalCompile(targetPlatform, args, servicesFacade, compilerOutStreamServer, CompileService.OutputFormat.XML, daemonOutStreamServer)
|
||||
}
|
||||
}
|
||||
finally {
|
||||
servicesFacade.disconnect()
|
||||
compilerOutStreamServer.disconnect()
|
||||
daemonOutStreamServer.disconnect()
|
||||
}
|
||||
): Int = profiler.withMeasure(this) {
|
||||
compileService.remoteIncrementalCompile(
|
||||
targetPlatform,
|
||||
args,
|
||||
CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents,
|
||||
compilationCancelledStatus = callbackServices.compilationCanceledStatus),
|
||||
RemoteOutputStreamServer(compilerOut),
|
||||
CompileService.OutputFormat.XML,
|
||||
RemoteOutputStreamServer(daemonOut))
|
||||
}
|
||||
|
||||
public val COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY: String = "kotlin.daemon.client.options"
|
||||
@@ -230,8 +216,9 @@ public object KotlinCompilerClient {
|
||||
println("Used memory $memAfter (${"%+d".format(memAfter - memBefore)} kb)")
|
||||
}
|
||||
finally {
|
||||
servicesFacade.disconnect()
|
||||
outStrm.disconnect()
|
||||
// forcing RMI to unregister all objects and stop
|
||||
java.rmi.server.UnicastRemoteObject.unexportObject(servicesFacade, true)
|
||||
java.rmi.server.UnicastRemoteObject.unexportObject(outStrm, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-11
@@ -20,19 +20,12 @@ import org.jetbrains.kotlin.rmi.LoopbackNetworkInterface
|
||||
import org.jetbrains.kotlin.rmi.RemoteOutputStream
|
||||
import org.jetbrains.kotlin.rmi.SOCKET_ANY_FREE_PORT
|
||||
import java.io.OutputStream
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
|
||||
|
||||
class RemoteOutputStreamServer(val out: OutputStream, port: Int = SOCKET_ANY_FREE_PORT) : RemoteOutputStream {
|
||||
|
||||
init {
|
||||
UnicastRemoteObject.exportObject(this, port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
|
||||
}
|
||||
|
||||
public fun disconnect() {
|
||||
UnicastRemoteObject.unexportObject(this, true)
|
||||
}
|
||||
|
||||
class RemoteOutputStreamServer(val out: OutputStream, port: Int = SOCKET_ANY_FREE_PORT)
|
||||
: RemoteOutputStream,
|
||||
java.rmi.server.UnicastRemoteObject(port, LoopbackNetworkInterface.clientLoopbackSocketFactory, LoopbackNetworkInterface.serverLoopbackSocketFactory)
|
||||
{
|
||||
override fun close() {
|
||||
out.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user