Bug 860085 - Remove XPCCallContext refcounting optimization. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Wed, 03 Jul 2013 11:05:20 -0600
changeset 137370 5e4bb03186a20e75861390f7a88e3e11a4e548a3
parent 137369 50d04f7ba2007ca4ab3f003f4934308de0582ff6
child 137371 a1ac79e6ba29a488e56fd2e966bfcb14f3b8706d
push id24920
push userphilringnalda@gmail.com
push dateThu, 04 Jul 2013 17:03:47 +0000
treeherdermozilla-central@efa23d6bd3fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs860085
milestone25.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 860085 - Remove XPCCallContext refcounting optimization. r=gabor 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
@@ -1133,17 +1133,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!