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.37k stars 1.63k forks source link

[GR-55718] MacOS only: System.getProperty("os.arch") is "x86_64" from JVM and then "amd64" from native image. #9337

Open credmond opened 3 months ago

credmond commented 3 months ago

Describe the issue As per title, on MacOs, calling System.getProperty("os.arch") returns x86_64 when running the application in the JVM, and then returns "amd64" from the native image.

Why does this matter?

Because many JAR libraries ship with their own .dylib/.dll/.so native libraries (for win, linux, darwin, etc...), etc. These libraries, in determining which native library to load, will consult System.getProperty("os.arch") and use its return value to form part of the path.

E.g., /darwin/x86_64/something.dylib vs. /darwin/amd64/something.dylib (i.e., the latter does not exist in any library).

For macOs, the correct arch should be x86_64 for non-M1, which this is.

At the very least, the native image should surely behave the same, not differently, as running the .class in the same GraalVM JVM.

This causes unusual and unexpected errors or behaviour. Many libraries will have less-efficient fallback classes if the library fails to load, and won't even tell you about it. In that case, it's impossible to use the tracing agent to trace the code paths, when the code paths are different because os.arch drives different choices for a tracing agent run versus native image run. This leads you to believe you have bad reflection config (unless you dive in and find out the real root cause).

Other libraries without such fallbacks fail immediately.

Two examples of such libraries with this loading behaviour:

     <dependency>
         <groupId>com.github.luben</groupId>
         <artifactId>zstd-jni</artifactId>
         <version>1.5.5-1</version>
     </dependency>
     <dependency>
         <groupId>org.lz4</groupId>
         <artifactId>lz4-java</artifactId>
         <version>1.8.0</version>
     </dependency>

Steps to reproduce the issue

On macOs, run this as a .class, then as a native image, and observe the difference.

public class Bug {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("Arch: " + System.getProperty("os.arch"));
    }
}

Describe GraalVM and your environment:

oubidar-Abderrahim commented 3 months ago

Thank you for reaching out about this, we'll take a look into it shortly

credmond commented 3 months ago

Hey -- any thoughts / insights on this?

Is it intentional for some reason, or a bug, do we think?

wirthi commented 3 months ago

We have assigned it to @pejovica last week and waiting for his analysis.

We have had problems like this before, and thought we had fixed them - so I assume this is a bug, but let's wait for Alex' analysis. The curious difference in this case is that it is a non-M1 Mac, maybe we missed that case?

credmond commented 2 months ago

Hi -- any updates on this?

Can you reproduce or do you want any additional info from me / my setup?