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

jni: Delete global reference in bound threads #75

Closed
facundominguez opened this issue Jul 5, 2017 · 2 comments
Closed

jni: Delete global reference in bound threads #75

facundominguez opened this issue Jul 5, 2017 · 2 comments
Assignees

Comments

@facundominguez
Copy link
Member

facundominguez commented Jul 5, 2017

The current approach is to have the Haskell GC delete the global references. Unfortunately, the GC deletes global references using unbound threads which are unsafe to use when making JNI calls.

The simplest fix of all is to wrap finalizers with Foreign.JNI.runInAttachedThread.

If the above is too slow, another solution is to implement a pool of threads to make sure finalizers are expediently executed once the GC makes up its mind to run them.

Lastly, #73 might also offer a solution to this problem.

@facundominguez
Copy link
Member Author

facundominguez commented Jul 17, 2017

If the above is too slow, another solution is to implement a pool of threads to make sure finalizers are expediently executed once the GC makes up its mind to run them.

Using a threadpool is probably over-complicating the solution. A single bound thread could do if performance is not a concern.

If the java heap is full and needs fast deletion of global references, can java force the Haskell GC to run the finalizers promptly before java finishes garbage collection? If not, which scenario would take advantage of a fast deletion of local references?

@facundominguez
Copy link
Member Author

facundominguez commented Jul 16, 2020

Next steps:

  • Change the finalizers calling deleteGlobalRefNonFinalized to use runInAttachedThread.
  • Measure how long it takes attaching and detaching a thread to the JVM when compared with the time it takes to delete deleteGlobalRefNonFinalized.
  • Have the finalizers execute deleteGlobalRefNonFinalized on a dedicated attached thread and measure how long it takes to delete a bunch of global references.

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