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

Can't compile native image on arm64 along with jna-platform #31750

Open
mageddo opened this issue Mar 10, 2023 · 5 comments
Open

Can't compile native image on arm64 along with jna-platform #31750

mageddo opened this issue Mar 10, 2023 · 5 comments
Labels
area/native-image env/windows Impacts Windows machines kind/bug Something isn't working

Comments

@mageddo
Copy link

mageddo commented Mar 10, 2023

Describe the bug

Hey I'm opening this issue because I'm having trouble generating native-image for Quarkus on arm64 while using jna-plaform dependency.

Context

I have an application which uses JNA and runs on different plataforms, Linux x64, arm64 and Windows x64. For the this case I need jna-platform dependency to use integrate with windows registry API (Advapi32). When compiling form arm64 I'm getting an issue because Advapi32 is getting initialized, no idea why.

Also confirmed that won't get this issue when not using quarkus dependencies.

log.txt

Actual behavior

I'm having trouble generating native-image for Quarkus on arm64 while using jna-plaform dependency.

How to Reproduce?

See MRE sample https://github.com/mageddo/java-examples/tree/quarkus-jna-platform-bug-evidence-tag/quarkus/quarkus-2-simple

The quarkus project was generated with quarkus mvn plugin ...

Output of uname -a or ver

Linux typer-pc 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

$ java -version
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment GraalVM CE 22.3.1 (build 19.0.2+7-jvmci-22.3-b12)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.1 (build 19.0.2+7-jvmci-22.3-b12, mixed mode, sharing)

@mageddo mageddo added the kind/bug Something isn't working label Mar 10, 2023
@quarkus-bot quarkus-bot bot added env/windows Impacts Windows machines triage/needs-triage labels Mar 10, 2023
@mageddo
Copy link
Author

mageddo commented Mar 10, 2023

I'm not really sure if the issue is on Quarkus or JNA or Graal but hope you help me to figure it out.

@gsmet
Copy link
Member

gsmet commented Mar 13, 2023

My guess is that it is a problem in GraalVM.

@zakkak @Karm could you confirm?

@zakkak
Copy link
Contributor

zakkak commented Mar 13, 2023

I wouldn't say that this is a problem in GraalVM. The error log is:

#9 761.2 Error: Classes that should be initialized at run time got initialized during image building:
#9 761.2  com.sun.jna.Native the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Native got initialized use --trace-class-initialization=com.sun.jna.Native
#9 761.2 com.sun.jna.NativeLibrary the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.NativeLibrary got initialized use --trace-class-initialization=com.sun.jna.NativeLibrary
#9 761.2 com.sun.jna.win32.W32APITypeMapper the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.win32.W32APITypeMapper got initialized use --trace-class-initialization=com.sun.jna.win32.W32APITypeMapper
#9 761.2 com.sun.jna.Callback the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Callback got initialized use --trace-class-initialization=com.sun.jna.Callback
#9 761.2 com.sun.jna.CallbackReference$AttachOptions the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.CallbackReference$AttachOptions got initialized use --trace-class-initialization=com.sun.jna.CallbackReference$AttachOptions
#9 761.2 com.sun.jna.Structure the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Structure got initialized use --trace-class-initialization=com.sun.jna.Structure
#9 761.2 com.sun.jna.CallbackReference the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.CallbackReference got initialized use --trace-class-initialization=com.sun.jna.CallbackReference
#9 761.2 com.sun.jna.platform.unix.Resource$Rlimit the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.Resource$Rlimit got initialized use --trace-class-initialization=com.sun.jna.platform.unix.Resource$Rlimit
#9 761.2 com.sun.jna.platform.unix.LibC the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.LibC got initialized use --trace-class-initialization=com.sun.jna.platform.unix.LibC
#9 761.2 com.sun.jna.platform.unix.LibCAPI$size_t the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.LibCAPI$size_t got initialized use --trace-class-initialization=com.sun.jna.platform.unix.LibCAPI$size_t
#9 761.2 com.sun.jna.win32.W32APIOptions the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.win32.W32APIOptions got initialized use --trace-class-initialization=com.sun.jna.win32.W32APIOptions
#9 761.2 To see how the classes got initialized, use --trace-class-initialization=com.sun.jna.Native,com.sun.jna.NativeLibrary,com.sun.jna.win32.W32APITypeMapper,com.sun.jna.Callback,com.sun.jna.CallbackReference$AttachOptions,com.sun.jna.Structure,com.sun.jna.CallbackReference,com.sun.jna.platform.unix.Resource$Rlimit,com.sun.jna.platform.unix.LibC,com.sun.jna.platform.unix.LibCAPI$size_t,com.sun.jna.win32.W32APIOptions
#9 761.2 com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
#9 761.2  com.sun.jna.Native the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Native got initialized use --trace-class-initialization=com.sun.jna.Native
#9 761.2 com.sun.jna.NativeLibrary the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.NativeLibrary got initialized use --trace-class-initialization=com.sun.jna.NativeLibrary
#9 761.2 com.sun.jna.win32.W32APITypeMapper the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.win32.W32APITypeMapper got initialized use --trace-class-initialization=com.sun.jna.win32.W32APITypeMapper
#9 761.2 com.sun.jna.Callback the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Callback got initialized use --trace-class-initialization=com.sun.jna.Callback
#9 761.2 com.sun.jna.CallbackReference$AttachOptions the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.CallbackReference$AttachOptions got initialized use --trace-class-initialization=com.sun.jna.CallbackReference$AttachOptions
#9 761.2 com.sun.jna.Structure the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.Structure got initialized use --trace-class-initialization=com.sun.jna.Structure
#9 761.2 com.sun.jna.CallbackReference the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.CallbackReference got initialized use --trace-class-initialization=com.sun.jna.CallbackReference
#9 761.2 com.sun.jna.platform.unix.Resource$Rlimit the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.Resource$Rlimit got initialized use --trace-class-initialization=com.sun.jna.platform.unix.Resource$Rlimit
#9 761.2 com.sun.jna.platform.unix.LibC the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.LibC got initialized use --trace-class-initialization=com.sun.jna.platform.unix.LibC
#9 761.2 com.sun.jna.platform.unix.LibCAPI$size_t the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.platform.unix.LibCAPI$size_t got initialized use --trace-class-initialization=com.sun.jna.platform.unix.LibCAPI$size_t
#9 761.2 com.sun.jna.win32.W32APIOptions the class was requested to be initialized at run time (from 'META-INF/native-image/jni-jna/native-image.properties' in 'file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar' with 'com.sun.jna'). To see why com.sun.jna.win32.W32APIOptions got initialized use --trace-class-initialization=com.sun.jna.win32.W32APIOptions
#9 761.2 To see how the classes got initialized, use --trace-class-initialization=com.sun.jna.Native,com.sun.jna.NativeLibrary,com.sun.jna.win32.W32APITypeMapper,com.sun.jna.Callback,com.sun.jna.CallbackReference$AttachOptions,com.sun.jna.Structure,com.sun.jna.CallbackReference,com.sun.jna.platform.unix.Resource$Rlimit,com.sun.jna.platform.unix.LibC,com.sun.jna.platform.unix.LibCAPI$size_t,com.sun.jna.win32.W32APIOptions

which indicates a conflict between the configuration in file:///app/build/quarkus-example-1.0.0-native-image-source-jar/quarkus-example-1.0.0-runner.jar which requires the package com.sun.jna to be runtime initialized while Quarkus ends up initializing at build-time.

@mageddo you should use --trace-class-initialization=com.sun.jna.Native,com.sun.jna.NativeLibrary,com.sun.jna.win32.W32APITypeMapper,com.sun.jna.Callback,com.sun.jna.CallbackReference$AttachOptions,com.sun.jna.Structure,com.sun.jna.CallbackReference,com.sun.jna.platform.unix.Resource$Rlimit,com.sun.jna.platform.unix.LibC,com.sun.jna.platform.unix.LibCAPI$size_t,com.sun.jna.win32.W32APIOptions to see what's causing the classes at hand to get build-time initialized and avoid it (either by registering more classes for runtime initialization or reinitialization, or by substituting code).

What got my eye in your configuration is:

--initialize-at-build-time=com.sun.jna.Platform

https://github.com/mageddo/java-examples/blob/3b27687122be725533a0dfa9e26670ad6643cb09/quarkus/quarkus-2-simple/src/main/resources/META-INF/native-image/jni-jna/native-image.properties#LL6

why do you explicitly initialize com.sun.jna.Platform at build-time? I would expect the opposite.

You might also need to reconsider:

--initialize-at-run-time=com.sun.jna

@mageddo
Copy link
Author

mageddo commented Mar 13, 2023

Hey @zakkak

you should use --trace-class-initialization=com.sun.jna.Native,com.sun.jna.NativeLibrary,com.sun.jna.win32.W32APITypeMapper,com.sun.jna.Callback,com.sun.jna.CallbackReference$AttachOptions,com.sun.jna.Structure,com.sun.jna.CallbackReference,com.sun.jna.platform.unix.Resource$Rlimit,com.sun.jna.platform.unix.LibC,com.sun.jna.platform.unix.LibCAPI$size_t,com.sun.jna.win32.W32APIOptions to see what's causing the classes at hand to get build-time initialized and avoid it (either by registering more classes for runtime initialization or reinitialization, or by substituting code).

I didn't use this option on this MRE but used that on the many tries I did, it shows up a not useful log saying that some other class called W32APITypeMapper interface proxy class but don't says who because the stacktrace ends before...

why do you explicitly initialize com.sun.jna.Platform at build-time? I would expect the opposite.

You might also need to reconsider:

--initialize-at-run-time=com.sun.jna

It's because on my real project I need to check the current operation system at build time to decide to go further or not in another code, not specifically related to JNA, I'm using this class as an utils but checked that class hasn't any other dependency which can cause the root cause here, anyway, If you remove that will still get the problem.

Another information, the problem only occurs when combining JNA with Quarkus, if you remove one of them from the dependencies then you won't get the issue, that's why I opened the issue here.

In other words, If you construct this exact same MRE without quarkus,you won't get the issue.

@zakkak
Copy link
Contributor

zakkak commented Mar 14, 2023

Another information, the problem only occurs when combining JNA with Quarkus, if you remove one of them from the dependencies then you won't get the issue, that's why I opened the issue here.

In other words, If you construct this exact same MRE without quarkus,you won't get the issue.

Yes, that's because Quarkus asks GraalVM to initialize and link all classes (except for those explicitely excluded) at build-time. If you remove Quarkus the classes get runtime initialized so there is no conflict. Similarly if you remove JNA, GraalVM manages to initialize all classes at build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants