-
Notifications
You must be signed in to change notification settings - Fork 555
[CoreCLR] Automatically detach current thread from JNI #10316
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add a test for this?
Or did MAUI's tests crash on exit? So, we'd need to somehow run an extra test suite?
What's odd is that I think we have a test for this? Maybe? From the abort message in #10314:
which suggests that if we:
then the assertion should be triggered, no? We have tests that do that, e.g.: android/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs Lines 329 to 380 in 510fc08
so why didn't we hit this before? Are thread pool threads different from "normal" Do we need to do "different" kinds of JNI calls on the created thread to trigger the assertion? It likely wouldn't be a bad idea to have a test that does: var t = new Thread(() => {
var list = new Java.Util.ArrayList();
list.Add(new Java.Lang.String("a");
list.Add(new Java.Lang.Integer(42);
});
t.Start();
t.Join(); and do a bit more than straight The assert message, as-is, does not imply to me that we need to worry about app exit. (And that's ignoring the fact that "app exit" is a very nebulous concept on Android in the first place!) |
Fixes #10314
In #10198 I added code which attaches current thread to JNI (https://github.com/dotnet/android/pull/10198/files#diff-fc0414b3741163879db7993fd1fb42fa76e5305bb54c0e9478e077b3094e7aa7R42-R46). If this code is called from a thread pool thread, the thread won't be detached from JNI when exitting.
This PR adds the recommended steps to automatically detach the thread from JNI when exitting: https://developer.android.com/training/articles/perf-jni#threads
/cc @grendello @jonathanpeppers