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.4k stars 1.64k forks source link

[GR-59499][Native Image] System.getProperties() fails when called from a virtual thread starting with Graalvm:22 #9939

Open utgheith opened 3 weeks ago

utgheith commented 3 weeks ago

Describe the Issue

This program works with GraalVM:21 but fails with GraalVM:22 and GraalVM:23

class Bad {
   public static void main(String[] args) throws Exception {
       Thread.ofVirtual().start(() ->
            System.out.println(System.getProperties())
            //System.out.println(java.time.ZoneId.systemDefault())
       ).join();
   }
}

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

openjdk version "23.0.1" 2024-10-15 OpenJDK Runtime Environment GraalVM CE 23.0.1+11.1 (build 23.0.1+11-jvmci-b01) OpenJDK 64-Bit Server VM GraalVM CE 23.0.1+11.1 (build 23.0.1+11-jvmci-b01, mixed mode, sharing)

Operating System and Version

Darwin ags-imac.lan 22.6.0 Darwin Kernel Version 22.6.0: Mon Jun 24 01:25:37 PDT 2024; root:xnu-8796.141.3.706.2~1/RELEASE_X86_64 x86_64

Diagnostic Flag Confirmation

Run Command

javac Bad.java
native-image -cp . Bad
./bad

Expected Behavior

worked

Actual Behavior

Exception in thread "" java.lang.IllegalThreadStateException: StackValue must not be used in a virtual thread unless the method is annotated @Uninterruptible.
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.graal.stackvalue.StackValueSnippets.throwNewException(StackValueSnippets.java:103)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixLibCSupport.malloc(PosixLibCSupport.java:65)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.UnmanagedMemorySupportImpl.malloc(UnmanagedMemorySupportImpl.java:54)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.UntrackedNullableNativeMemory.malloc(UntrackedNullableNativeMemory.java:57)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.NullableNativeMemory.malloc(NullableNativeMemory.java:57)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixUtils.getUserNameOrDir(PosixUtils.java:363)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixUtils.getUserDir(PosixUtils.java:352)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixSystemPropertiesSupport.userHomeValue(PosixSystemPropertiesSupport.java:51)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.userHome(SystemPropertiesSupport.java:259)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeLazyValue(SystemPropertiesSupport.java:237)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.ensureFullyInitialized(SystemPropertiesSupport.java:161)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.getProperties(SystemPropertiesSupport.java:177)
    at java.base@23.0.1/java.lang.System.getProperties(System.java:380)
    at Bad.lambda$main$0(Bad.java:5)
    at java.base@23.0.1/java.lang.Thread.runWith(Thread.java:1588)
    at java.base@23.0.1/java.lang.VirtualThread.run(VirtualThread.java:329)
    at java.base@23.0.1/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:209)

Steps to Reproduce

(1) put the graalvm binaries in your path (2) create a file named Bad.java and put the code above in it (3) javac Bad.jva (4) native-image -cp . Bad (5) ./bad

Additional Context

Tried on different Ubuntu releases, same problem

Run-Time Log Output and Error Messages

Exception in thread "" java.lang.IllegalThreadStateException: StackValue must not be used in a virtual thread unless the method is annotated @Uninterruptible.
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.graal.stackvalue.StackValueSnippets.throwNewException(StackValueSnippets.java:103)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixLibCSupport.malloc(PosixLibCSupport.java:65)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.UnmanagedMemorySupportImpl.malloc(UnmanagedMemorySupportImpl.java:54)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.UntrackedNullableNativeMemory.malloc(UntrackedNullableNativeMemory.java:57)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.memory.NullableNativeMemory.malloc(NullableNativeMemory.java:57)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixUtils.getUserNameOrDir(PosixUtils.java:363)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixUtils.getUserDir(PosixUtils.java:352)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.PosixSystemPropertiesSupport.userHomeValue(PosixSystemPropertiesSupport.java:51)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.userHome(SystemPropertiesSupport.java:259)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeLazyValue(SystemPropertiesSupport.java:237)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.ensureFullyInitialized(SystemPropertiesSupport.java:161)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.SystemPropertiesSupport.getProperties(SystemPropertiesSupport.java:177)
    at java.base@23.0.1/java.lang.System.getProperties(System.java:380)
    at Bad.lambda$main$0(Bad.java:5)
    at java.base@23.0.1/java.lang.Thread.runWith(Thread.java:1588)
    at java.base@23.0.1/java.lang.VirtualThread.run(VirtualThread.java:329)
    at java.base@23.0.1/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:209)
andriy-dmytruk commented 20 hours ago

I am facing the same issue, but the method in question is java.time.LocalDateTime.now(). Calling it from a virtual thread produces the same error:

Suppressed: java.lang.IllegalThreadStateException: StackValue must not be used in a virtual thread unless the method is annotated @Uninterruptible.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.graal.stackvalue.StackValueSnippets.throwNewException(StackValueSnippets.java:103)
        at java.base@21.0.2/jdk.internal.misc.VM.getNanoTimeAdjustment(VM.java:42)
        at java.base@21.0.2/java.time.Clock.currentInstant(Clock.java:498)
        at java.base@21.0.2/java.time.Clock$SystemClock.instant(Clock.java:614)
        at java.base@21.0.2/java.time.LocalDateTime.now(LocalDateTime.java:213)
        at java.base@21.0.2/java.time.LocalDateTime.now(LocalDateTime.java:182)