-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Native Image] -H:+AllowJRTFileSystem reads from GraalVM instead of the provided JAVA_HOME #10013
Comments
It seems that the |
To give you more context, here's my workaround for one of the Espresso demos: |
Thanks for taking a look, I tried adapting the repro to set the system properties on the command line and at runtime, and was still seeing the same issue. Also note that the jrt filesystem supports setting the Java home as part of the environment passed to import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
public class JRTFS {
public static void main(String[] args) throws IOException {
String javaHome = args[0];
System.setProperty("java.home", javaHome);
System.setProperty("org.graalvm.home", javaHome);
FileSystem fileSystem =
FileSystems.newFileSystem(URI.create("jrt:/"), Map.of("java.home", javaHome));
Path path = fileSystem.getPath("/modules/java.base/module-info.class");
System.err.printf("%s %s\n", path, Files.size(path));
}
}
|
Hey @cushon, I debugged the issue, but I can only foresee a partial fix. Passing a It relies on dynamically loading the ATM, Native Image JRT support is meant to access the same VM used to build the image (specified by Can you please provide more details on your use case? Note: I found another bug that breaks the intended behavior of accessing the JRT FS for the provided |
Thanks for the explanation, I'd forgotten about how the jrt filesystem dynamically loads The use-case is a build tool that needs to resolve definitions of JDK APIs, conceptually it's trying to do the same thing as javac's
That sounds interesting. I wonder how compatible it would be in practice, I don't know much the format has changed between JDK versions. |
Describe the Issue
Using
-H:+AllowJRTFileSystem
creates a native image that reads from the Graal JDK's module files, instead of reading from the provided JAVA_HOME.Using the latest version of GraalVM can resolve many issues.
GraalVM Version
java version "23.0.1" 2024-10-15
Java(TM) SE Runtime Environment Oracle GraalVM 23.0.1+11.1 (build 23.0.1+11-jvmci-b01)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 23.0.1+11.1 (build 23.0.1+11-jvmci-b01, mixed mode, sharing)
Operating System and Version
x86_64 GNU/Linux
Diagnostic Flag Confirmation
-H:ThrowMissingRegistrationErrors=
flag.Run Command
./graalvm-jdk-23.0.1+11.1/bin/native-image -H:ThrowMissingRegistrationErrors= --verbose --no-fallback -H:+AllowJRTFileSystem -jar j.jar
Expected Behavior
I expected the native image to use the jrt filesystem to read from the provided JAVA_HOME
Actual Behavior
The native image reads from the JAVA_HOME of the GraalVM used at image built time, and fails if the GraalVM is removed.
Steps to Reproduce
Use this test program:
Running on OpenJDK shows the program loading a file using the jrt filesystem:
Building with native-image:
If the GraalVM install is removed, the application fails, it appears to contain references to the GraalVM runtime that was used to create the native image.
I expected the native image to use the jrt filesystem to read from the provided
java.home
, instead of reading from the GraalVM that was used to create the native image.Additional Context
No response
Run-Time Log Output and Error Messages
No response
The text was updated successfully, but these errors were encountered: