Description
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.