Backed out changeset 37c314d53f82 (bug 1284511). r=blassey, a=lizzard
authorTooru Fujisawa <arai_a@mac.com>
Fri, 09 Sep 2016 14:08:12 -0400
changeset 348095 68f57be1e4611d6164d16bf092468fd2b90bc48c
parent 348094 236385abdffc17d9450a811263f66647da7cc408
child 348096 28878b37a89e309b3311bc9cc6aa864a74a96d3e
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, lizzard
bugs1284511
milestone50.0a2
backs out37c314d53f827e5fc094fcb9b1537b4101681507
Backed out changeset 37c314d53f82 (bug 1284511). r=blassey, a=lizzard
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -986,18 +986,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; }
@@ -1097,51 +1096,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;
 };
 
 #ifdef MOZ_NUWA_PROCESS
 #include "ipc/Nuwa.h"
 #endif
 
@@ -1201,17 +1181,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; }
@@ -1340,50 +1320,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();
 }