Bug 1372777 - Check that the native pointer has not been detached from the java object when dispatched to different thread r=esawin
authorRandall Barker <rbarker@mozilla.com>
Mon, 19 Jun 2017 11:57:27 -0700
changeset 364954 8e1de9b8675384f6307830d381fcd195a432ea83
parent 364953 7d042155a0887865e09f3f3502aef0f7149b40aa
child 364955 8ddbba90e78bff67d15ea1ba8b606adee051c3a6
push id32057
push userkwierso@gmail.com
push dateWed, 21 Jun 2017 00:59:08 +0000
treeherdermozilla-central@f31652d75fb5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1372777
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1372777 - Check that the native pointer has not been detached from the java object when dispatched to different thread r=esawin MozReview-Commit-ID: DyeZDaHeWdL
widget/android/jni/Natives.h
widget/android/nsWindow.cpp
--- a/widget/android/jni/Natives.h
+++ b/widget/android/jni/Natives.h
@@ -399,29 +399,31 @@ class ProxyNativeCall : public AbstractC
         (*mNativeCall)(mozilla::Get<Indices>(mArgs)...);
     }
 
     template<bool Static, bool ThisArg, size_t... Indices>
     typename mozilla::EnableIf<!Static && ThisArg, void>::Type
     Call(const typename Owner::LocalRef& inst,
          mozilla::IndexSequence<Indices...>) const
     {
-        Impl* const impl = NativePtr<Impl>::Get(inst);
-        MOZ_CATCH_JNI_EXCEPTION(inst.Env());
-        (impl->*mNativeCall)(inst, mozilla::Get<Indices>(mArgs)...);
+        if (Impl* const impl = NativePtr<Impl>::Get(inst)) {
+            MOZ_CATCH_JNI_EXCEPTION(inst.Env());
+            (impl->*mNativeCall)(inst, mozilla::Get<Indices>(mArgs)...);
+        }
     }
 
     template<bool Static, bool ThisArg, size_t... Indices>
     typename mozilla::EnableIf<!Static && !ThisArg, void>::Type
     Call(const typename Owner::LocalRef& inst,
          mozilla::IndexSequence<Indices...>) const
     {
-        Impl* const impl = NativePtr<Impl>::Get(inst);
-        MOZ_CATCH_JNI_EXCEPTION(inst.Env());
-        (impl->*mNativeCall)(mozilla::Get<Indices>(mArgs)...);
+        if (Impl* const impl = NativePtr<Impl>::Get(inst)) {
+            MOZ_CATCH_JNI_EXCEPTION(inst.Env());
+            (impl->*mNativeCall)(mozilla::Get<Indices>(mArgs)...);
+        }
     }
 
     template<size_t... Indices>
     void Clear(JNIEnv* env, mozilla::IndexSequence<Indices...>)
     {
         int dummy[] = {
             (ProxyArg<Args>::Clear(env, Get<Indices>(mArgs)), 0)...
         };
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -978,21 +978,24 @@ public:
                 : mCompositor(mozilla::Move(aCompositor))
             {}
 
             void Run() override
             {
                 MOZ_ASSERT(NS_IsMainThread());
 
                 JNIEnv* const env = jni::GetGeckoThreadEnv();
-                LayerViewSupport* const lvs = GetNative(
-                        LayerView::Compositor::LocalRef(env, mCompositor));
-                MOZ_CATCH_JNI_EXCEPTION(env);
+                // Make sure LayerViewSupport hasn't been detached from the
+                // Java object since this event was dispatched.
+                if (LayerViewSupport* const lvs = GetNative(
+                        LayerView::Compositor::LocalRef(env, mCompositor))) {
+                    MOZ_CATCH_JNI_EXCEPTION(env);
 
-                lvs->OnResumedCompositor();
+                    lvs->OnResumedCompositor();
+                }
             }
         };
 
         nsAppShell::PostEvent(MakeUnique<LayerViewEvent>(
                 MakeUnique<OnResumedEvent>(aObj)));
     }
 
     void SyncInvalidateAndScheduleComposite()