Last Comment Bug 705386 - AutoLocalJNIFrame should use JNIForThread()
: AutoLocalJNIFrame should use JNIForThread()
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Widget: Android (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla11
Assigned To: Mounir Lamouri (:mounir)
:
:
Mentors:
Depends on:
Blocks: websms
  Show dependency treegraph
 
Reported: 2011-11-25 15:58 PST by Mounir Lamouri (:mounir)
Modified: 2011-11-30 03:51 PST (History)
3 users (show)
mounir: in‑testsuite-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch v1 (2.32 KB, patch)
2011-11-25 15:58 PST, Mounir Lamouri (:mounir)
mwu.code: review-
Details | Diff | Splinter Review
Patch v2 (9.77 KB, patch)
2011-11-29 07:56 PST, Mounir Lamouri (:mounir)
no flags Details | Diff | Splinter Review
Patch v3 (3.01 KB, patch)
2011-11-29 08:09 PST, Mounir Lamouri (:mounir)
mwu.code: review+
mounir: checkin+
Details | Diff | Splinter Review

Description Mounir Lamouri (:mounir) 2011-11-25 15:58:07 PST
Created attachment 577014 [details] [diff] [review]
Patch v1

Using JNI() forbids us to use AutoLocalJNIFrame if the method isn't called in the main thread. We should use JNIForThread() instead to allow such usage.
Comment 1 Michael Wu [:mwu] 2011-11-25 17:46:21 PST
Who is using JNI on another thread?
Comment 2 Mounir Lamouri (:mounir) 2011-11-26 01:10:13 PST
(In reply to Michael Wu [:mwu] from comment #1)
> Who is using JNI on another thread?

All callers of GetJNIForThread() could use JNI on another thread (which I realize is mostly WebSMS methods). However, I wrote a method that is called from another thread which means I can't call it with the current implementation of AutoLocalJNIFrame.
Comment 3 Naoki Hirata :nhirata (please use needinfo instead of cc) 2011-11-29 00:33:06 PST
related to bug 704785?
Comment 4 Mounir Lamouri (:mounir) 2011-11-29 02:24:26 PST
(In reply to Naoki Hirata :nhirata from comment #3)
> related to bug 704785?

The stack track lets me think the crash in bug 704785 happens in the main thread. In that case, it wouldn't be related.
Comment 5 Michael Wu [:mwu] 2011-11-29 05:41:28 PST
Comment on attachment 577014 [details] [diff] [review]
Patch v1

I don't want AutoLocalJNIFrame (with JNIForThread) to be used by other threads unless the code explicitly asks for it. In most cases, getting a JNIEnv on a different thread isn't a good idea unless you really need it and have made sure that it is safe.
Comment 6 Mounir Lamouri (:mounir) 2011-11-29 07:56:09 PST
Created attachment 577612 [details] [diff] [review]
Patch v2
Comment 7 Mounir Lamouri (:mounir) 2011-11-29 08:09:09 PST
Created attachment 577621 [details] [diff] [review]
Patch v3
Comment 8 Michael Wu [:mwu] 2011-11-29 08:20:37 PST
Comment on attachment 577621 [details] [diff] [review]
Patch v3

Review of attachment 577621 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good, thanks!

::: widget/src/android/AndroidBridge.h
@@ +253,5 @@
>          // the AutoLocalJNIFrame's scope INVALID; be sure that you locked down
>          // any local refs that you need to keep around in global refs!
>          void Purge() {
> +            mJNIEnv->PopLocalFrame(NULL);
> +            mJNIEnv->PushLocalFrame(mEntries);

You can probably use Push() here too.
Comment 9 Marco Bonardo [::mak] 2011-11-30 03:51:56 PST
https://hg.mozilla.org/mozilla-central/rev/3a5731a60002

Note You need to log in before you can comment on or make changes to this bug.