Bug 620984 - 'Firefox 4.0b8 Crash Report [@ DEBUG_CheckWrapperThreadSafety(XPCWrappedNative const*) ]'. r=jst, a=blocking.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 13 Jan 2011 13:09:35 -0800
changeset 60581 f2da7d8646f63b6871b581431e876d51fa8605f7
parent 60580 a6bd34672545f87a6606a427cedfa426ddf9d65a
child 60582 c8cb1ab7612aeef4da89d843601073e941dfa6ec
push id18037
push usercleary@mozilla.com
push dateFri, 14 Jan 2011 17:42:55 +0000
treeherdermozilla-central@4e0501a0c5e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst, blocking
bugs620984
milestone2.0b10pre
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 620984 - 'Firefox 4.0b8 Crash Report [@ DEBUG_CheckWrapperThreadSafety(XPCWrappedNative const*) ]'. r=jst, a=blocking.
js/src/xpconnect/src/xpcprivate.h
js/src/xpconnect/src/xpcwrappednative.cpp
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -2800,17 +2800,18 @@ private:
     XPCNativeSet*                mSet;
     JSObject*                    mFlatJSObject;
     XPCNativeScriptableInfo*     mScriptableInfo;
     XPCWrappedNativeTearOffChunk mFirstChunk;
     PRWord                       mWrapperWord;
 
 #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
 public:
-    nsCOMPtr<nsIThread>          mThread; // Don't want to overload _mOwningThread
+    // Don't want to overload _mOwningThread
+    PRThread*                    mThread; 
 #endif
 };
 
 /***************************************************************************
 ****************************************************************************
 *
 * Core classes for wrapped JSObject for use from native code...
 *
--- a/js/src/xpconnect/src/xpcwrappednative.cpp
+++ b/js/src/xpconnect/src/xpcwrappednative.cpp
@@ -848,16 +848,19 @@ XPCWrappedNative::GetUsedOnly(XPCCallCon
 // This ctor is used if this object will have a proto.
 XPCWrappedNative::XPCWrappedNative(already_AddRefed<nsISupports> aIdentity,
                                    XPCWrappedNativeProto* aProto)
     : mMaybeProto(aProto),
       mSet(aProto->GetSet()),
       mFlatJSObject(INVALID_OBJECT), // non-null to pass IsValid() test
       mScriptableInfo(nsnull),
       mWrapperWord(0)
+#ifdef XPC_CHECK_WRAPPER_THREADSAFETY
+    , mThread(PR_GetCurrentThread())
+#endif
 {
     mIdentity = aIdentity.get();
 
     NS_ASSERTION(mMaybeProto, "bad ctor param");
     NS_ASSERTION(mSet, "bad ctor param");
 
     DEBUG_TrackNewWrapper(this);
 }
@@ -867,16 +870,19 @@ XPCWrappedNative::XPCWrappedNative(alrea
                                    XPCWrappedNativeScope* aScope,
                                    XPCNativeSet* aSet)
 
     : mMaybeScope(TagScope(aScope)),
       mSet(aSet),
       mFlatJSObject(INVALID_OBJECT), // non-null to pass IsValid() test
       mScriptableInfo(nsnull),
       mWrapperWord(0)
+#ifdef XPC_CHECK_WRAPPER_THREADSAFETY
+    , mThread(PR_GetCurrentThread())
+#endif
 {
     mIdentity = aIdentity.get();
 
     NS_ASSERTION(aScope, "bad ctor param");
     NS_ASSERTION(aSet, "bad ctor param");
 
     DEBUG_TrackNewWrapper(this);
 }
@@ -1187,17 +1193,17 @@ XPCWrappedNative::FinishInit(XPCCallCont
     if(mScriptableInfo && mScriptableInfo->GetFlags().WantCreate() &&
        NS_FAILED(mScriptableInfo->GetCallback()->Create(this, ccx,
                                                         mFlatJSObject)))
     {
         return JS_FALSE;
     }
 
 #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
-    mThread = do_GetCurrentThread();
+    NS_ASSERTION(mThread, "Should have been set at construction time!");
 
     if(HasProto() && GetProto()->ClassIsMainThreadOnly() && !NS_IsMainThread())
     {
         DEBUG_ReportWrapperThreadSafetyError(ccx,
             "MainThread only wrapper created on the wrong thread", this);
         return JS_FALSE;
     }
 #endif
@@ -3745,27 +3751,28 @@ void DEBUG_ReportWrapperThreadSafetyErro
 }
 
 void DEBUG_CheckWrapperThreadSafety(const XPCWrappedNative* wrapper)
 {
     XPCWrappedNativeProto* proto = wrapper->GetProto();
     if(proto && proto->ClassIsThreadSafe())
         return;
 
-    PRBool val;
     if(proto && proto->ClassIsMainThreadOnly())
     {
+        // NS_IsMainThread is safe to call even after we've started shutting
+        // down.
         if(!NS_IsMainThread())
         {
             XPCCallContext ccx(NATIVE_CALLER);
             DEBUG_ReportWrapperThreadSafetyError(ccx,
                 "Main Thread Only wrapper accessed on another thread", wrapper);
         }
     }
-    else if(NS_SUCCEEDED(wrapper->mThread->IsOnCurrentThread(&val)) && !val)
+    else if(PR_GetCurrentThread() != wrapper->mThread)
     {
         XPCCallContext ccx(NATIVE_CALLER);
         DEBUG_ReportWrapperThreadSafetyError(ccx,
             "XPConnect WrappedNative is being accessed on multiple threads but "
             "the underlying native xpcom object does not have a "
             "nsIClassInfo with the 'THREADSAFE' flag set", wrapper);
     }
 }