Bug 1508626 - add assertions to diagnose why the font loader is running after shutdown. r=jfkthame
authorLee Salzman <lsalzman@mozilla.com>
Tue, 14 May 2019 16:14:26 +0000
changeset 473795 c8fc7c4dc43c27a9c094b38de983425c1a06f43c
parent 473794 2659abca52029881f180395cc0edb45b5292d25d
child 473796 c9f1a1db8fa2190a88c09eb624b321a07da6c3e1
push id36015
push usercbrindusan@mozilla.com
push dateTue, 14 May 2019 21:40:04 +0000
treeherdermozilla-central@f17162f343b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1508626
milestone68.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 1508626 - add assertions to diagnose why the font loader is running after shutdown. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D30979
gfx/thebes/gfxFontInfoLoader.cpp
--- a/gfx/thebes/gfxFontInfoLoader.cpp
+++ b/gfx/thebes/gfxFontInfoLoader.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxFontInfoLoader.h"
 #include "nsCRT.h"
 #include "nsIObserverService.h"
+#include "nsXPCOM.h"        // for gXPCOMThreadsShutDown
 #include "nsThreadUtils.h"  // for nsRunnable
 #include "gfxPlatformFontList.h"
 
 #ifdef XP_WIN
 #  include <windows.h>
 #endif
 
 using namespace mozilla;
@@ -106,22 +107,25 @@ nsresult AsyncFontInfoLoader::Run() {
   // post a completion event that transfer the data to the fontlist
   NS_DispatchToMainThread(mCompleteEvent);
 
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(gfxFontInfoLoader::ShutdownObserver, nsIObserver)
 
+static bool sFontLoaderShutdownObserved = false;
+
 NS_IMETHODIMP
 gfxFontInfoLoader::ShutdownObserver::Observe(nsISupports* aSubject,
                                              const char* aTopic,
                                              const char16_t* someData) {
   if (!nsCRT::strcmp(aTopic, "quit-application")) {
     mLoader->CancelLoader();
+    sFontLoaderShutdownObserved = true;
   } else {
     MOZ_ASSERT_UNREACHABLE("unexpected notification topic");
   }
   return NS_OK;
 }
 
 void gfxFontInfoLoader::StartLoader(uint32_t aDelay, uint32_t aInterval) {
   mInterval = aInterval;
@@ -142,23 +146,36 @@ void gfxFontInfoLoader::StartLoader(uint
       return;
     }
   }
 
   AddShutdownObserver();
 
   // delay? ==> start async thread after a delay
   if (aDelay) {
+    NS_ASSERTION(!sFontLoaderShutdownObserved,
+                 "Bug 1508626 - Setting delay timer for font loader after "
+                 "shutdown observed");
+    NS_ASSERTION(!gXPCOMThreadsShutDown,
+                 "Bug 1508626 - Setting delay timer for font loader after "
+                 "shutdown but before observer");
     mState = stateTimerOnDelay;
     mTimer->InitWithNamedFuncCallback(DelayedStartCallback, this, aDelay,
                                       nsITimer::TYPE_ONE_SHOT,
                                       "gfxFontInfoLoader::StartLoader");
     return;
   }
 
+  NS_ASSERTION(
+      !sFontLoaderShutdownObserved,
+      "Bug 1508626 - Initializing font loader after shutdown observed");
+  NS_ASSERTION(!gXPCOMThreadsShutDown,
+               "Bug 1508626 - Initializing font loader after shutdown but "
+               "before observer");
+
   mFontInfo = CreateFontInfoData();
 
   // initialize
   InitLoader();
 
   // start async load
   nsresult rv = NS_NewNamedThread("Font Loader",
                                   getter_AddRefs(mFontLoaderThread), nullptr);
@@ -190,16 +207,23 @@ void gfxFontInfoLoader::FinalizeLoader(F
   mLoadTime = mFontInfo->mLoadTime;
 
   // try to load all font data immediately
   if (LoadFontInfo()) {
     CancelLoader();
     return;
   }
 
+  NS_ASSERTION(!sFontLoaderShutdownObserved,
+               "Bug 1508626 - Finalize with interval timer for font loader "
+               "after shutdown observed");
+  NS_ASSERTION(!gXPCOMThreadsShutDown,
+               "Bug 1508626 - Finalize with interval timer for font loader "
+               "after shutdown but before observer");
+
   // not all work completed ==> run load on interval
   mState = stateTimerOnInterval;
   mTimer->InitWithNamedFuncCallback(LoadFontInfoCallback, this, mInterval,
                                     nsITimer::TYPE_REPEATING_SLACK,
                                     "gfxFontInfoLoader::FinalizeLoader");
 }
 
 void gfxFontInfoLoader::CancelLoader() {
@@ -218,16 +242,23 @@ void gfxFontInfoLoader::CancelLoader() {
     mFontLoaderThread = nullptr;
   }
   RemoveShutdownObserver();
   CleanupLoader();
 }
 
 void gfxFontInfoLoader::LoadFontInfoTimerFire() {
   if (mState == stateTimerOnDelay) {
+    NS_ASSERTION(!sFontLoaderShutdownObserved,
+                 "Bug 1508626 - Setting interval timer for font loader after "
+                 "shutdown observed");
+    NS_ASSERTION(!gXPCOMThreadsShutDown,
+                 "Bug 1508626 - Setting interval timer for font loader after "
+                 "shutdown but before observer");
+
     mState = stateTimerOnInterval;
     mTimer->SetDelay(mInterval);
   }
 
   bool done = LoadFontInfo();
   if (done) {
     CancelLoader();
   }