Bug 937152 - Remove XPCWrappedJS::mMainThread and mMainThreadOnly. r=bholley, a=bajaj
authorAndrew McCreight <continuation@gmail.com>
Sun, 17 Nov 2013 14:47:02 -0800
changeset 167808 1aa44c9f128dbf8213d5df805bf810e686df3d97
parent 167807 e02d5c7b1e628032f027360fbef9bd15b0dd2532
child 167809 74e9dd9a411cad59822577a62ef33e339ae9927c
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, bajaj
bugs937152
milestone27.0
Bug 937152 - Remove XPCWrappedJS::mMainThread and mMainThreadOnly. r=bholley, a=bajaj
js/xpconnect/src/XPCWrappedJS.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCWrappedJS.cpp
+++ b/js/xpconnect/src/XPCWrappedJS.cpp
@@ -170,30 +170,16 @@ nsXPCWrappedJS::AddRef(void)
 
 nsrefcnt
 nsXPCWrappedJS::Release(void)
 {
     if (!MOZ_LIKELY(NS_IsMainThread()))
         MOZ_CRASH();
     NS_PRECONDITION(0 != mRefCnt, "dup release");
 
-    if (mMainThreadOnly && !NS_IsMainThread()) {
-        // We'd like to abort here, but this can happen if someone uses a proxy
-        // for the nsXPCWrappedJS.
-        nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-        // If we can't get the main thread anymore we just leak, but this really
-        // shouldn't happen.
-        MOZ_ASSERT(mainThread, "Can't get main thread, leaking nsXPCWrappedJS!");
-        if (mainThread) {
-            NS_ProxyRelease(mainThread,
-                            static_cast<nsIXPConnectWrappedJS*>(this));
-        }
-        return mRefCnt;
-    }
-
     // need to take the map lock here to prevent GetNewOrUsed from trying
     // to reuse a wrapper on one thread while it's being destroyed on another
     XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
     XPCAutoLock lock(rt->GetMapLock());
 
 do_decrement:
 
     nsrefcnt cnt = --mRefCnt;
@@ -248,38 +234,16 @@ JSObject*
 nsXPCWrappedJS::GetJSObject()
 {
     if (mJSObj) {
         JS::ExposeObjectToActiveJS(mJSObj);
     }
     return mJSObj;
 }
 
-static bool
-CheckMainThreadOnly(nsXPCWrappedJS *aWrapper)
-{
-    if(aWrapper->IsMainThreadOnly())
-        return NS_IsMainThread();
-
-    nsCOMPtr<nsIClassInfo> ci;
-    CallQueryInterface(aWrapper, getter_AddRefs(ci));
-    if (ci) {
-        uint32_t flags;
-        if (NS_SUCCEEDED(ci->GetFlags(&flags)) && !(flags & nsIClassInfo::MAIN_THREAD_ONLY))
-            return true;
-
-        if (!NS_IsMainThread())
-            return false;
-    }
-
-    aWrapper->SetIsMainThreadOnly();
-
-    return true;
-}
-
 // static
 nsresult
 nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
                              REFNSIID aIID,
                              nsISupports* aOuter,
                              nsXPCWrappedJS** wrapperResult)
 {
     // Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
@@ -338,23 +302,16 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleO
 #if DEBUG_xpc_leaks
                 printf("Created nsXPCWrappedJS %p, JSObject is %p\n",
                        (void*)wrapper, (void*)jsObj);
 #endif
                 XPCAutoLock lock(rt->GetMapLock());
                 map->Add(cx, root);
             }
 
-            if (!CheckMainThreadOnly(root)) {
-                XPCAutoLock lock(rt->GetMapLock());
-                map->Remove(root);
-
-                wrapper = nullptr;
-            }
-
             goto return_wrapper;
         } else {
             // just a root wrapper
             nsXPCWrappedJSClass* rootClazz = nullptr;
             nsXPCWrappedJSClass::GetNewOrUsed(cx, NS_GET_IID(nsISupports),
                                               &rootClazz);
             if (!rootClazz)
                 goto return_wrapper;
@@ -370,23 +327,16 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleO
             {   // scoped lock
 #if DEBUG_xpc_leaks
                 printf("Created nsXPCWrappedJS %p, JSObject is %p\n",
                        (void*)root, (void*)rootJSObj);
 #endif
                 XPCAutoLock lock(rt->GetMapLock());
                 map->Add(cx, root);
             }
-
-            if (!CheckMainThreadOnly(root)) {
-                XPCAutoLock lock(rt->GetMapLock());
-                map->Remove(root);
-
-                goto return_wrapper;
-            }
         }
     }
 
     // at this point we have a root and may need to build the specific wrapper
     MOZ_ASSERT(root,"bad root");
     MOZ_ASSERT(clazz,"bad clazz");
 
     if (!wrapper) {
@@ -420,29 +370,25 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext
                                JSObject* aJSObj,
                                nsXPCWrappedJSClass* aClass,
                                nsXPCWrappedJS* root,
                                nsISupports* aOuter)
     : mJSObj(aJSObj),
       mClass(aClass),
       mRoot(root ? root : this),
       mNext(nullptr),
-      mOuter(root ? nullptr : aOuter),
-      mMainThread(NS_IsMainThread()),
-      mMainThreadOnly(root && root->mMainThreadOnly)
+      mOuter(root ? nullptr : aOuter)
 {
 #ifdef DEBUG_stats_jband
     static int count = 0;
     static const int interval = 10;
     if (0 == (++count % interval))
         printf("//////// %d instances of nsXPCWrappedJS created\n", count);
 #endif
 
-    MOZ_ASSERT_IF(mMainThreadOnly, mMainThread);
-
     InitStub(GetClass()->GetIID());
 
     // intentionally do double addref - see Release().
     NS_ADDREF_THIS();
     NS_ADDREF_THIS();
     NS_ADDREF(aClass);
     NS_IF_ADDREF(mOuter);
 
@@ -569,30 +515,16 @@ nsXPCWrappedJS::CallMethod(uint16_t meth
                            nsXPTCMiniVariant* params)
 {
     // Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
     if (!MOZ_LIKELY(NS_IsMainThread()))
         MOZ_CRASH();
 
     if (!IsValid())
         return NS_ERROR_UNEXPECTED;
-    if (NS_IsMainThread() != mMainThread) {
-        NS_NAMED_LITERAL_STRING(kFmt, "Attempt to use JS function on a different thread calling %s.%s. JS objects may not be shared across threads.");
-        PRUnichar* msg =
-            nsTextFormatter::smprintf(kFmt.get(),
-                                      GetClass()->GetInterfaceName(),
-                                      info->name);
-        nsCOMPtr<nsIConsoleService> cs =
-            do_GetService(NS_CONSOLESERVICE_CONTRACTID);
-        if (cs)
-            cs->LogStringMessage(msg);
-        NS_Free(msg);
-
-        return NS_ERROR_NOT_SAME_THREAD;
-    }
     return GetClass()->CallMethod(this, methodIndex, info, params);
 }
 
 NS_IMETHODIMP
 nsXPCWrappedJS::GetInterfaceIID(nsIID** iid)
 {
     NS_PRECONDITION(iid, "bad param");
 
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -2726,22 +2726,16 @@ public:
     // category are only deleted when we see that their corresponding JSObject
     // is to be finalized.
     bool IsSubjectToFinalization() const {return IsValid() && mRefCnt == 1;}
     bool IsObjectAboutToBeFinalized() {return JS_IsAboutToBeFinalized(&mJSObj);}
 
     bool IsAggregatedToNative() const {return mRoot->mOuter != nullptr;}
     nsISupports* GetAggregatedNativeObject() const {return mRoot->mOuter;}
 
-    void SetIsMainThreadOnly() {
-        MOZ_ASSERT(mMainThread);
-        mMainThreadOnly = true;
-    }
-    bool IsMainThreadOnly() const {return mMainThreadOnly;}
-
     void TraceJS(JSTracer* trc);
     static void GetTraceName(JSTracer* trc, char *buf, size_t bufsize);
 
     virtual ~nsXPCWrappedJS();
 protected:
     nsXPCWrappedJS();   // not implemented
     nsXPCWrappedJS(JSContext* cx,
                    JSObject* aJSObj,
@@ -2752,18 +2746,16 @@ protected:
    void Unlink();
 
 private:
     JS::Heap<JSObject*> mJSObj;
     nsXPCWrappedJSClass* mClass;
     nsXPCWrappedJS* mRoot;
     nsXPCWrappedJS* mNext;
     nsISupports* mOuter;    // only set in root
-    bool mMainThread;
-    bool mMainThreadOnly;
 };
 
 /***************************************************************************/
 
 class XPCJSObjectHolder : public nsIXPConnectJSObjectHolder,
                           public XPCRootSetElem
 {
 public: