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

JNA fails to load with GraalVM throwing JNA: Problems loading core IDs: java.lang.Object #2261

Closed
amahfouz1 opened this issue Mar 16, 2020 · 6 comments
Assignees

Comments

@amahfouz1
Copy link

amahfouz1 commented Mar 16, 2020

I know JNA is not supported out of the box on GraalVM and there are some issues closed with that conclusion but still, I tried to see if I can find a workaround. When JNA initializes during build time it never works during the runtime. I differed it to initialize at runtime and had all the resources and I started feeling there is a light at the end of the tunnel but unfortunately JNA failed when it's booting up and loading the libjnidispatch.so library it fails with: JNA: Problems loading core IDs: java.lang.Object (It's basically ClassNotFoundException)
This is the line throwing this error: https://github.com/java-native-access/jna/blob/e6ab3ecdfa5482b41230fc28888df22da4d15bd4/native/dispatch.c#L3267.
Not sure why it's not able to load Java.Lang.Object why it's not available at that time within the SubstrateVM image. I opened a similar ticket on JNA side java-native-access/jna#1172 and I am trying to connect the dots to see what we can do to help as a community to contribute to get JNA working it's very crucial for so many existing Java native libraries.

Steps to reproduce:

  • Version of JNA : 5.3.1
  • Version and vendor of the java virtual machine:
    openjdk version "1.8.0_242"
    OpenJDK Runtime Environment (build 1.8.0_242-b06)
    OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 25.242-b06-jvmci-20.0-b02, mixed mode)
  • Operating system: Oracle Linux 7 and Centos 7

Repo: https://github.com/amahfouz1/clj-pcap-native

  • Build docker image:
    I have a Dockerfile handy in the repo to help to build the image.
cd clj-pcap-native
docker build -t clj-pcap .
  • Run docker image mounting the project:
docker run -it -v `pwd`:/clj-pcap clj-pcap /bin/sh
  • Generate native executable:
cd /clj-pcap
lein native-image
  • Run the executable:
/clj-pcap/target/default+uberjar/cljpcap -Djna.debug_load=true
sh-4.2# /clj-pcap/target/default+uberjar/cljpcap -Djna.debug_load=true
Mar 15, 2020 8:13:53 PM com.sun.jna.Native extractFromResourcePath
INFO: Looking in classpath from sun.misc.Launcher$AppClassLoader@16c0128 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Mar 15, 2020 8:13:53 PM com.sun.jna.Native extractFromResourcePath
INFO: Found library resource at resourcew:com/sun/jna/linux-x86-64/libjnidispatch.so
Mar 15, 2020 8:13:53 PM com.sun.jna.Native extractFromResourcePath
INFO: Extracting library to /root/.cache/JNA/temp/jna2847104491610838225.tmp
JNA: Problems loading core IDs: java.lang.Object

The libjndispatch.so is found and the C code is now started executing but it fails :(

JNA it seems like it's not able to run the basic JVM classes within the SubstrateVM image.

@matthiasblaesing
Copy link

I commented on the JNA side: I think the reflection/jni configuration is missing a huge number of types/methods/fields, that are needed at runtime.

@amahfouz1
Copy link
Author

@matthiasblaesing thanks finally after a sleepless week I have figured out all the needed JNA metadata for GraalVM and now it's working perfectly, it was a lot of fiddling through the JNA code and tracing it back to the errors.

@MuriloFtto
Copy link

MuriloFtto commented Sep 16, 2020

@amahfouz1 Can you pass this on ? I have the same problem

@amahfouz1
Copy link
Author

@MuriloFtto I am working on contributing a full JNA configuration sample for GraalVM will let you know once it's ready.

@dennisdietrich
Copy link

@MuriloFtto I am working on contributing a full JNA configuration sample for GraalVM will let you know once it's ready.

I'm very interested in your findings. Are you still planning on writing that sample or maybe have even published it already somewhere? Thanks!

@amahfouz1
Copy link
Author

@dennisdietrich @MuriloFtto Please find my sample code here https://github.com/amahfouz1/jna-graalvm sorry for the delay.

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

5 participants