Open sgammon opened 3 months ago
Thanks for such a detailed issue description. I'll follow along at the coroutines issue for now, as I suspect this behavior is entirely out of our control at this layer.
@JakeWharton I thought initially that Mosaic might be off the hook, but actually this might be multiple issues (or just one really complex one), and at least coroutines thinks it may have to do with Mosaic. I've isolated this to a simple reproducer; see the tracker issue at elide-dev/elide#972. Back on our own codebase, I can isolate this into an interesting stacktrace:
...
Suppressed: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[BlockingEventLoop@4a98064b, Continuation at com.jakewharton.mosaic.MosaicKt$runMosaic$2.invokeSuspend(mosaic.kt)@6732a44]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:140)
... 21 more
Caused by: java.lang.IncompatibleClassChangeError
at kotlin.coroutines.CombinedContext.get(CoroutineContextImpl.kt:125)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:93)
... 20 more
...
Exception in thread "main" java.lang.RuntimeException: Exception while trying to handle coroutine exception at kotlinx.coroutines.CoroutineExceptionHandlerKt.handlerException(CoroutineExceptionHandler.kt:35) at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:26) at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:142) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:111) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:263) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69) at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:47) at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source) at com.jakewharton.mosaic.BlockingKt.runMosaicBlocking(blocking.kt:6) at elide.tool.cli.AbstractToolCommand.call(AbstractToolCommand.kt:260) at elide.tool.cli.AbstractToolCommand.call(AbstractToolCommand.kt:30) at picocli.CommandLine.executeUserObject(CommandLine.java:2045) at picocli.CommandLine.access$1500(CommandLine.java:148) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2465) at picocli.CommandLine$RunLast.handle(CommandLine.java:2457) at picocli.CommandLine$RunLast.handle(CommandLine.java:2419) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2277) at picocli.CommandLine$RunLast.execute(CommandLine.java:2421) at picocli.CommandLine.execute(CommandLine.java:2174) at elide.tool.cli.Elide$Companion.exec$runtime(Elide.kt:232) at elide.tool.cli.Elide$Companion.entry(Elide.kt:195) at elide.tool.cli.ElideKt.main(Elide.kt:305) Suppressed: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[BlockingEventLoop@4a98064b, Continuation at com.jakewharton.mosaic.MosaicKt$runMosaic$2.invokeSuspend(mosaic.kt)@6732a44]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:140) ... 21 more Caused by: java.lang.IncompatibleClassChangeError at kotlin.coroutines.CombinedContext.get(CoroutineContextImpl.kt:125) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:93) ... 20 more Exception in thread "main" java.lang.IncompatibleClassChangeError at kotlin.coroutines.CombinedContext.fold(CoroutineContextImpl.kt:131) at kotlin.coroutines.CombinedContext.toString(CoroutineContextImpl.kt:174) at kotlinx.coroutines.internal.DiagnosticCoroutineContextException.getLocalizedMessage(CoroutineExceptionHandlerImpl.kt:37) at java.base@22.0.1/java.lang.Throwable.toString(Throwable.java:519) at java.base@22.0.1/java.lang.String.valueOf(String.java:4507) at java.base@22.0.1/java.lang.Throwable.printEnclosedStackTrace(Throwable.java:745) at java.base@22.0.1/java.lang.Throwable.lockedPrintStackTrace(Throwable.java:713) at java.base@22.0.1/java.lang.Throwable.printStackTrace(Throwable.java:695) at java.base@22.0.1/java.lang.Throwable.printStackTrace(Throwable.java:682) at java.base@22.0.1/java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:698) at java.base@22.0.1/java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) at kotlinx.coroutines.internal.CoroutineExceptionHandlerImplKt.propagateExceptionFinalResort(CoroutineExceptionHandlerImpl.kt:31) at kotlinx.coroutines.internal.CoroutineExceptionHandlerImpl_commonKt.handleUncaughtCoroutineException(CoroutineExceptionHandlerImpl.common.kt:48) at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:26) at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:142) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:111) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:263) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69) at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:47) at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source) at com.jakewharton.mosaic.BlockingKt.runMosaicBlocking(blocking.kt:6) at elide.tool.cli.AbstractToolCommand.call(AbstractToolCommand.kt:260) at elide.tool.cli.AbstractToolCommand.call(AbstractToolCommand.kt:30) at picocli.CommandLine.executeUserObject(CommandLine.java:2045) at picocli.CommandLine.access$1500(CommandLine.java:148) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2465) at picocli.CommandLine$RunLast.handle(CommandLine.java:2457) at picocli.CommandLine$RunLast.handle(CommandLine.java:2419) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2277) at picocli.CommandLine$RunLast.execute(CommandLine.java:2421) at picocli.CommandLine.execute(CommandLine.java:2174) at elide.tool.cli.Elide$Companion.exec$runtime(Elide.kt:232) at elide.tool.cli.Elide$Companion.entry(Elide.kt:195) at elide.tool.cli.ElideKt.main(Elide.kt:305)
Does this exception even make any sense to you? I'm in Gradle, and this was against Mosaic latest/coroutines latest.
Okay, sorry for the volume of comments, but I've been able to work around this for now by restoring to:
0.12.0
1.5.13-dev-k2.0.0-RC1-50f08dfa4b4
We have a suite of "self tests" in our binary which use the Jest sample. The output looks like this normally:
Running these at the latest GraalVM release, and release of Mosaic, produces a crash:
After investigating further, I was able to produce an exception:
The snippets of code in question:
AbstractToolCommand.kt
:I have shortened this to use the counter example instead. The code I'm using is:
2.0.0
2.0.0
(built-in)0.13.0
1.9.0-RC
0.24.0
The relevant lines from Coroutines show that this is failing at an AtomicFU callsite:
I have tried really hard to debug further and gotten nowhere. Some other details I've been able to confirm:
-O3
and-O4
produce crashes (bus error
orsegmentation fault
)-O2
produces the stacktrace above-O1
and-O0
seem to producebus error
The failure ultimately happens because
System.classData
is called, which is substituted under SVM.AtomicReferenceFieldUpdater
calls this as part ofaccessCheck
, through a failed call toisInstance
; the failedisInstance
check throws withthrowAccessCheckException
, which uses reflection and is present in the stacktrace.2.0.0-RC3
1.5.13-dev-k2.0.0-RC1-50f08dfa4b4
(Android)0.11.0
1.8.0
0.23.2
I intend to cross-file with the Coroutines and GraalVM teams. I can supply test binaries, symbols, and a reproducer in-situ.