Closed Jire closed 8 years ago
Quasar seems extremely glitchy in my use cases. For example the following straightforward code results in hi there
being printed twice.
fiber {
println("hi there")
Fiber.sleep(3000)
println("hi there later")
}
Shouldn't sleep
be @Suspendable
?
@circlespainter you're right. This fixes the VerifyError but the application still prints numerous times. It may be a bug in Kotlin.
Ok, this is somewhat articulated:
0.7.4-SNAPSHOT
on Sonatype Snapshots with Kotlin 1.0.0-beta-3595
(which is the official Beta 3).@Suspendable
is also needed on the closure passed to fiber
(docs updated). More precisely the agent method doesn't need it but instead AoT seems to need it.kotlin
branch of the quasar-gradle-template has been updated accordingly and it has both agent and AoT modes (see README.md
).every
method, as if the sleep
call site hadn't been instrumented and without verification errors, but this happens only when using AoT (hence the issue title update and the bug label):package org.abendigo
import co.paralleluniverse.fibers.Fiber
import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.kotlin.fiber
import co.paralleluniverse.strands.Strand
import java.util.*
import java.util.concurrent.TimeUnit
@Suspendable fun sleep(duration: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS) = Strand.sleep(duration, timeUnit)
inline fun <T> every(duration: Int, timeUnit: TimeUnit = TimeUnit.MILLISECONDS, crossinline action: () -> T):
Fiber<Unit> = every(duration.toLong(), timeUnit, action)
inline fun <T> every(duration: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS, crossinline action: () -> T) =
fiber @Suspendable {
println("\nEvery - start\n")
action()
while (true) {
println("Every - sleeping")
sleep(duration, timeUnit)
println("Every - action")
action()
}
}
public fun main(args: Array<String>) {
every(1000) { println("test ${Date().time}") }
Thread.sleep(Long.MAX_VALUE)
}
Workaround: use the agent instead.
@circlespainter If I use non-AoT it does work properly as expected which is fine for development purposes. Unfortunately I need AoT because my software needs to be given to regular clients. Hopefully the bug will be fixed soon, thanks!
@circlespainter When using Quasar's agent instrumentation the following code fails:
val TYPE_TO_BYTES = mapOf(Boolean::class.qualifiedName to 1, Byte::class.qualifiedName to 1,
Short::class.qualifiedName to 2, Int::class.qualifiedName to 4, Long::class.qualifiedName to 8,
Float::class.qualifiedName to 4, Double::class.qualifiedName to 8)
due to
java.lang.NoClassDefFoundError: Could not initialize class kotlin.reflect.jvm.internal.impl.platform.JavaToKotlinClassMap
at kotlin.reflect.jvm.internal.RuntimeTypeMapper.mapJvmClassToKotlinClassId(RuntimeTypeMapper.kt:244)
at kotlin.reflect.jvm.internal.KClassImpl.getClassId(KClassImpl.kt:56)
at kotlin.reflect.jvm.internal.KClassImpl.getQualifiedName(KClassImpl.kt:109)
Is the above problem somewhat related to the previous one? If not, do you mind opening a separate issue? Also, does it happen with AoT too? What does it say if you turn instrumentation debugging on (append =vdc
to the agent)?
As for agent-based instrumentation: why is it a problem to ship a final product to clients using it? It is perfectly fine in production and actually it's even the only way to use some Comsat integrations without having to AoT-instrument and repackage 3rd-party libraries. If your only concern is to simplify deployment (and I can see no other) just use Capsule.
@circlespainter I will open a new issue with more information about my problem.
I intend to deliver my app as a single JAR and I thought I'd have to include scripts to pass the Quasar arguments and wouldn't I also have to include the Quasar core JAR? Does Capsule let me pack Quasar core inside of a single JAR and run it with AoT?
@Jire Sorry, missed your comment. Yes, Capsule allows you to pack Java/native agents and everything you need in a single JAR.
@Jire Ok, I now believe this is a duplicate of #112: if you remove inlining it works (for me at least). If you confirm I'll close this issue and bring the code to the existing one.
This is with Kotlin 1.0.0-beta-3595. I am receiving a VerifyError with this code: