Introduce new Kotlin Daemon without RMI abstraction
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import com.sun.javafx.scene.CameraHelper.project
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
@@ -13,6 +14,9 @@ dependencies {
|
||||
compileOnly(project(":js:js.frontend"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) }
|
||||
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
+5
@@ -29,4 +29,9 @@ enum class CompilationResultCategory(val code: Int) {
|
||||
IC_COMPILE_ITERATION(0),
|
||||
BUILD_REPORT_LINES(1),
|
||||
VERBOSE_BUILD_REPORT_LINES(2),
|
||||
}
|
||||
|
||||
interface CompilationResultsAsync {
|
||||
suspend fun add(compilationResultCategory: Int, value: Serializable)
|
||||
val clientSide: CompilationResultsAsync
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.Serializable
|
||||
|
||||
class CompilationResultsAsyncWrapper(val rmiImpl: CompilationResults) : CompilationResultsAsync {
|
||||
|
||||
override val clientSide: CompilationResultsAsync
|
||||
get() = this
|
||||
|
||||
override suspend fun add(compilationResultCategory: Int, value: Serializable) {
|
||||
rmiImpl.add(compilationResultCategory, value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CompilationResultsRMIWrapper(val clientSide: CompilationResultsAsync) : CompilationResults, Serializable {
|
||||
|
||||
override fun add(compilationResultCategory: Int, value: Serializable) = runBlocking {
|
||||
clientSide.add(compilationResultCategory, value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun CompilationResults.toClient() =
|
||||
if (this is CompilationResultsRMIWrapper) this.clientSide
|
||||
else CompilationResultsAsyncWrapper(this)
|
||||
|
||||
fun CompilationResultsAsync.toRMI() =
|
||||
if (this is CompilationResultsAsyncWrapper) this.rmiImpl
|
||||
else CompilationResultsRMIWrapper(this)
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
|
||||
import java.io.File
|
||||
|
||||
|
||||
interface CompileServiceAsync {
|
||||
|
||||
suspend fun checkCompilerId(expectedCompilerId: CompilerId): Boolean
|
||||
|
||||
suspend fun getUsedMemory(): CompileService.CallResult<Long>
|
||||
|
||||
suspend fun getDaemonOptions(): CompileService.CallResult<DaemonOptions>
|
||||
|
||||
suspend fun getDaemonInfo(): CompileService.CallResult<String>
|
||||
|
||||
suspend fun getDaemonJVMOptions(): CompileService.CallResult<DaemonJVMOptions>
|
||||
|
||||
suspend fun registerClient(aliveFlagPath: String?): CompileService.CallResult<Nothing>
|
||||
|
||||
// TODO: (-old-) consider adding another client alive checking mechanism, e.g. socket/socketPort
|
||||
|
||||
suspend fun getClients(): CompileService.CallResult<List<String>>
|
||||
|
||||
suspend fun leaseCompileSession(aliveFlagPath: String?): CompileService.CallResult<Int>
|
||||
|
||||
suspend fun releaseCompileSession(sessionId: Int): CompileService.CallResult<Nothing>
|
||||
|
||||
suspend fun shutdown(): CompileService.CallResult<Nothing>
|
||||
|
||||
suspend fun scheduleShutdown(graceful: Boolean): CompileService.CallResult<Boolean>
|
||||
|
||||
suspend fun compile(
|
||||
sessionId: Int,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBaseAsync,
|
||||
compilationResults: CompilationResultsAsync?
|
||||
): CompileService.CallResult<Int>
|
||||
|
||||
suspend fun clearJarCache()
|
||||
|
||||
suspend fun releaseReplSession(sessionId: Int): CompileService.CallResult<Nothing>
|
||||
|
||||
suspend fun leaseReplSession(
|
||||
aliveFlagPath: String?,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBaseAsync,
|
||||
templateClasspath: List<java.io.File>,
|
||||
templateClassName: String
|
||||
): CompileService.CallResult<Int>
|
||||
|
||||
suspend fun replCreateState(sessionId: Int): CompileService.CallResult<ReplStateFacadeAsync>
|
||||
|
||||
suspend fun replCheck(
|
||||
sessionId: Int,
|
||||
replStateId: Int,
|
||||
codeLine: ReplCodeLine
|
||||
): CompileService.CallResult<ReplCheckResult>
|
||||
|
||||
suspend fun replCompile(
|
||||
sessionId: Int,
|
||||
replStateId: Int,
|
||||
codeLine: ReplCodeLine
|
||||
): CompileService.CallResult<ReplCompileResult>
|
||||
|
||||
suspend fun classesFqNamesByFiles(sessionId: Int, sourceFiles: Set<File>): CompileService.CallResult<Set<String>>
|
||||
|
||||
val serverPort: Int
|
||||
get() = 0
|
||||
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
||||
import java.io.File
|
||||
|
||||
class CompileServiceAsyncWrapper(
|
||||
val rmiCompileService: CompileService
|
||||
) : CompileServiceAsync {
|
||||
|
||||
override suspend fun classesFqNamesByFiles(sessionId: Int, sourceFiles: Set<File>) =
|
||||
rmiCompileService.classesFqNamesByFiles(sessionId, sourceFiles)
|
||||
|
||||
override suspend fun compile(
|
||||
sessionId: Int,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBaseAsync,
|
||||
compilationResults: CompilationResultsAsync?
|
||||
) = rmiCompileService.compile(
|
||||
sessionId,
|
||||
compilerArguments,
|
||||
compilationOptions,
|
||||
servicesFacade.toRMI(),
|
||||
compilationResults?.toRMI()
|
||||
)
|
||||
|
||||
override suspend fun leaseReplSession(
|
||||
aliveFlagPath: String?,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBaseAsync,
|
||||
templateClasspath: List<File>,
|
||||
templateClassName: String
|
||||
) = rmiCompileService.leaseReplSession(
|
||||
aliveFlagPath,
|
||||
compilerArguments,
|
||||
compilationOptions,
|
||||
servicesFacade.toRMI(),
|
||||
templateClasspath,
|
||||
templateClassName
|
||||
)
|
||||
|
||||
override suspend fun replCreateState(sessionId: Int) =
|
||||
rmiCompileService.replCreateState(sessionId).toClient()
|
||||
|
||||
override suspend fun getUsedMemory() =
|
||||
rmiCompileService.getUsedMemory()
|
||||
|
||||
override suspend fun getDaemonOptions() =
|
||||
rmiCompileService.getDaemonOptions()
|
||||
|
||||
|
||||
override suspend fun getDaemonInfo() =
|
||||
rmiCompileService.getDaemonInfo()
|
||||
|
||||
|
||||
override suspend fun getDaemonJVMOptions() =
|
||||
rmiCompileService.getDaemonJVMOptions()
|
||||
|
||||
override suspend fun registerClient(aliveFlagPath: String?) =
|
||||
rmiCompileService.registerClient(aliveFlagPath)
|
||||
|
||||
override suspend fun getClients() =
|
||||
rmiCompileService.getClients()
|
||||
|
||||
|
||||
override suspend fun leaseCompileSession(aliveFlagPath: String?) =
|
||||
rmiCompileService.leaseCompileSession(aliveFlagPath)
|
||||
|
||||
|
||||
override suspend fun releaseCompileSession(sessionId: Int) =
|
||||
rmiCompileService.releaseCompileSession(sessionId)
|
||||
|
||||
|
||||
override suspend fun shutdown() =
|
||||
rmiCompileService.shutdown()
|
||||
|
||||
|
||||
override suspend fun scheduleShutdown(graceful: Boolean) =
|
||||
rmiCompileService.scheduleShutdown(graceful)
|
||||
|
||||
override suspend fun clearJarCache() =
|
||||
rmiCompileService.clearJarCache()
|
||||
|
||||
|
||||
override suspend fun releaseReplSession(sessionId: Int) =
|
||||
rmiCompileService.releaseReplSession(sessionId)
|
||||
|
||||
|
||||
override suspend fun replCheck(sessionId: Int, replStateId: Int, codeLine: ReplCodeLine) =
|
||||
rmiCompileService.replCheck(sessionId, replStateId, codeLine)
|
||||
|
||||
override suspend fun replCompile(
|
||||
sessionId: Int,
|
||||
replStateId: Int,
|
||||
codeLine: ReplCodeLine
|
||||
) = rmiCompileService.replCompile(sessionId, replStateId, codeLine)
|
||||
|
||||
override suspend fun checkCompilerId(expectedCompilerId: CompilerId) =
|
||||
rmiCompileService.checkCompilerId(expectedCompilerId)
|
||||
|
||||
}
|
||||
|
||||
fun CompileService.toClient() = CompileServiceAsyncWrapper(this)
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
|
||||
import java.io.File
|
||||
|
||||
class CompileServiceClientRMIWrapper(
|
||||
val asyncCompileService: CompileServiceAsync
|
||||
) : CompileService {
|
||||
|
||||
override fun classesFqNamesByFiles(sessionId: Int, sourceFiles: Set<File>) = runBlocking {
|
||||
asyncCompileService.classesFqNamesByFiles(sessionId, sourceFiles)
|
||||
}
|
||||
|
||||
private fun reportNotImplemented(): Nothing = throw IllegalStateException("Unexpected call to deprecated method")
|
||||
|
||||
// deprecated methods :
|
||||
override fun remoteCompile(
|
||||
sessionId: Int,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
args: Array<out String>,
|
||||
servicesFacade: CompilerCallbackServicesFacade,
|
||||
compilerOutputStream: RemoteOutputStream,
|
||||
outputFormat: CompileService.OutputFormat,
|
||||
serviceOutputStream: RemoteOutputStream,
|
||||
operationsTracer: RemoteOperationsTracer?
|
||||
): CompileService.CallResult<Int> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
override fun remoteIncrementalCompile(
|
||||
sessionId: Int,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
args: Array<out String>,
|
||||
servicesFacade: CompilerCallbackServicesFacade,
|
||||
compilerOutputStream: RemoteOutputStream,
|
||||
compilerOutputFormat: CompileService.OutputFormat,
|
||||
serviceOutputStream: RemoteOutputStream,
|
||||
operationsTracer: RemoteOperationsTracer?
|
||||
): CompileService.CallResult<Int> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
override fun leaseReplSession(
|
||||
aliveFlagPath: String?,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
servicesFacade: CompilerCallbackServicesFacade,
|
||||
templateClasspath: List<File>,
|
||||
templateClassName: String,
|
||||
scriptArgs: Array<out Any?>?,
|
||||
scriptArgsTypes: Array<out Class<out Any>>?,
|
||||
compilerMessagesOutputStream: RemoteOutputStream,
|
||||
evalOutputStream: RemoteOutputStream?,
|
||||
evalErrorStream: RemoteOutputStream?,
|
||||
evalInputStream: RemoteInputStream?,
|
||||
operationsTracer: RemoteOperationsTracer?
|
||||
): CompileService.CallResult<Int> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
override fun remoteReplLineCheck(sessionId: Int, codeLine: ReplCodeLine): CompileService.CallResult<ReplCheckResult> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
override fun remoteReplLineCompile(
|
||||
sessionId: Int,
|
||||
codeLine: ReplCodeLine,
|
||||
history: List<ReplCodeLine>?
|
||||
): CompileService.CallResult<ReplCompileResult> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
override fun remoteReplLineEval(
|
||||
sessionId: Int,
|
||||
codeLine: ReplCodeLine,
|
||||
history: List<ReplCodeLine>?
|
||||
): CompileService.CallResult<ReplEvalResult> {
|
||||
reportNotImplemented()
|
||||
}
|
||||
|
||||
// normal methods:
|
||||
override fun compile(
|
||||
sessionId: Int,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationResults: CompilationResults?
|
||||
) = runBlocking {
|
||||
asyncCompileService.compile(
|
||||
sessionId,
|
||||
compilerArguments,
|
||||
compilationOptions,
|
||||
servicesFacade.toClient(),
|
||||
compilationResults?.toClient() // TODO
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
override fun leaseReplSession(
|
||||
aliveFlagPath: String?,
|
||||
compilerArguments: Array<out String>,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
templateClasspath: List<File>,
|
||||
templateClassName: String
|
||||
) = runBlocking {
|
||||
asyncCompileService.leaseReplSession(
|
||||
aliveFlagPath,
|
||||
compilerArguments,
|
||||
compilationOptions,
|
||||
servicesFacade.toClient(),
|
||||
templateClasspath,
|
||||
templateClassName
|
||||
)
|
||||
}
|
||||
|
||||
override fun replCreateState(sessionId: Int) = runBlocking {
|
||||
asyncCompileService.replCreateState(sessionId)
|
||||
}.toRMI()
|
||||
|
||||
override fun getUsedMemory() = runBlocking {
|
||||
asyncCompileService.getUsedMemory()
|
||||
}
|
||||
|
||||
override fun getDaemonOptions() = runBlocking {
|
||||
asyncCompileService.getDaemonOptions()
|
||||
}
|
||||
|
||||
override fun getDaemonInfo() = runBlocking {
|
||||
asyncCompileService.getDaemonInfo()
|
||||
}
|
||||
|
||||
|
||||
override fun getDaemonJVMOptions() = runBlocking {
|
||||
asyncCompileService.getDaemonJVMOptions()
|
||||
}
|
||||
|
||||
override fun registerClient(aliveFlagPath: String?) = runBlocking {
|
||||
asyncCompileService.registerClient(aliveFlagPath)
|
||||
}
|
||||
|
||||
override fun getClients() = runBlocking {
|
||||
asyncCompileService.getClients()
|
||||
}
|
||||
|
||||
|
||||
override fun leaseCompileSession(aliveFlagPath: String?) = runBlocking {
|
||||
asyncCompileService.leaseCompileSession(aliveFlagPath)
|
||||
}
|
||||
|
||||
|
||||
override fun releaseCompileSession(sessionId: Int) = runBlocking {
|
||||
asyncCompileService.releaseCompileSession(sessionId)
|
||||
}
|
||||
|
||||
|
||||
override fun shutdown() = runBlocking {
|
||||
asyncCompileService.shutdown()
|
||||
}
|
||||
|
||||
|
||||
override fun scheduleShutdown(graceful: Boolean) = runBlocking {
|
||||
asyncCompileService.scheduleShutdown(graceful)
|
||||
}
|
||||
|
||||
override fun clearJarCache() = runBlocking {
|
||||
asyncCompileService.clearJarCache()
|
||||
}
|
||||
|
||||
|
||||
override fun releaseReplSession(sessionId: Int) = runBlocking {
|
||||
asyncCompileService.releaseReplSession(sessionId)
|
||||
}
|
||||
|
||||
|
||||
override fun replCheck(sessionId: Int, replStateId: Int, codeLine: ReplCodeLine) = runBlocking {
|
||||
asyncCompileService.replCheck(sessionId, replStateId, codeLine)
|
||||
}
|
||||
|
||||
override fun replCompile(
|
||||
sessionId: Int,
|
||||
replStateId: Int,
|
||||
codeLine: ReplCodeLine
|
||||
) = runBlocking {
|
||||
asyncCompileService.replCompile(sessionId, replStateId, codeLine)
|
||||
}
|
||||
|
||||
override fun checkCompilerId(expectedCompilerId: CompilerId) = runBlocking {
|
||||
asyncCompileService.checkCompilerId(expectedCompilerId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun CompileServiceAsync.toRMI() = when (this) {
|
||||
is CompileServiceAsyncWrapper -> this.rmiCompileService
|
||||
else -> CompileServiceClientRMIWrapper(this)
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.incremental.components.LookupInfo
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
|
||||
interface CompilerCallbackServicesFacadeAsync : CompilerServicesFacadeBaseAsync {
|
||||
|
||||
suspend fun hasIncrementalCaches(): Boolean
|
||||
|
||||
suspend fun hasLookupTracker(): Boolean
|
||||
|
||||
suspend fun hasCompilationCanceledStatus(): Boolean
|
||||
|
||||
// ----------------------------------------------------
|
||||
// IncrementalCache
|
||||
suspend fun incrementalCache_getObsoletePackageParts(target: TargetId): Collection<String>
|
||||
|
||||
suspend fun incrementalCache_getObsoleteMultifileClassFacades(target: TargetId): Collection<String>
|
||||
|
||||
suspend fun incrementalCache_getPackagePartData(target: TargetId, partInternalName: String): JvmPackagePartProto?
|
||||
|
||||
suspend fun incrementalCache_getModuleMappingData(target: TargetId): ByteArray?
|
||||
|
||||
suspend fun incrementalCache_registerInline(target: TargetId, fromPath: String, jvmSignature: String, toPath: String)
|
||||
|
||||
suspend fun incrementalCache_getClassFilePath(target: TargetId, internalClassName: String): String
|
||||
|
||||
suspend fun incrementalCache_close(target: TargetId)
|
||||
|
||||
suspend fun incrementalCache_getMultifileFacadeParts(target: TargetId, internalName: String): Collection<String>?
|
||||
|
||||
// ----------------------------------------------------
|
||||
// LookupTracker
|
||||
suspend fun lookupTracker_requiresPosition(): Boolean
|
||||
|
||||
fun lookupTracker_record(lookups: Collection<LookupInfo>)
|
||||
|
||||
suspend fun lookupTracker_isDoNothing(): Boolean
|
||||
|
||||
// ----------------------------------------------------
|
||||
// CompilationCanceledStatus
|
||||
suspend fun compilationCanceledStatus_checkCanceled(): Void?
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
interface CompilerServicesFacadeBaseAsync {
|
||||
/**
|
||||
* Reports different kind of diagnostic messages from compile daemon to compile daemon clients (jps, gradle, ...)
|
||||
*/
|
||||
suspend fun report(category: Int, severity: Int, message: String?, attachment: Serializable?)
|
||||
}
|
||||
|
||||
suspend fun CompilerServicesFacadeBaseAsync.report(
|
||||
category: ReportCategory,
|
||||
severity: ReportSeverity,
|
||||
message: String? = null,
|
||||
attachment: Serializable? = null
|
||||
) {
|
||||
report(category.code, severity.code, message, attachment)
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
|
||||
class CompilerServicesFacadeBaseAsyncWrapper(
|
||||
val rmiImpl: CompilerServicesFacadeBase
|
||||
) : CompilerServicesFacadeBaseAsync {
|
||||
|
||||
override suspend fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) =
|
||||
rmiImpl.report(category, severity, message, attachment)
|
||||
|
||||
}
|
||||
|
||||
fun CompilerServicesFacadeBase.toClient() =
|
||||
if (this is CompilerServicesFacadeBaseRMIWrapper) this.clientSide
|
||||
else CompilerServicesFacadeBaseAsyncWrapper(this)
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.Serializable
|
||||
|
||||
class CompilerServicesFacadeBaseRMIWrapper(val clientSide: CompilerServicesFacadeBaseAsync) : CompilerServicesFacadeBase, Serializable {
|
||||
|
||||
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) = runBlocking {
|
||||
clientSide.report(category, severity, message, attachment)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun CompilerServicesFacadeBaseAsync.toRMI() =
|
||||
if (this is CompilerServicesFacadeBaseAsyncWrapper) this.rmiImpl
|
||||
else CompilerServicesFacadeBaseRMIWrapper(this)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
enum class DaemonProtocolVariant {
|
||||
RMI, SOCKETS
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
|
||||
interface IncrementalCompilerServicesFacadeAsync : CompilerServicesFacadeBaseAsync
|
||||
@@ -34,7 +34,15 @@ interface Profiler {
|
||||
fun getCounters(): Map<Any?, PerfCounters>
|
||||
fun getTotalCounters(): PerfCounters
|
||||
|
||||
fun<R> withMeasure(obj: Any?, body: () -> R): R
|
||||
fun beginMeasure(obj: Any?) : List<Long> = listOf()
|
||||
fun endMeasure(obj: Any?, startState: List<Long>) {}
|
||||
}
|
||||
|
||||
inline fun<R> Profiler.withMeasure(obj: Any?, body: () -> R): R {
|
||||
val startState = beginMeasure(obj)
|
||||
val res = body()
|
||||
endMeasure(obj, startState)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@@ -85,57 +93,64 @@ inline fun usedMemory(withGC: Boolean): Long {
|
||||
}
|
||||
|
||||
|
||||
inline fun<R> withMeasureWallTime(perfCounters: PerfCounters, body: () -> R): R {
|
||||
val startTime = System.nanoTime()
|
||||
val res = body()
|
||||
inline fun<R> beginWithMeasureWallTime(perfCounters: PerfCounters) = listOf(System.nanoTime())
|
||||
|
||||
inline fun<R> endWithMeasureWallTime(perfCounters: PerfCounters, startState: List<Long>) {
|
||||
val (startTime) = startState
|
||||
perfCounters.addMeasurement(time = System.nanoTime() - startTime) // TODO: add support for time wrapping
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
inline fun<R> withMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean, body: () -> R): R {
|
||||
inline fun beginWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean): List<Long> {
|
||||
val startTime = System.nanoTime()
|
||||
val startThreadTime = threadMXBean.threadCpuTime()
|
||||
val startThreadUserTime = threadMXBean.threadUserTime()
|
||||
return listOf(startTime, startThreadTime, startThreadUserTime)
|
||||
}
|
||||
|
||||
val res = body()
|
||||
inline fun endWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean, startState: List<Long>) {
|
||||
val (startTime, startThreadTime, startThreadUserTime) = startState
|
||||
|
||||
// TODO: add support for time wrapping
|
||||
perfCounters.addMeasurement(time = System.nanoTime() - startTime,
|
||||
thread = threadMXBean.threadCpuTime() - startThreadTime,
|
||||
threadUser = threadMXBean.threadUserTime() - startThreadUserTime)
|
||||
return res
|
||||
}
|
||||
|
||||
inline fun<R> withMeasureWallAndThreadTimes(perfCounters: PerfCounters, body: () -> R): R = withMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean(), body)
|
||||
inline fun beginWithMeasureWallAndThreadTimes(perfCounters: PerfCounters) =
|
||||
beginWithMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean())
|
||||
inline fun endWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, startState: List<Long>) =
|
||||
endWithMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean(), startState)
|
||||
|
||||
|
||||
inline fun<R> withMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean, body: () -> R): R {
|
||||
inline fun beginWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean): List<Long> {
|
||||
val startMem = usedMemory(withGC)
|
||||
val startTime = System.nanoTime()
|
||||
val startThreadTime = threadMXBean.threadCpuTime()
|
||||
val startThreadUserTime = threadMXBean.threadUserTime()
|
||||
|
||||
val res = body()
|
||||
return listOf(startMem, startTime, startThreadTime, startThreadUserTime)
|
||||
}
|
||||
|
||||
inline fun endWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean, startState: List<Long>){
|
||||
val (startMem, startTime, startThreadTime, startThreadUserTime) = startState
|
||||
|
||||
// TODO: add support for time wrapping
|
||||
perfCounters.addMeasurement(time = System.nanoTime() - startTime,
|
||||
thread = threadMXBean.threadCpuTime() - startThreadTime,
|
||||
threadUser = threadMXBean.threadUserTime() - startThreadUserTime,
|
||||
memory = usedMemory(withGC) - startMem)
|
||||
return res
|
||||
}
|
||||
|
||||
inline fun<R> withMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean, body: () -> R): R =
|
||||
withMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean(), body)
|
||||
inline fun<R> beginWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean) =
|
||||
beginWithMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean())
|
||||
|
||||
inline fun<R> endWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean, startState: List<Long>) =
|
||||
endWithMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean(), startState)
|
||||
|
||||
|
||||
class DummyProfiler : Profiler {
|
||||
override fun getCounters(): Map<Any?, PerfCounters> = mapOf(null to SimplePerfCounters())
|
||||
override fun getTotalCounters(): PerfCounters = SimplePerfCounters()
|
||||
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun <R> withMeasure(obj: Any?, body: () -> R): R = body()
|
||||
}
|
||||
|
||||
|
||||
@@ -151,19 +166,27 @@ abstract class TotalProfiler : Profiler {
|
||||
|
||||
class WallTotalProfiler : TotalProfiler() {
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun <R> withMeasure(obj: Any?, body: () -> R): R = withMeasureWallTime(total, body)
|
||||
override inline fun beginMeasure(obj: Any?) = beginWithMeasureWallTime(total)
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun endMeasure(obj: Any?, startState: List<Long>) = endWithMeasureWallTime(total, startState)
|
||||
}
|
||||
|
||||
|
||||
class WallAndThreadTotalProfiler : TotalProfiler() {
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun <R> withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimes(total, threadMXBean, body)
|
||||
override inline fun beginMeasure(obj: Any?) = beginWithMeasureWallAndThreadTimes(total, threadMXBean)
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun endMeasure(obj: Any?, startState: List<Long>) = endWithMeasureWallAndThreadTimes(total, threadMXBean, startState)
|
||||
}
|
||||
|
||||
|
||||
class WallAndThreadAndMemoryTotalProfiler(val withGC: Boolean) : TotalProfiler() {
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun <R> withMeasure(obj: Any?, body: () -> R): R = withMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, body)
|
||||
override inline fun beginMeasure(obj: Any?) =
|
||||
beginWithMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean)
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun endMeasure(obj: Any?, startState: List<Long>) =
|
||||
endWithMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, startState)
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +197,9 @@ class WallAndThreadByClassProfiler() : TotalProfiler() {
|
||||
override fun getCounters(): Map<Any?, PerfCounters> = counters
|
||||
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun <R> withMeasure(obj: Any?, body: () -> R): R =
|
||||
withMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, body)
|
||||
override inline fun beginMeasure(obj: Any?) =
|
||||
beginWithMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean)
|
||||
@Suppress("OVERRIDE_BY_INLINE")
|
||||
override inline fun endMeasure(obj: Any?, startState: List<Long>) =
|
||||
endWithMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, startState)
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.ILineId
|
||||
|
||||
interface ReplStateFacadeAsync {
|
||||
suspend fun getId(): Int
|
||||
|
||||
suspend fun getHistorySize(): Int
|
||||
|
||||
suspend fun historyGet(index: Int): ILineId
|
||||
|
||||
suspend fun historyReset(): List<ILineId>
|
||||
|
||||
suspend fun historyResetTo(id: ILineId): List<ILineId>
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.repl.ILineId
|
||||
|
||||
class ReplStateFacadeAsyncWrapper(val rmiReplStateFacade: ReplStateFacade) : ReplStateFacadeAsync {
|
||||
|
||||
override suspend fun getId() = rmiReplStateFacade.getId()
|
||||
|
||||
override suspend fun getHistorySize() = rmiReplStateFacade.getHistorySize()
|
||||
|
||||
override suspend fun historyGet(index: Int) = rmiReplStateFacade.historyGet(index)
|
||||
|
||||
override suspend fun historyReset() = rmiReplStateFacade.historyReset()
|
||||
|
||||
override suspend fun historyResetTo(id: ILineId) = rmiReplStateFacade.historyResetTo(id)
|
||||
|
||||
}
|
||||
|
||||
fun ReplStateFacade.toClient() = ReplStateFacadeAsyncWrapper(this)
|
||||
fun CompileService.CallResult<ReplStateFacade>.toClient() = when (this) {
|
||||
is CompileService.CallResult.Good -> CompileService.CallResult.Good(this.result.toClient())
|
||||
is CompileService.CallResult.Dying -> this
|
||||
is CompileService.CallResult.Error -> this
|
||||
is CompileService.CallResult.Ok -> this
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.cli.common.repl.ILineId
|
||||
import java.io.Serializable
|
||||
|
||||
class ReplStateFacadeRMIWrapper(val clientSide: ReplStateFacadeAsync) : ReplStateFacade, Serializable {
|
||||
|
||||
override fun getId() = runBlocking { clientSide.getId() }
|
||||
|
||||
override fun getHistorySize() = runBlocking { clientSide.getHistorySize() }
|
||||
|
||||
override fun historyGet(index: Int) = runBlocking { clientSide.historyGet(index) }
|
||||
|
||||
override fun historyReset() = runBlocking { clientSide.historyReset() }
|
||||
|
||||
override fun historyResetTo(id: ILineId) = runBlocking { clientSide.historyResetTo(id) }
|
||||
|
||||
}
|
||||
|
||||
fun ReplStateFacadeAsync.toRMI() = ReplStateFacadeRMIWrapper(this)
|
||||
fun CompileService.CallResult<ReplStateFacadeAsync>.toRMI() = when (this) {
|
||||
is CompileService.CallResult.Good -> CompileService.CallResult.Good(this.result.toRMI())
|
||||
is CompileService.CallResult.Dying -> this
|
||||
is CompileService.CallResult.Error -> this
|
||||
is CompileService.CallResult.Ok -> this
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
fun <R> Profiler.withMeasureBlocking(obj: Any?, body: suspend () -> R): R = runBlocking { withMeasure<R>(obj) { body() } }
|
||||
Reference in New Issue
Block a user