Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
utgheith opened this issue Oct 22, 2024 · 1 comment
Assignees

Comments

@utgheith
Copy link

utgheith commented Oct 22, 2024

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

  • I tried the -H:ThrowMissingRegistrationErrors= flag.

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 [email protected]/java.lang.System.getProperties(System.java:380)
	at Bad.lambda$main$0(Bad.java:5)
	at [email protected]/java.lang.Thread.runWith(Thread.java:1588)
	at [email protected]/java.lang.VirtualThread.run(VirtualThread.java:329)
	at [email protected]/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 [email protected]/java.lang.System.getProperties(System.java:380)
	at Bad.lambda$main$0(Bad.java:5)
	at [email protected]/java.lang.Thread.runWith(Thread.java:1588)
	at [email protected]/java.lang.VirtualThread.run(VirtualThread.java:329)
	at [email protected]/java.lang.VirtualThread$VThreadContinuation$1.run(VirtualThread.java:209)
@utgheith utgheith changed the title [Native Image] System.getProperties() fails when called from a native thread starting with Graalvm:22 [Native Image] System.getProperties() fails when called from a virtual thread starting with Graalvm:22 Oct 23, 2024
@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Oct 24, 2024
@oubidar-Abderrahim oubidar-Abderrahim changed the title [Native Image] System.getProperties() fails when called from a virtual thread starting with Graalvm:22 [GR-59499][Native Image] System.getProperties() fails when called from a virtual thread starting with Graalvm:22 Oct 31, 2024
@andriy-dmytruk
Copy link

andriy-dmytruk commented Nov 15, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants