Bug 1196317 - Optimize CallbackObject::mCreationStack out from cycle collection graph when possible. r=mccr8, a=sledru
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 20 Aug 2015 18:36:06 +0300
changeset 288866 49ba692877f98f33100955babdbe60138e864154
parent 288865 f4b2c0381b884b23f69b6502112c77cf6c9b57cb
child 288867 9d5c76e1a730842b4aab24454b773d1872f6c651
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, sledru
bugs1196317
milestone42.0a2
Bug 1196317 - Optimize CallbackObject::mCreationStack out from cycle collection graph when possible. r=mccr8, a=sledru
dom/base/nsGlobalWindow.cpp
dom/bindings/CallbackObject.h
dom/events/EventListenerManager.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1913,20 +1913,17 @@ void
 nsGlobalWindow::UnmarkGrayTimers()
 {
   for (nsTimeout* timeout = mTimeouts.getFirst();
        timeout;
        timeout = timeout->getNext()) {
     if (timeout->mScriptHandler) {
       Function* f = timeout->mScriptHandler->GetCallback();
       if (f) {
-        // Callable() already does xpc_UnmarkGrayObject.
-        DebugOnly<JS::Handle<JSObject*> > o = f->Callable();
-        MOZ_ASSERT(!JS::ObjectIsMarkedGray(o.value),
-                   "Should have been unmarked");
+        f->MarkForCC();
       }
     }
   }
 }
 
 //*****************************************************************************
 // nsGlobalWindow::nsIScriptGlobalObject
 //*****************************************************************************
--- a/dom/bindings/CallbackObject.h
+++ b/dom/bindings/CallbackObject.h
@@ -78,16 +78,26 @@ public:
   {
     JSObject* result = mCreationStack;
     if (result) {
       JS::ExposeObjectToActiveJS(result);
     }
     return result;
   }
 
+  void MarkForCC()
+  {
+    if (mCallback) {
+      JS::ExposeObjectToActiveJS(mCallback);
+    }
+    if (mCreationStack) {
+      JS::ExposeObjectToActiveJS(mCreationStack);
+    }
+  }
+
   /*
    * This getter does not change the color of the JSObject meaning that the
    * object returned is not guaranteed to be kept alive past the next CC.
    *
    * This should only be called if you are certain that the return value won't
    * be passed into a JS API function and that it won't be stored without being
    * rooted (or otherwise signaling the stored value to the CC).
    */
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1462,23 +1462,22 @@ EventListenerManager::MarkForCC()
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
     const Listener& listener = mListeners.ElementAt(i);
     JSEventHandler* jsEventHandler = listener.GetJSEventHandler();
     if (jsEventHandler) {
       const TypedEventHandler& typedHandler =
         jsEventHandler->GetTypedEventHandler();
       if (typedHandler.HasEventHandler()) {
-        JS::ExposeObjectToActiveJS(typedHandler.Ptr()->Callable());
+        typedHandler.Ptr()->MarkForCC();
       }
     } else if (listener.mListenerType == Listener::eWrappedJSListener) {
       xpc_TryUnmarkWrappedGrayObject(listener.mListener.GetXPCOMCallback());
     } else if (listener.mListenerType == Listener::eWebIDLListener) {
-      // Callback() unmarks gray
-      listener.mListener.GetWebIDLCallback()->Callback();
+      listener.mListener.GetWebIDLCallback()->MarkForCC();
     }
   }
   if (mRefCnt.IsPurple()) {
     mRefCnt.RemovePurple();
   }
 }
 
 void