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

Handle asynchronous Java exceptions #19

Closed
alpmestan opened this issue Feb 29, 2016 · 3 comments
Closed

Handle asynchronous Java exceptions #19

alpmestan opened this issue Feb 29, 2016 · 3 comments
Milestone

Comments

@alpmestan
Copy link
Contributor

From the JNI spec:

Asynchronous Exceptions
In cases of multiple threads, threads other than the current thread may post an asynchronous exception. An asynchronous exception does not immediately affect the execution of the native code in the current thread, until:

  • the native code calls one of the JNI functions that could raise synchronous exceptions, or
  • the native code uses ExceptionOccurred() to explicitly check for synchronous and asynchronous
    exceptions.

Note that only those JNI functions that could potentially raise synchronous exceptions check for asynchronous exceptions.
Native methods should insert ExceptionOccurred() checks in necessary places (such as in a tight loop without other exception checks) to ensure that the current thread responds to asynchronous exceptions in a reasonable amount of time.

@mboes
Copy link
Member

mboes commented Feb 29, 2016

I'm not sure that we need to do anything special here. I think we can close the ticket. While async exceptions currently never get raised while in the middle of evaluating Haskell code, it's also not something that can be helped. Unless we hook into the RTS to have it ask Java whether async exceptions occurred whenever we reach a "safe point", we can't do better than raising the async exception next time a JNI call from the current thread is made. We can't have timer based polling or anything like that, because the polling would happen in another thread and so be oblivious to the async exceptions thrown to the target thread. What's more, it's reasonable to say that safe points as relates to Java exceptions are fewer and farther between than Haskell safe points. They only occur every time one calls a JNI function.

@mboes
Copy link
Member

mboes commented Feb 29, 2016

However, we should at the very least document the behaviour of Sparkle in the face of async Java exceptions.

@mboes
Copy link
Member

mboes commented Nov 8, 2016

This issue was moved to tweag/inline-java#4

@mboes mboes closed this as completed Nov 8, 2016
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