Backed out changeset 2872d7dca33b (bug 1284511) r=blassey a=merge
authorTooru Fujisawa <arai_a@mac.com>
Fri, 09 Sep 2016 00:45:40 +0900
changeset 354528 5ff6c6e6718608582a064b6b42d8e077ff3bf606
parent 354527 c0027a6323616e6fbb2d4229016097cde9b518a0
child 354529 176aff980979bf588baed78c2824571a6a7f2b96
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, merge
bugs1284511
milestone51.0a1
backs out2872d7dca33b68a7c49adffeb2b671c28820ac60
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
Backed out changeset 2872d7dca33b (bug 1284511) r=blassey a=merge
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -970,18 +970,17 @@ class Watchdog
     explicit Watchdog(WatchdogManager* aManager)
       : mManager(aManager)
       , mLock(nullptr)
       , mWakeup(nullptr)
       , mThread(nullptr)
       , mHibernating(false)
       , mInitialized(false)
       , mShuttingDown(false)
-      , mSlowScriptSecondHalf(false)
-      , mSlowScriptHalfLastElapsedTime(0)
+      , mSlowScriptSecondHalfCount(0)
       , mMinScriptRunTimeSeconds(1)
     {}
     ~Watchdog() { MOZ_ASSERT(!Initialized()); }
 
     WatchdogManager* Manager() { return mManager; }
     bool Initialized() { return mInitialized; }
     bool ShuttingDown() { return mShuttingDown; }
     PRLock* GetLock() { return mLock; }
@@ -1081,51 +1080,32 @@ class Watchdog
         PR_NotifyCondVar(mWakeup);
     }
 
     int32_t MinScriptRunTimeSeconds()
     {
         return mMinScriptRunTimeSeconds;
     }
 
-    bool IsSlowScriptSecondHalf()
-    {
-        return mSlowScriptSecondHalf;
-    }
-    void FlipSlowScriptSecondHalf()
-    {
-        mSlowScriptSecondHalf = !mSlowScriptSecondHalf;
-    }
-    PRTime GetSlowScriptHalfLastElapsedTime()
-    {
-        return mSlowScriptHalfLastElapsedTime;
-    }
-    void SetSlowScriptHalfLastElapsedTime(PRTime t)
-    {
-        mSlowScriptHalfLastElapsedTime = t;
-    }
-    void ResetSlowScript()
-    {
-        mSlowScriptSecondHalf = false;
-        mSlowScriptHalfLastElapsedTime = 0;
-    }
+    uint32_t GetSlowScriptSecondHalfCount() { return mSlowScriptSecondHalfCount; }
+    void IncrementSlowScriptSecondHalfCount() { mSlowScriptSecondHalfCount++; }
+    void ResetSlowScriptSecondHalfCount() { mSlowScriptSecondHalfCount = 0; }
 
   private:
     WatchdogManager* mManager;
 
     PRLock* mLock;
     PRCondVar* mWakeup;
     PRThread* mThread;
     bool mHibernating;
     bool mInitialized;
     bool mShuttingDown;
 
     // See the comment in WatchdogMain.
-    bool mSlowScriptSecondHalf;
-    PRTime mSlowScriptHalfLastElapsedTime;
+    uint32_t mSlowScriptSecondHalfCount;
 
     mozilla::Atomic<int32_t> mMinScriptRunTimeSeconds;
 };
 
 #define PREF_MAX_SCRIPT_RUN_TIME_CONTENT "dom.max_script_run_time"
 #define PREF_MAX_SCRIPT_RUN_TIME_CHROME "dom.max_chrome_script_run_time"
 
 class WatchdogManager : public nsIObserver
@@ -1181,17 +1161,17 @@ class WatchdogManager : public nsIObserv
         MOZ_ASSERT(NS_IsMainThread());
         Maybe<AutoLockWatchdog> lock;
         if (mWatchdog)
             lock.emplace(mWatchdog);
 
         // Write state.
         mTimestamps[TimestampRuntimeStateChange] = PR_Now();
         if (mWatchdog)
-            mWatchdog->ResetSlowScript();
+            mWatchdog->ResetSlowScriptSecondHalfCount();
         mRuntimeState = active ? RUNTIME_ACTIVE : RUNTIME_INACTIVE;
 
         // The watchdog may be hibernating, waiting for the runtime to go
         // active. Wake it up if necessary.
         if (active && mWatchdog && mWatchdog->Hibernating())
             mWatchdog->WakeUp();
     }
     bool IsRuntimeActive() { return mRuntimeState == RUNTIME_ACTIVE; }
@@ -1313,50 +1293,49 @@ WatchdogMain(void* arg)
         // we want to show the slow script UI.  The timeout T is controlled by
         // prefs.  We want to avoid showing the slow script dialog if the
         // user's laptop goes to sleep in the middle of running a script.  To
         // ensure this, we invoke the interrupt callback only after the T/2
         // elapsed twice.  If the computer is put to sleep during one of the
         // T/2 periods, the script still has the other T/2 seconds to finish.
         //
         //   + <-- TimestampRuntimeStateChange = PR_Now()
+        //   |     mSlowScriptSecondHalfCount = 0
         //   |
-        //   | t0 >= T/2
+        //   | T/2
         //   |
-        //   + <-- mSlowScriptSecondHalf == false
+        //   + <-- mSlowScriptSecondHalfCount = 1
         //   |
-        //   | t1 >= T/2
+        //   | T/2
         //   |
-        //   + <-- mSlowScriptSecondHalf == true
+        //   + <-- mSlowScriptSecondHalfCount = 2
         //   |     Invoke interrupt callback
         //   |
-        //   | t2 >= T/2
+        //   | T/2
         //   |
-        //   + <-- mSlowScriptSecondHalf == false
+        //   + <-- mSlowScriptSecondHalfCount = 3
         //   |
-        //   | t3 >= T/2
+        //   | T/2
         //   |
-        //   + <-- mSlowScriptSecondHalf == true
+        //   + <-- mSlowScriptSecondHalfCount = 4
         //         Invoke interrupt callback
         //
         PRTime usecs = self->MinScriptRunTimeSeconds() * PR_USEC_PER_SEC;
         if (manager->IsRuntimeActive()) {
-            PRTime elapsedTime = manager->TimeSinceLastRuntimeStateChange();
-            PRTime lastElapsedTime = self->GetSlowScriptHalfLastElapsedTime();
-            if (elapsedTime >= lastElapsedTime + usecs / 2) {
-                self->SetSlowScriptHalfLastElapsedTime(elapsedTime);
-                if (self->IsSlowScriptSecondHalf()) {
+            uint32_t count = self->GetSlowScriptSecondHalfCount() + 1;
+            if (manager->TimeSinceLastRuntimeStateChange() >= usecs * count / 2) {
+                self->IncrementSlowScriptSecondHalfCount();
+                if (count % 2 == 0) {
                     bool debuggerAttached = false;
                     nsCOMPtr<nsIDebug2> dbg = do_GetService("@mozilla.org/xpcom/debug;1");
                     if (dbg)
                         dbg->GetIsDebuggerAttached(&debuggerAttached);
                     if (!debuggerAttached)
                         JS_RequestInterruptCallback(manager->Runtime()->Context());
                 }
-                self->FlipSlowScriptSecondHalf();
             }
         }
     }
 
     // Tell the manager that we've shut down.
     self->Finished();
 }