Fix for bug 534341 (XPConnect should not unroot globals of non-main thread contexts). r=bent.
authorPeter Van der Beken <peterv@propagandism.org>
Sun, 13 Dec 2009 16:58:04 -0800
changeset 35710 8f6bdbf8e7017fb0bdfe875035402c60701a8cdb
parent 35709 50cc41c7a17698106e4c8320cee3f49d5b29a34b
child 35711 efa4edae64d961bf831cbb6903868f4dc82911e4
push id10687
push userpvanderbeken@mozilla.com
push dateMon, 14 Dec 2009 05:10:28 +0000
treeherdermozilla-central@8f6bdbf8e701 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs534341
milestone1.9.3a1pre
Fix for bug 534341 (XPConnect should not unroot globals of non-main thread contexts). r=bent.
js/src/xpconnect/src/xpcjsruntime.cpp
js/src/xpconnect/src/xpcprivate.h
--- a/js/src/xpconnect/src/xpcjsruntime.cpp
+++ b/js/src/xpconnect/src/xpcjsruntime.cpp
@@ -439,17 +439,18 @@ void XPCJSRuntime::AddXPConnectRoots(JSC
 void XPCJSRuntime::UnrootContextGlobals()
 {
     mUnrootedGlobalCount = 0;
     JSContext *iter = nsnull, *acx;
     while((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
     {
         NS_ASSERTION(!JS_HAS_OPTION(acx, JSOPTION_UNROOTED_GLOBAL),
                      "unrooted global should be set only during CC");
-        if(nsXPConnect::GetXPConnect()->GetRequestDepth(acx) == 0)
+        if(XPCPerThreadData::IsMainThreadContext(acx) &&
+           nsXPConnect::GetXPConnect()->GetRequestDepth(acx) == 0)
         {
             JS_ClearNewbornRoots(acx);
             if(acx->globalObject)
             {
                 JS_ToggleOptions(acx, JSOPTION_UNROOTED_GLOBAL);
                 ++mUnrootedGlobalCount;
             }
         }
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -3432,16 +3432,21 @@ public:
         else if(sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread())
         {
             return sMainThreadData;
         }
 
         return GetDataImpl(cx);
     }
 
+    static inline JSBool IsMainThreadContext(JSContext *cx)
+    {
+        return cx->thread == sMainJSThread;
+    }
+
     static void CleanupAllThreads();
 
     ~XPCPerThreadData();
 
     nsresult GetException(nsIException** aException)
     {
         if(EnsureExceptionManager())
             return mExceptionManager->GetCurrentException(aException);