-
Notifications
You must be signed in to change notification settings - Fork 15
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
don't rely on JNI_GetCreatedJavaVMs
#199
Comments
Some more thoughts:
|
In the case of sparkle, the JVM is calling into Haskell.
Maybe |
Ah well that's just like Android then, and I also have a desktop JavaFX app which works like that. So we have the same use case here.
You do what you think is best. |
Putting A possible design is to take the JVM pointer with an API call like: setJVM :: Ptr JVM -> IO () When unset, the JVM is the value returned by |
Sounds like a plan but where does the code calling |
There is at least GetJavaVM and JNI_OnLoad to get it. |
Yes both are not exposed by the |
I don't know how to solve it in Haskell. I guess it is the same trouble that users would have to set the |
On second thought, we could offer the call in C void io_tweag_jni_set_jvm(JavaVM*) so the user doesn't need to cross the language boundary to initialize the pointer. |
No too sure how it all comes together but I'd like to avoid having the user have to implement a C shim. Currently with In Java (Kotlin actually), using JNA:
In Haskell:
|
Oh, I see what you mean now. In that case it would make sense to expose GetJavaVM in Haskell, indeed. |
For calls from Haskell into the JVM
jni
relies on a cached pointer to JNI'sJavaVM
struct. This pointer is currently obtained via thejvm
function that callsJNI_GetCreatedJavaVMs
: https://github.com/tweag/inline-java/blob/master/jni/src/common/Foreign/JNI/Unsafe/Internal.hs#L363 This call isn't available on Android.One way to obtain this pointer is through the
JNIEnv
struct that is being passed by JNI on calls from Java (it has a member functionGetJavaVM
), and cache it in a global variable. This commit provides a HaskelljniInit
function that users of the package have to call before making any calls back into Java. user16332@affeae4#diff-513af56a87e02a1e7a882ec00c88255da344d42b129da7da6308b34ac37408b9R361Another solution would be to implement JNI_OnLoad which provides the pointer.
The text was updated successfully, but these errors were encountered: