Refactor daemon tests, some minor fixes in the client and daemon
Tests refactored for better readability and code reuse Some shutdown livelock is fixed Some logging added
This commit is contained in:
+3
@@ -145,6 +145,7 @@ object KotlinCompilerClient {
|
||||
compilerService.releaseCompileSession(sessionId)
|
||||
}
|
||||
|
||||
@Deprecated("Use other compile method", ReplaceWith("compile"))
|
||||
fun compile(compilerService: CompileService,
|
||||
sessionId: Int,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
@@ -158,6 +159,7 @@ object KotlinCompilerClient {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Use non-deprecated compile method", ReplaceWith("compile"))
|
||||
fun incrementalCompile(compileService: CompileService,
|
||||
sessionId: Int,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
@@ -308,6 +310,7 @@ object KotlinCompilerClient {
|
||||
|
||||
// --- Implementation ---------------------------------------
|
||||
|
||||
@Synchronized
|
||||
private inline fun <R> connectLoop(reportingTargets: DaemonReportingTargets, body: () -> R?): R? {
|
||||
try {
|
||||
var attempts = 0
|
||||
|
||||
@@ -335,6 +335,7 @@ class CompileServiceImpl(
|
||||
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
|
||||
val compilerMode = compilationOptions.compilerMode
|
||||
val targetPlatform = compilationOptions.targetPlatform
|
||||
log.info("Starting compilation with args: " + compilerArguments.joinToString(" "))
|
||||
val k2PlatformArgs = try {
|
||||
when (targetPlatform) {
|
||||
CompileService.TargetPlatform.JVM -> K2JVMCompilerArguments().apply { K2JVMCompiler().parseArguments(compilerArguments, this) }
|
||||
@@ -709,6 +710,10 @@ class CompileServiceImpl(
|
||||
|
||||
private fun shutdownImpl() {
|
||||
log.info("Shutdown started")
|
||||
fun Long.mb() = this / (1024 * 1024)
|
||||
with (Runtime.getRuntime()) {
|
||||
log.info("Memory stats: total: ${totalMemory().mb()}mb, free: ${freeMemory().mb()}mb, max: ${maxMemory().mb()}mb")
|
||||
}
|
||||
state.alive.set(Aliveness.Dying.ordinal)
|
||||
|
||||
UnicastRemoteObject.unexportObject(this, true)
|
||||
@@ -869,9 +874,18 @@ class CompileServiceImpl(
|
||||
ifAliveChecksImpl(minAliveness, ignoreCompilerChanged, body)
|
||||
}
|
||||
|
||||
inline private fun<R> ifAliveChecksImpl(minAliveness: Aliveness = Aliveness.Alive, ignoreCompilerChanged: Boolean = false, body: () -> CompileService.CallResult<R>): CompileService.CallResult<R> =
|
||||
when {
|
||||
state.alive.get() < minAliveness.ordinal -> CompileService.CallResult.Dying()
|
||||
inline private fun<R> ifAliveChecksImpl(minAliveness: Aliveness = Aliveness.Alive, ignoreCompilerChanged: Boolean = false, body: () -> CompileService.CallResult<R>): CompileService.CallResult<R> {
|
||||
val curState = state.alive.get()
|
||||
return when {
|
||||
curState < minAliveness.ordinal -> {
|
||||
log.info("Cannot perform operation, requested state: ${minAliveness.name} > actual: ${try {
|
||||
Aliveness.values()[curState].name
|
||||
}
|
||||
catch (_: Throwable) {
|
||||
"invalid($curState)"
|
||||
}}")
|
||||
CompileService.CallResult.Dying()
|
||||
}
|
||||
!ignoreCompilerChanged && classpathWatcher.isChanged -> {
|
||||
log.info("Compiler changed, scheduling shutdown")
|
||||
shutdownWithDelay()
|
||||
@@ -887,6 +901,7 @@ class CompileServiceImpl(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun<R> withValidClientOrSessionProxy(sessionId: Int,
|
||||
body: (ClientOrSessionProxy<Any>?) -> CompileService.CallResult<R>
|
||||
|
||||
Reference in New Issue
Block a user