From cbaa981aab95cfb3784d9e15e659d23d7b878e3a Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 10 Sep 2015 13:07:41 +0200 Subject: [PATCH] migrate to the new annotations syntax --- .../rmi/kotlinr/KotlinCompilerClient.kt | 12 +++++----- .../jetbrains/kotlin/rmi/CompileService.kt | 22 +++++++++---------- .../org/jetbrains/kotlin/rmi/DaemonParams.kt | 8 +++---- .../org/jetbrains/kotlin/rmi/NetworkUtils.kt | 4 ++-- .../kotlin/rmi/RemoteOutputStream.kt | 6 ++--- .../kotlin/rmi/service/CompileDaemon.kt | 2 +- .../kotlin/rmi/service/CompileServiceImpl.kt | 15 +------------ 7 files changed, 28 insertions(+), 41 deletions(-) diff --git a/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt b/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt index 27e82b1d4d6..e2f97e23ce7 100644 --- a/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt +++ b/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt @@ -36,7 +36,7 @@ public object KotlinCompilerClient { // TODO: remove jvmStatic after all use sites will switch to kotlin - jvmStatic + @JvmStatic public fun connectToCompileService(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, @@ -117,7 +117,7 @@ public object KotlinCompilerClient { // TODO: remove jvmStatic after all use sites will switch to kotlin - jvmStatic + @JvmStatic public fun incrementalCompile(compiler: CompileService, args: Array, caches: Map, compilerOut: OutputStream, daemonOut: OutputStream): Int { val compilerOutStreamServer = RemoteOutputStreamServer(compilerOut) @@ -143,7 +143,7 @@ public object KotlinCompilerClient { } - jvmStatic public fun main(vararg args: String) { + @JvmStatic public fun main(vararg args: String) { val compilerId = CompilerId() val daemonOptions = DaemonOptions() val daemonLaunchingOptions = DaemonJVMOptions() @@ -351,13 +351,13 @@ public object KotlinCompilerClient { makeRunFilenameString(timestamp = "lock", digest = compilerId.compilerClasspath.map { File(it).absolutePath }.distinctStringsDigest(), port = "0")) - private volatile var locked = acquireLockFile(lockFile) + private @Volatile var locked = acquireLockFile(lockFile) private val channel = if (locked) RandomAccessFile(lockFile, "rw").channel else null private val lock = channel?.lock() public fun isLocked(): Boolean = locked - synchronized public fun release(): Unit { + @Synchronized public fun release(): Unit { if (locked) { lock?.release() channel?.close() @@ -366,7 +366,7 @@ public object KotlinCompilerClient { } } - synchronized private fun acquireLockFile(lockFile: File): Boolean { + @Synchronized private fun acquireLockFile(lockFile: File): Boolean { val maxAttempts = COMPILE_DAEMON_STARTUP_LOCK_TIMEOUT_MS / COMPILE_DAEMON_STARTUP_LOCK_TIMEOUT_CHECK_MS + 1 var attempt = 0L while (true) { diff --git a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/CompileService.kt b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/CompileService.kt index 5160d1caa97..6c01ffba748 100644 --- a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/CompileService.kt +++ b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/CompileService.kt @@ -28,35 +28,35 @@ public interface CompileService : Remote { } public interface RemoteIncrementalCache : Remote { - throws(RemoteException::class) + @Throws(RemoteException::class) public fun getObsoletePackageParts(): Collection - throws(RemoteException::class) + @Throws(RemoteException::class) public fun getPackagePartData(fqName: String): ByteArray? - throws(RemoteException::class) + @Throws(RemoteException::class) public fun getModuleMappingData(): ByteArray? - throws(RemoteException::class) + @Throws(RemoteException::class) public fun registerInline(fromPath: String, jvmSignature: String, toPath: String) - throws(RemoteException::class) + @Throws(RemoteException::class) fun getClassFilePath(internalClassName: String): String - throws(RemoteException::class) + @Throws(RemoteException::class) public fun close() } - throws(RemoteException::class) + @Throws(RemoteException::class) public fun getCompilerId(): CompilerId - throws(RemoteException::class) + @Throws(RemoteException::class) public fun getUsedMemory(): Long - throws(RemoteException::class) + @Throws(RemoteException::class) public fun shutdown() - throws(RemoteException::class) + @Throws(RemoteException::class) public fun remoteCompile( args: Array, compilerOutputStream: RemoteOutputStream, @@ -64,7 +64,7 @@ public interface CompileService : Remote { serviceOutputStream: RemoteOutputStream ): Int - throws(RemoteException::class) + @Throws(RemoteException::class) public fun remoteIncrementalCompile( args: Array, caches: Map, diff --git a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt index f61ab210dc9..a6025c77426 100644 --- a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt +++ b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/DaemonParams.kt @@ -239,14 +239,14 @@ fun updateEntryDigest(entry: File, md: MessageDigest) { } } -jvmName("getFilesClasspathDigest_Files") +@JvmName("getFilesClasspathDigest_Files") fun Iterable.getFilesClasspathDigest(): String { val md = MessageDigest.getInstance(COMPILER_ID_DIGEST) this.forEach { updateEntryDigest(it, md) } return md.digest().joinToString("", transform = { "%02x".format(it) }) } -jvmName("getFilesClasspathDigest_Strings") +@JvmName("getFilesClasspathDigest_Strings") fun Iterable.getFilesClasspathDigest(): String = map { File(it) }.getFilesClasspathDigest() fun Iterable.distinctStringsDigest(): String = @@ -271,9 +271,9 @@ public data class CompilerId( } companion object { - public jvmStatic fun makeCompilerId(vararg paths: File): CompilerId = makeCompilerId(paths.asIterable()) + public @JvmStatic fun makeCompilerId(vararg paths: File): CompilerId = makeCompilerId(paths.asIterable()) - public jvmStatic fun makeCompilerId(paths: Iterable): CompilerId = + public @JvmStatic fun makeCompilerId(paths: Iterable): CompilerId = CompilerId(compilerClasspath = paths.map { it.absolutePath }, compilerDigest = paths.getFilesClasspathDigest()) } } diff --git a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/NetworkUtils.kt b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/NetworkUtils.kt index 4558d7dc2ca..633e5c5f449 100644 --- a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/NetworkUtils.kt +++ b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/NetworkUtils.kt @@ -53,14 +53,14 @@ public object LoopbackNetworkInterface { data class ServerLoopbackSocketFactory : RMIServerSocketFactory, Serializable { - throws(IOException::class) + @Throws(IOException::class) override fun createServerSocket(port: Int): ServerSocket = ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(loopbackInetAddressName)) } data class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable { - throws(IOException::class) + @Throws(IOException::class) override fun createSocket(host: String, port: Int): Socket = Socket(InetAddress.getByName(loopbackInetAddressName), port) } } diff --git a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/RemoteOutputStream.kt b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/RemoteOutputStream.kt index a295bf34ba1..c480490d3b7 100644 --- a/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/RemoteOutputStream.kt +++ b/compiler/rmi/rmi-interface/src/org/jetbrains/kotlin/rmi/RemoteOutputStream.kt @@ -22,12 +22,12 @@ import java.rmi.RemoteException public interface RemoteOutputStream : Remote { - throws(IOException::class, RemoteException::class) + @Throws(IOException::class, RemoteException::class) public fun close() - throws(IOException::class, RemoteException::class) + @Throws(IOException::class, RemoteException::class) public fun write(data: ByteArray, offset: Int, length: Int) - throws(IOException::class, RemoteException::class) + @Throws(IOException::class, RemoteException::class) public fun write(dataByte: Int) } diff --git a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileDaemon.kt b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileDaemon.kt index ed25d1010cd..a3df5ccfe3f 100644 --- a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileDaemon.kt +++ b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileDaemon.kt @@ -88,7 +88,7 @@ public object CompileDaemon { return null } - jvmStatic public fun main(args: Array) { + @JvmStatic public fun main(args: Array) { log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "")) log.info("daemon JVM args: " + ManagementFactory.getRuntimeMXBean().inputArguments.joinToString(" ")) diff --git a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt index 4f1c726531e..00529f9cff9 100644 --- a/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt +++ b/compiler/rmi/rmi-server/src/org/jetbrains/kotlin/rmi/service/CompileServiceImpl.kt @@ -91,7 +91,7 @@ class CompileServiceImpl>( // internal implementation stuff - private volatile var _lastUsedSeconds = nowSeconds() + private @Volatile var _lastUsedSeconds = nowSeconds() public val lastUsedSeconds: Long get() = if (rwlock.isWriteLocked || rwlock.readLockCount - rwlock.readHoldCount > 0) nowSeconds() else _lastUsedSeconds val log by lazy { Logger.getLogger("compiler") } @@ -161,19 +161,6 @@ class CompileServiceImpl>( return (rt.totalMemory() - rt.freeMemory()) } - // TODO: consider using version as a part of compiler ID or drop this function - private fun loadKotlinVersionFromResource(): String { - (javaClass.classLoader as? URLClassLoader) - ?.findResource("META-INF/MANIFEST.MF") - ?.let { - try { - return Manifest(it.openStream()).mainAttributes.getValue("Implementation-Version") ?: "" - } - catch (e: IOException) {} - } - return "" - } - fun ThreadMXBean.threadCpuTime() = if (isCurrentThreadCpuTimeSupported) currentThreadCpuTime else 0L fun ThreadMXBean.threadUserTime() = if (isCurrentThreadCpuTimeSupported) currentThreadUserTime else 0L