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

Request to explore JavaCPP as an extension to model Python FFI. #14

Open
abhi18av opened this issue Jul 27, 2017 · 4 comments
Open

Request to explore JavaCPP as an extension to model Python FFI. #14

abhi18av opened this issue Jul 27, 2017 · 4 comments
Labels

Comments

@abhi18av
Copy link

Hi @Stewori

This is not an issue so please do feel free to close it down. This is more like a query/suggestion regarding the project. The basic question is -

Why is a seperate JyNI project needed to accomplish the linkage to python native extensions?

I'd like to suggest that perhaps, https://github.com/bytedeco/javacpp might be a worthy option to explore in this space as well. It's being used by ND4J and DeepLearning4J projects plus there are a number of bindings already generated located here https://github.com/bytedeco/javacpp-presets .

I hope that JavaCpp might take us closer to a proper package compatibility. I'm really looking forward to using proper python packages with Jython , Thanks again :)

@Stewori
Copy link
Owner

Stewori commented Aug 3, 2017

Hello @abhi18av,
note that JyNI is not yet another Java FFI, but actually emulates the existing CPython C-extension API.
This API is very involved and needs rather special treatment in terms of dynamic loading, memory management and various further aspects.

  • it must bridge reference counting and mark-and-sweep gc
  • it is especially challenging to get finalizers and weak references right in this context
  • it must resolve GIL handling
  • it needs to control RTLD flag, which isn't trivial via JNI

For details have a look at this paper.
E.g. with JavaCPP it is only possible to call into native code and to pass callbacks, while CPython extension API requires to export symbols (which is not supported by JavaCPP AFAICT).
Even if it would be feasible with JavaCPP, I would not see the benefit, because the JNI glue code is really the trivial part of JyNI and is already done.
Then, JavaCPP requires C/C++ compilation for each extension specifically, which is a major drawback compared to e.g. JNR ("interestingly" they ignore that aspect in their readme entirely and somehow describe JavaCPP as superior to e.g. JNR).
On the other hand, JavaCPP's main advantage - tight C++ integration - would not pay off for JyNI at all, because CPython is written in plain C.
Also, I doubt there is potential for performance gain, because JavaCPP boils down to JNI as well. In contrast to that, JNR is said to be slightly faster than plain JNI due to some smart use of assembler. Anyway, I would not explore any beyond-JNI optimization before project panama turns out, as that is by far the most promising advancement in terms of Java FFI performance (presumingly, JyNI 3 will make use of that one day).

@Stewori Stewori closed this as completed Aug 3, 2017
@Stewori Stewori reopened this Aug 3, 2017
@abhi18av
Copy link
Author

abhi18av commented Aug 5, 2017

After your wonderful explanation, I do have a better understanding of the scope of the project @Stewori . Thanks for taking out the time to be so thorough 👍

@abhi18av
Copy link
Author

abhi18av commented Aug 5, 2017

I do wish that Python3 transition would pick up speed in the Jython world :)

@saudet
Copy link

saudet commented Mar 24, 2018

Hello, author of JavaCPP here. I agree, CPython doesn't need C++. :)
But I do hope that this is all going to get integrated one day...

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

No branches or pull requests

3 participants