NativeWeakPtr::Detach should return Promise to wait for detached completely
Categories
(GeckoView :: General, enhancement, P2)
Tracking
(firefox115 fixed)
| Tracking | Status | |
|---|---|---|
| firefox115 | --- | fixed |
People
(Reporter: m_kato, Assigned: m_kato)
References
(Blocks 1 open bug)
Details
Attachments
(2 files)
When debugging bug 1778039, I found the following.
void GeckoViewSupport::Transfer(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aQueue,
jni::Object::Param aCompositor,
jni::Object::Param aDispatcher,
jni::Object::Param aSessionAccessibility,
jni::Object::Param aInitData) {
...
mWindow->mSessionAccessibility.Detach();
if (aSessionAccessibility) {
AttachAccessibility(inst, aSessionAccessibility);
}
When calling Detach is done, We don't ensure that JNI object isn't released. so If re-attaching same JNI object, disposer by Detach can run after AttachAccessibility is done.
Because disposer have to run in Gecko main thread, but OnWeakNonIntrusiveDetach creates task to call Java method in Android UI thread. It means that some JNI implementation only creates disposing tasks by Detach, then it doesn't dispose the object yet.
So GeckoViewSupport::Transfer has dangerous logic for SessionAccessibility.
I would like to return MozPromise by NativeWeakPtr::Detach to resolve this issue. I guess that this issue is one of crash reason of bug 1778039, but I am not sure that it is all.
| Assignee | ||
Comment 1•2 years ago
|
||
Actually, NativeWeakPtr::Detach may not release JNI ojbect immediately because
it depends on JNI object's OnWeakNonIntrusiveDetachi implementation.
SessionAccessibility's OnWeakNonIntrusiveDetach implementation uses the
runnable to run on Android UI thread then disposer runs on main thread, so
if Detach is finished, JNI object isn't detached yet.
If calling NativeWeakPtrHolder::Attach immediately with same/recycled Java
object after NettiveWeakPtr::Detach, it is possible to run disposer for JNI
object by OnWeakNonIntrusiveDetach after Attach is finished. So it may
release newer attached object unfortunately.
So I would like to add a way to waiting for detach JNI object using
MozPromise.
Also, MozPromise.h includes Natives.h header (for GeckoResult support).
So I cannot modify inline method to use MozPromise due to recursive. So I
split implementation with NativesInlines.h as workaround.
| Assignee | ||
Comment 2•2 years ago
|
||
Although GeckoViewSupport::Transfer will re-attach SessionAccessibility,
it doesn't wait for previous SessionAccessibility is disposed completely
since SessionAccessibility::OnWeakNonIntrusiveDetach makes tasks only.
When worst case,
- Create a task for calling SessionAccessilibity::SetAttached(false) on Android UI thread.
- Create a task for calling SessionAccessilibity::SetAttached(true) on Android UI thread.
- Attach new JNI object to SeessionAccessibility
- Run 1's task on Android UI thread, then create a task for disposing JNI object on Gecko thread.
- Run 2's task on Android UI thread.
- Run 4's task on Gecko thread. JNI object is detached incorrectly if JNI object is recycled.
If reattaching same JNI object, we detach new object unfortunately. Since I add
MozPromise By Part 1, we can wait for it to use this API.
Depends on D175335
Comment 4•2 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/a41bdd815729
https://hg.mozilla.org/mozilla-central/rev/33cdbcb6cf0a
Description
•