Bug 860085 - Remove XPCCallContext refcounting optimization. r=gabor a=bbajaj
authorBobby Holley <bobbyholley@gmail.com>
Fri, 19 Jul 2013 18:21:54 -0700
changeset 147987 dd08f5dd367cc0fc1da4d9312691d38e209af70e
parent 147986 904e8f0210be36d96927dfed9e045d79fa64c29a
child 147988 b3aa850f03fc54392a9dc26a46096d89902a165b
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor, bbajaj
bugs860085
milestone24.0a2
Bug 860085 - Remove XPCCallContext refcounting optimization. r=gabor a=bbajaj We only use XPCCallContext for reflector calls now, at which point an AddRef is totally insignificant. Using an auto pointer here lets us clean up some code, and makes the XPCCallContext destructor start to look pretty sane. :-)
js/xpconnect/src/XPCCallContext.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCCallContext.cpp
+++ b/js/xpconnect/src/XPCCallContext.cpp
@@ -44,21 +44,16 @@ XPCCallContext::XPCCallContext(XPCContex
         return;
 
     mXPCContext = XPCContext::GetXPCContext(mJSContext);
     mPrevCallerLanguage = mXPCContext->SetCallingLangType(mCallerLanguage);
 
     // hook into call context chain.
     mPrevCallContext = XPCJSRuntime::Get()->SetCallContext(this);
 
-    // We only need to addref xpconnect once so only do it if this is the first
-    // context in the chain.
-    if (!mPrevCallContext)
-        NS_ADDREF(mXPC);
-
     mState = HAVE_CONTEXT;
 
     if (!obj)
         return;
 
     mMethodIndex = 0xDEAD;
 
     mState = HAVE_OBJECT;
@@ -236,31 +231,22 @@ XPCCallContext::SystemIsBeingShutDown()
     mXPCContext = nullptr;
     mState = SYSTEM_SHUTDOWN;
     if (mPrevCallContext)
         mPrevCallContext->SystemIsBeingShutDown();
 }
 
 XPCCallContext::~XPCCallContext()
 {
-    // do cleanup...
-
-    bool shouldReleaseXPC = false;
-
     if (mXPCContext) {
         mXPCContext->SetCallingLangType(mPrevCallerLanguage);
 
         DebugOnly<XPCCallContext*> old = XPCJSRuntime::Get()->SetCallContext(mPrevCallContext);
         NS_ASSERTION(old == this, "bad pop from per thread data");
-
-        shouldReleaseXPC = mPrevCallContext == nullptr;
     }
-
-    if (shouldReleaseXPC && mXPC)
-        NS_RELEASE(mXPC);
 }
 
 /* readonly attribute nsISupports Callee; */
 NS_IMETHODIMP
 XPCCallContext::GetCallee(nsISupports * *aCallee)
 {
     nsISupports* temp = mWrapper ? mWrapper->GetIdentityObject() : nullptr;
     NS_IF_ADDREF(temp);
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1135,17 +1135,17 @@ inline void CHECK_STATE(int s) const {NS
 #else
 #define CHECK_STATE(s) ((void)0)
 #endif
 
 private:
     mozilla::AutoPushJSContext      mPusher;
     State                           mState;
 
-    nsXPConnect*                    mXPC;
+    nsRefPtr<nsXPConnect>           mXPC;
 
     XPCContext*                     mXPCContext;
     JSContext*                      mJSContext;
 
     XPCContext::LangType            mCallerLanguage;
 
     // ctor does not necessarily init the following. BEWARE!