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

[Feature Request] Direct Mapping like JNA's? #156

Open
Tianscar opened this issue Mar 8, 2024 · 2 comments
Open

[Feature Request] Direct Mapping like JNA's? #156

Tianscar opened this issue Mar 8, 2024 · 2 comments

Comments

@Tianscar
Copy link
Contributor

Tianscar commented Mar 8, 2024

I think it will be more convenient to use Java's built-in syntax, i.e. native method, to call native methods. "JNADirect" does this.

In order to do this with JFFI, I tried to create a Closure#Handle on the Java side (in the Closure object, using Invoker to call the native method) and then use NativeMethods#register to link the Closure#Handle's function pointer to the native method stub on the Java side.

But this is too slow, due to the whole process went through multiple calls back and forth between Java and native:

Java (downcall to native, method with `native` keyword)
 -> native (upcall to Java, ffi closure)
 -> Java (downcall to native, Java closure)
 -> native (performing `ffi_call`)
 -> the native method I wanna call

JNA do the entire process of creating the ffi_closure and performing ffi_call on the native side, which avoids multiple calls on the Java and native sides, ensures performance.

Could you consider adding this feature or adding some methods to a more efficient way implementing this feature?

Thanks in advance

@headius
Copy link
Member

headius commented Mar 13, 2024

I would love to support this feature, but I'm not sure I understand it!

Do you know where JNA does this in their codebase? We should be able to copy the same logic but it sounds like it will require work on the native side (to do the entire ffi_closure logic within the generated native stub).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants