Graal: [native-image] Error when compiling projects with Kotlin Coroutines

Created on 7 Nov 2018  路  3Comments  路  Source: oracle/graal

When compiling a Spring Fu application that is using Kotlin Coroutines 1.0.0, I get the following error while the same application with Reactive only API compiles correctly.

fatal error: com.oracle.svm.core.util.VMError$HostedError: Non-instantiated type referenced by a compiled method: kotlin.Result$Companion
    at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:66)
    at com.oracle.svm.hosted.image.NativeImageCodeCache.addConstantToHeap(NativeImageCodeCache.java:366)
    at com.oracle.svm.hosted.image.NativeImageCodeCache.addConstantsToHeap(NativeImageCodeCache.java:350)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:887)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:402)
    at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Processing image build request failed
native-image

Most helpful comment

@sdeleuze thanks for the report! @zarechenskiy thanks for the minimal reproducer! The issue is fixed in https://github.com/oracle/graal/commit/57199de5ef7c04cd9e11ec00a750956c3fcca386.

All 3 comments

Worth to notice: kotlin.Result is an inline class, a new feature from Kotlin 1.3, so the issue could maybe come from that. https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/coroutines/src/kotlin/Result.kt

I created the following issue on Kotlin side: https://youtrack.jetbrains.com/issue/KT-28050

I'd love to show a minimized version of the issue:

// kotlin 1.3.11
suspend fun main() {
    foo()
}

suspend fun foo() {}

Note that if you place Result.toString or Result.Companion.toString() (which is the same) at the beginning of the main function, then the error will be gone:

// kotlin 1.3.11
suspend fun main() {
    Result.toString()
    foo()
}

suspend fun foo() {}

There are several references to kotlin/Result$Failure in the generated bytecode, which doesn't seem illegal (at least from the first glance).
Maybe you could provide more information why this error appears? Could it be a bug in GraalVM?

@sdeleuze thanks for the report! @zarechenskiy thanks for the minimal reproducer! The issue is fixed in https://github.com/oracle/graal/commit/57199de5ef7c04cd9e11ec00a750956c3fcca386.

Was this page helpful?
0 / 5 - 0 ratings