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 extension #13054

Closed
dufoli opened this issue Nov 1, 2020 · 14 comments
Closed

jna extension #13054

dufoli opened this issue Nov 1, 2020 · 14 comments
Labels
kind/extension-proposal Discuss and Propose new extensions triage/moved This issue/PR is moved to another repository

Comments

@dufoli
Copy link
Contributor

dufoli commented Nov 1, 2020

graalvm do not support jna in native mode.
But JNA seems to be mainly a classic jar wich use a jni small subset to load native lib.
So my point is that maybe it is doable to use substitution + reflection identification + proxy identification to have jna support.

reference:
https://github.com/java-native-access/jna

quick analyse:

proxy:
https://github.com/java-native-access/jna/search?q=newproxyinstance

  • all interface inherited of com.sun.jna.Library and Library itself
  • all interface inherited of com.sun.jna.Callback and Callback itself

Reflections:

@dufoli dufoli added the kind/extension-proposal Discuss and Propose new extensions label Nov 1, 2020
@gsmet
Copy link
Member

gsmet commented Nov 2, 2020

I really don't think it's something we will want to do on our own.

@stuartwdouglas WDYT?

@gsmet
Copy link
Member

gsmet commented Nov 2, 2020

/cc @dmlloyd too as you might have insights on the GraalVM side.

@dmlloyd
Copy link
Member

dmlloyd commented Nov 2, 2020

It's doable. GraalVM have said "no" (oracle/graal#673) but it should be possible as you say.

@gsmet
Copy link
Member

gsmet commented Nov 2, 2020

@dufoli do you have a specific use case?

@dufoli
Copy link
Contributor Author

dufoli commented Nov 2, 2020

Indeed it was because, I was thinking to the fact that java is not used compair to other language (python, ...) for machine learning. I discover deep java library and thinking that it can be awesome to have a neural network available on quarkus. I discover that there is someone who have work on it on apache/camel-quarkus#1598
. But native support is not working before it depend of JNA.
And I think that native can boost performance which is very important for neural network. So that s why I create this issue for jna.

@stuartwdouglas
Copy link
Member

Maybe we could have a Quarkiverse extension? I started one here just to play around with what would be involved: https://github.com/stuartwdouglas/quarkiverse-jna

Unfortunately it is not going to be as simple as just registering some stuff for reflection. The first error that pops up is https://github.com/java-native-access/jna/blob/54c84a34f82d1e8148b0ed3808b64db4d1f79df3/src/com/sun/jna/internal/ReflectionUtils.java#L76 where they are using reflection to hack into method handle internals.

It would be really cool to have neural networks on Quarkus, but at this stage it is hard to say how much work is involved.

@geoand
Copy link
Contributor

geoand commented Nov 3, 2020

Riding the AI / ML wave in Quarkus would be awesome, but at this point I really think that any work in that direction should probably be done outside of Quarkus core.

@JiriOndrusek
Copy link
Contributor

I don't have enough experience with jna, but it seems, that some kind of usage with graalvm is possible and example is on the way - oracle/graal#2261 (comment)

@dufoli
Copy link
Contributor Author

dufoli commented Nov 9, 2020

@gastaldi can you create jna on quarkiverse and clone repo from mine (dufoli/quarkiverse-jna) . it is now failing with
Fatal error:java.lang.RuntimeException: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
...
quarkus-jna-integration-tests-0.1.0-SNAPSHOT-runner.o:(.data+0xaa0): undefined reference to `Java_java_util_prefs_FileSystemPreferences_chmod'
collect2: error: ld returned 1 exit status

but it seems to be related to graalvm bug:
oracle/graal#2856 fixed in 20.3

@gastaldi
Copy link
Contributor

gastaldi commented Nov 9, 2020

@dufoli I created https://github.com/quarkiverse/quarkiverse-jna and gave you push access. Feel free to push your code there when it's usable.

Thanks! Closing this issue now

@gastaldi gastaldi closed this as completed Nov 9, 2020
@gastaldi gastaldi added the triage/moved This issue/PR is moved to another repository label Nov 9, 2020
@amahfouz1
Copy link

I have the full JNA configurations sample here if anyone is interested https://github.com/amahfouz1/jna-graalvm

@dufoli
Copy link
Contributor Author

dufoli commented Apr 7, 2021

Me, I am working on extension but never finished it.

@amahfouz1
Copy link

@dufoli here you go the full configuration and it has been proven stable in production. Let me know if you need any help with the extension.

@GavinRay97
Copy link
Contributor

@amahfouz1 Thank you for this!

If this works, maybe it's possible to merge it upstream into JNA itself?

All that JNA has to do is distribute these files in it's JAR, at the following location:
META-INF/native-image/<group-id>/<artifact-id>

And it should work for everyone. Would be awesome to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/extension-proposal Discuss and Propose new extensions triage/moved This issue/PR is moved to another repository
Projects
None yet
Development

No branches or pull requests

9 participants