migrate to the new annotations syntax

This commit is contained in:
Ilya Chernikov
2015-09-10 13:07:41 +02:00
parent 473ff00940
commit cbaa981aab
7 changed files with 28 additions and 41 deletions
@@ -36,7 +36,7 @@ public object KotlinCompilerClient {
// TODO: remove jvmStatic after all use sites will switch to kotlin // TODO: remove jvmStatic after all use sites will switch to kotlin
jvmStatic @JvmStatic
public fun connectToCompileService(compilerId: CompilerId, public fun connectToCompileService(compilerId: CompilerId,
daemonJVMOptions: DaemonJVMOptions, daemonJVMOptions: DaemonJVMOptions,
daemonOptions: DaemonOptions, daemonOptions: DaemonOptions,
@@ -117,7 +117,7 @@ public object KotlinCompilerClient {
// TODO: remove jvmStatic after all use sites will switch to kotlin // TODO: remove jvmStatic after all use sites will switch to kotlin
jvmStatic @JvmStatic
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<TargetId, IncrementalCache>, compilerOut: OutputStream, daemonOut: OutputStream): Int { public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<TargetId, IncrementalCache>, compilerOut: OutputStream, daemonOut: OutputStream): Int {
val compilerOutStreamServer = RemoteOutputStreamServer(compilerOut) 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 compilerId = CompilerId()
val daemonOptions = DaemonOptions() val daemonOptions = DaemonOptions()
val daemonLaunchingOptions = DaemonJVMOptions() val daemonLaunchingOptions = DaemonJVMOptions()
@@ -351,13 +351,13 @@ public object KotlinCompilerClient {
makeRunFilenameString(timestamp = "lock", makeRunFilenameString(timestamp = "lock",
digest = compilerId.compilerClasspath.map { File(it).absolutePath }.distinctStringsDigest(), digest = compilerId.compilerClasspath.map { File(it).absolutePath }.distinctStringsDigest(),
port = "0")) 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 channel = if (locked) RandomAccessFile(lockFile, "rw").channel else null
private val lock = channel?.lock() private val lock = channel?.lock()
public fun isLocked(): Boolean = locked public fun isLocked(): Boolean = locked
synchronized public fun release(): Unit { @Synchronized public fun release(): Unit {
if (locked) { if (locked) {
lock?.release() lock?.release()
channel?.close() 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 val maxAttempts = COMPILE_DAEMON_STARTUP_LOCK_TIMEOUT_MS / COMPILE_DAEMON_STARTUP_LOCK_TIMEOUT_CHECK_MS + 1
var attempt = 0L var attempt = 0L
while (true) { while (true) {
@@ -28,35 +28,35 @@ public interface CompileService : Remote {
} }
public interface RemoteIncrementalCache : Remote { public interface RemoteIncrementalCache : Remote {
throws(RemoteException::class) @Throws(RemoteException::class)
public fun getObsoletePackageParts(): Collection<String> public fun getObsoletePackageParts(): Collection<String>
throws(RemoteException::class) @Throws(RemoteException::class)
public fun getPackagePartData(fqName: String): ByteArray? public fun getPackagePartData(fqName: String): ByteArray?
throws(RemoteException::class) @Throws(RemoteException::class)
public fun getModuleMappingData(): ByteArray? public fun getModuleMappingData(): ByteArray?
throws(RemoteException::class) @Throws(RemoteException::class)
public fun registerInline(fromPath: String, jvmSignature: String, toPath: String) public fun registerInline(fromPath: String, jvmSignature: String, toPath: String)
throws(RemoteException::class) @Throws(RemoteException::class)
fun getClassFilePath(internalClassName: String): String fun getClassFilePath(internalClassName: String): String
throws(RemoteException::class) @Throws(RemoteException::class)
public fun close() public fun close()
} }
throws(RemoteException::class) @Throws(RemoteException::class)
public fun getCompilerId(): CompilerId public fun getCompilerId(): CompilerId
throws(RemoteException::class) @Throws(RemoteException::class)
public fun getUsedMemory(): Long public fun getUsedMemory(): Long
throws(RemoteException::class) @Throws(RemoteException::class)
public fun shutdown() public fun shutdown()
throws(RemoteException::class) @Throws(RemoteException::class)
public fun remoteCompile( public fun remoteCompile(
args: Array<out String>, args: Array<out String>,
compilerOutputStream: RemoteOutputStream, compilerOutputStream: RemoteOutputStream,
@@ -64,7 +64,7 @@ public interface CompileService : Remote {
serviceOutputStream: RemoteOutputStream serviceOutputStream: RemoteOutputStream
): Int ): Int
throws(RemoteException::class) @Throws(RemoteException::class)
public fun remoteIncrementalCompile( public fun remoteIncrementalCompile(
args: Array<out String>, args: Array<out String>,
caches: Map<TargetId, RemoteIncrementalCache>, caches: Map<TargetId, RemoteIncrementalCache>,
@@ -239,14 +239,14 @@ fun updateEntryDigest(entry: File, md: MessageDigest) {
} }
} }
jvmName("getFilesClasspathDigest_Files") @JvmName("getFilesClasspathDigest_Files")
fun Iterable<File>.getFilesClasspathDigest(): String { fun Iterable<File>.getFilesClasspathDigest(): String {
val md = MessageDigest.getInstance(COMPILER_ID_DIGEST) val md = MessageDigest.getInstance(COMPILER_ID_DIGEST)
this.forEach { updateEntryDigest(it, md) } this.forEach { updateEntryDigest(it, md) }
return md.digest().joinToString("", transform = { "%02x".format(it) }) return md.digest().joinToString("", transform = { "%02x".format(it) })
} }
jvmName("getFilesClasspathDigest_Strings") @JvmName("getFilesClasspathDigest_Strings")
fun Iterable<String>.getFilesClasspathDigest(): String = map { File(it) }.getFilesClasspathDigest() fun Iterable<String>.getFilesClasspathDigest(): String = map { File(it) }.getFilesClasspathDigest()
fun Iterable<String>.distinctStringsDigest(): String = fun Iterable<String>.distinctStringsDigest(): String =
@@ -271,9 +271,9 @@ public data class CompilerId(
} }
companion object { 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<File>): CompilerId = public @JvmStatic fun makeCompilerId(paths: Iterable<File>): CompilerId =
CompilerId(compilerClasspath = paths.map { it.absolutePath }, compilerDigest = paths.getFilesClasspathDigest()) CompilerId(compilerClasspath = paths.map { it.absolutePath }, compilerDigest = paths.getFilesClasspathDigest())
} }
} }
@@ -53,14 +53,14 @@ public object LoopbackNetworkInterface {
data class ServerLoopbackSocketFactory : RMIServerSocketFactory, Serializable { 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)) override fun createServerSocket(port: Int): ServerSocket = ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(loopbackInetAddressName))
} }
data class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable { data class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable {
throws(IOException::class) @Throws(IOException::class)
override fun createSocket(host: String, port: Int): Socket = Socket(InetAddress.getByName(loopbackInetAddressName), port) override fun createSocket(host: String, port: Int): Socket = Socket(InetAddress.getByName(loopbackInetAddressName), port)
} }
} }
@@ -22,12 +22,12 @@ import java.rmi.RemoteException
public interface RemoteOutputStream : Remote { public interface RemoteOutputStream : Remote {
throws(IOException::class, RemoteException::class) @Throws(IOException::class, RemoteException::class)
public fun close() public fun close()
throws(IOException::class, RemoteException::class) @Throws(IOException::class, RemoteException::class)
public fun write(data: ByteArray, offset: Int, length: Int) public fun write(data: ByteArray, offset: Int, length: Int)
throws(IOException::class, RemoteException::class) @Throws(IOException::class, RemoteException::class)
public fun write(dataByte: Int) public fun write(dataByte: Int)
} }
@@ -88,7 +88,7 @@ public object CompileDaemon {
return null return null
} }
jvmStatic public fun main(args: Array<String>) { @JvmStatic public fun main(args: Array<String>) {
log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "<unknown>")) log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "<unknown>"))
log.info("daemon JVM args: " + ManagementFactory.getRuntimeMXBean().inputArguments.joinToString(" ")) log.info("daemon JVM args: " + ManagementFactory.getRuntimeMXBean().inputArguments.joinToString(" "))
@@ -91,7 +91,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
// internal implementation stuff // 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 public val lastUsedSeconds: Long get() = if (rwlock.isWriteLocked || rwlock.readLockCount - rwlock.readHoldCount > 0) nowSeconds() else _lastUsedSeconds
val log by lazy { Logger.getLogger("compiler") } val log by lazy { Logger.getLogger("compiler") }
@@ -161,19 +161,6 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
return (rt.totalMemory() - rt.freeMemory()) 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.threadCpuTime() = if (isCurrentThreadCpuTimeSupported) currentThreadCpuTime else 0L
fun ThreadMXBean.threadUserTime() = if (isCurrentThreadCpuTimeSupported) currentThreadUserTime else 0L fun ThreadMXBean.threadUserTime() = if (isCurrentThreadCpuTimeSupported) currentThreadUserTime else 0L