oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.45k stars 1.64k forks source link

[GR-32914] Kotlin 1.5.10 and nativeImage gradle builds fail #3466

Closed yschimke closed 3 weeks ago

yschimke commented 3 years ago

Describe the issue

Kotlin 1.5.21 and nativeImage gradle builds fail

Steps to reproduce the issue

See https://github.com/square/okhttp/runs/2816094342?check_suite_focus=true

[ConsoleLauncher:1931]   (features):   2,117.94 ms,  2.82 GB
Error: Unsupported features in 5 methods
[ConsoleLauncher:1931]     analysis:  97,213.36 ms,  2.82 GB
Detailed message:
Error: unbalanced monitors: mismatch at monitorexit, 106|LoadField#this$0 != 162|LoadField#this$0
Call path from entry point to okhttp3.internal.http2.Http2Connection$pushHeadersLater$$inlined$execute$default$1.runOnce(): 
    at okhttp3.internal.http2.Http2Connection$pushHeadersLater$$inlined$execute$default$1.runOnce(TaskQueue.kt:98)
    at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:116)
    at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42)
    at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:65)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:553)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
    at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Original exception that caused the problem: org.graalvm.compiler.code.SourceStackTraceBailoutException$1: unbalanced monitors: mismatch at monitorexit, 106|LoadField#this$0 != 162|LoadField#this$0
    at okhttp3.internal.http2.Http2Connection$pushHeadersLater$$inlined$execute$default$1.runOnce(TaskQueue.kt:225)
Caused by: org.graalvm.compiler.core.common.PermanentBailoutException: unbalanced monitors: mismatch at monitorexit, 106|LoadField#this$0 != 162|LoadField#this$0
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.bailout(BytecodeParser.java:3974)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genMonitorExit(BytecodeParser.java:2842)

Please include both build steps as well as run steps

  1. git clone https://github.com/square/okhttp
  2. git checkout bff87d1fc6bf1527a4052b0b5251fab53238f714
  3. ./gradlew okcurl:nativeImage or
  4. ./gradlew -PgraalBuild native-image-tests:nativeImage

Describe GraalVM and your environment:

munishchouhan commented 3 years ago

@yschimke thanks for reporting the issue We will check it out and get back to you

munishchouhan commented 3 years ago

@yschimke Apologies for replying so late, but when I tried to check out the branch in the reproducer, I am getting the following error: git checkout 7842d7da9f89d99b85f6a539a146b678c7558417 fatal: reference is not a tree: 7842d7da9f89d99b85f6a539a146b678c7558417

munishchouhan commented 3 years ago

Hi @yschimke any update on this?

yschimke commented 3 years ago

@mcraj017 my bad, I had pushed my commit to my fork, not the square org repo. I've updated the PR (SHA bff87d1fc6bf1527a4052b0b5251fab53238f714) and pushed to square org. Should work now.

https://github.com/square/okhttp/pull/6777

yschimke commented 3 years ago

This workaround fixes it

--- a/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt
+++ b/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt
@@ -76,22 +76,24 @@ class TaskQueue internal constructor(
   }

   /** Overload of [schedule] that uses a lambda for a repeating task. */
-  inline fun schedule(
+  fun schedule(
     name: String,
     delayNanos: Long = 0L,
-    crossinline block: () -> Long
+    block: () -> Long
   ) {
     schedule(object : Task(name) {
-      override fun runOnce() = block()
+      override fun runOnce(): Long {
+        return block()
+      }
     }, delayNanos)
   }

   /** Executes [block] once on a task runner thread. */
-  inline fun execute(
+  fun execute(
     name: String,
     delayNanos: Long = 0L,
     cancelable: Boolean = true,
-    crossinline block: () -> Unit
+    block: () -> Unit
   ) {
     schedule(object : Task(name, cancelable) {
       override fun runOnce(): Long {
munishchouhan commented 3 years ago

@yschimke thanks for that, i will check it out and let you know

munishchouhan commented 3 years ago

@yschimke I have raised the bug to native-image team

swankjesse commented 2 years ago

Updates?

swankjesse commented 11 months ago

Updates?

wirthi commented 3 weeks ago

Since this ticket was reported, we had numerous fixes and improvements around unbalanced monitors; this should now be supported. Graal still enforces structured locking but won't bailout at build time anymore if unstructured locking or related monitor patterns are encountered.