Bug 1527803: Make sure debug service is instantiated before starting Watchdog thread. r=erahm
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Feb 2019 13:03:06 -0800
changeset 518601 965d985aeda572d16800fa301ca9fee410cb2fe7
parent 518600 4dee747dc404598c2f322ffbfc519536162b7a96
child 518602 aea45260a0bcb1da32fe474c957c5b1751b636da
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1527803
milestone67.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 1527803: Make sure debug service is instantiated before starting Watchdog thread. r=erahm The watchdog thread's stack is intentionally kept as small as possible, since the work that it does is trivial and should not require much stack space. One result of this is that the stack segment is generally too small to instantiate a new service (and we really don't want to be instantiating services on it anyway). The debug service is generally instantiated before the watchdog thread tries to touch it, but this isn't guaranteed (and, in particular, it often isn't for xpcshell runs on some noopt debug builds). Instantiating it before starting the watchdog thread solves this problem. Differential Revision: https://phabricator.services.mozilla.com/D20869
js/xpconnect/src/XPCJSContext.cpp
--- a/js/xpconnect/src/XPCJSContext.cpp
+++ b/js/xpconnect/src/XPCJSContext.cpp
@@ -139,16 +139,26 @@ class Watchdog {
     }
 
     mWakeup = PR_NewCondVar(mLock);
     if (!mWakeup) {
       MOZ_CRASH("PR_NewCondVar failed.");
     }
 
     {
+      // Make sure the debug service is instantiated before we create the
+      // watchdog thread, since we intentionally try to keep the thread's stack
+      // segment as small as possible. It isn't always large enough to
+      // instantiate a new service, and even when it is, we don't want fault in
+      // extra pages if we can avoid it.
+      nsCOMPtr<nsIDebug2> dbg = do_GetService("@mozilla.org/xpcom/debug;1");
+      Unused << dbg;
+    }
+
+    {
       AutoLockWatchdog lock(this);
 
       // Gecko uses thread private for accounting and has to clean up at thread
       // exit. Therefore, even though we don't have a return value from the
       // watchdog, we need to join it on shutdown.
       mThread = PR_CreateThread(PR_USER_THREAD, WatchdogMain, this,
                                 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                                 PR_JOINABLE_THREAD, kWatchdogStackSize);