Backed out changeset 2864e2610800 (bug 877584) for causing bug 881266
authorEd Morley <emorley@mozilla.com>
Tue, 11 Jun 2013 16:11:14 +0100
changeset 134643 86413e921d5d5bdbefd6475619ebb0eab6185184
parent 134642 200344975d6f14ea2cfe7d074426bf49aa2d55b5
child 134644 9aa012a41d0d9e80ffc9e0c3dc3bc9c9a88f39b5
child 134674 acc83523042859fe4389993f95aab1f5efc68946
push id29308
push useremorley@mozilla.com
push dateTue, 11 Jun 2013 15:25:03 +0000
treeherdermozilla-inbound@9aa012a41d0d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs877584, 881266
milestone24.0a1
backs out2864e2610800d032cde71bdb000b2691ea7a4480
first release with
nightly linux32
86413e921d5d / 24.0a1 / 20130611081224 / files
nightly linux64
86413e921d5d / 24.0a1 / 20130611081224 / files
nightly mac
86413e921d5d / 24.0a1 / 20130611081224 / files
nightly win32
86413e921d5d / 24.0a1 / 20130611081224 / files
nightly win64
86413e921d5d / 24.0a1 / 20130611081224 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 2864e2610800 (bug 877584) for causing bug 881266
content/base/src/nsContentUtils.cpp
js/xpconnect/idl/nsIXPConnect.idl
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsCycleCollector.h
xpcom/glue/nsCycleCollectionJSRuntime.h
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -49,17 +49,16 @@
 #include "nsCOMPtr.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentDLF.h"
 #include "nsContentList.h"
 #include "nsContentPolicyUtils.h"
 #include "nsCPrefetchService.h"
 #include "nsCRT.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsCycleCollector.h"
 #include "nsDataHashtable.h"
 #include "nsDocShellCID.h"
 #include "nsDOMCID.h"
 #include "nsDOMDataTransfer.h"
 #include "nsDOMJSUtils.h"
 #include "nsDOMMutationObserver.h"
 #include "nsDOMTouchEvent.h"
 #include "nsError.h"
@@ -4321,32 +4320,37 @@ nsContentUtils::DestroyAnonymousContent(
   }
 }
 
 /* static */
 void
 nsContentUtils::HoldJSObjects(void* aScriptObjectHolder,
                               nsScriptObjectTracer* aTracer)
 {
-  cyclecollector::AddJSHolder(aScriptObjectHolder, aTracer);
+  MOZ_ASSERT(sXPConnect, "Tried to HoldJSObjects when there was no XPConnect");
+  if (sXPConnect) {
+    sXPConnect->AddJSHolder(aScriptObjectHolder, aTracer);
+  }
 }
 
 /* static */
 void
 nsContentUtils::DropJSObjects(void* aScriptObjectHolder)
 {
-  cyclecollector::RemoveJSHolder(aScriptObjectHolder);
+  if (sXPConnect) {
+    sXPConnect->RemoveJSHolder(aScriptObjectHolder);
+  }
 }
 
 #ifdef DEBUG
 /* static */
 bool
-nsContentUtils::AreJSObjectsHeld(void* aScriptObjectHolder)
-{
-  return cyclecollector::TestJSHolder(aScriptObjectHolder);
+nsContentUtils::AreJSObjectsHeld(void* aScriptHolder)
+{
+  return sXPConnect->TestJSHolder(aScriptHolder);
 }
 #endif
 
 /* static */
 void
 nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)
 {
   nsIMEStateManager::OnInstalledMenuKeyboardListener(aInstalling);
--- a/js/xpconnect/idl/nsIXPConnect.idl
+++ b/js/xpconnect/idl/nsIXPConnect.idl
@@ -286,17 +286,17 @@ interface nsIXPCFunctionThisTranslator :
 %{ C++
 // For use with the service manager
 // {CB6593E0-F9B2-11d2-BDD6-000064657374}
 #define NS_XPCONNECT_CID \
 { 0xcb6593e0, 0xf9b2, 0x11d2, \
     { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
 %}
 
-[uuid(4498aa26-62df-4a4f-8a45-7ddfd7f84834)]
+[uuid(2950bc62-ba03-4465-9685-a0eec9e188c2)]
 interface nsIXPConnect : nsISupports
 {
 %{ C++
   NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID)
 %}
 
     /**
      * Initializes classes on a global object that has already been created.
@@ -556,16 +556,37 @@ interface nsIXPConnect : nsISupports
      *         to this method.
      */
     [noscript] jsval evalInSandboxObject(in AString source, in string filename,
                                          in JSContextPtr cx,
                                          in JSObjectPtr sandbox,
                                          in boolean returnStringOnly);
 
     /**
+     * Root JS objects held by aHolder.
+     * @param aHolder The object that hold the JS objects that should be rooted.
+     * @param aTrace The tracer for aHolder.
+     */
+    [noscript,notxpcom] void addJSHolder(in voidPtr aHolder,
+                                         in nsScriptObjectTracerPtr aTracer);
+
+    /**
+     * Stop rooting the JS objects held by aHolder.
+     * @param aHolder The object that hold the rooted JS objects.
+     */
+    [noscript,notxpcom] void removeJSHolder(in voidPtr aHolder);
+
+    /**
+     * Test to see if a JS holder is in our hashtable.
+     * Only available in debug builds.
+     * @param aHolder The object to test for.
+     */
+    [noscript,notxpcom] bool testJSHolder(in voidPtr aHolder);
+
+    /**
      * Note aJSContext as a child to the cycle collector.
      * @param aJSContext The JSContext to note.
      * @param aCb The cycle collection traversal callback.
      */
     [noscript,notxpcom] void noteJSContext(in JSContextPtr aJSContext,
                                            in nsCCTraversalCallbackRef aCb);
 
     /**
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -1783,23 +1783,25 @@ nsXPConnect::AddJSHolder(void* aHolder, 
 }
 
 void
 nsXPConnect::RemoveJSHolder(void* aHolder)
 {
     mRuntime->RemoveJSHolder(aHolder);
 }
 
-#ifdef DEBUG
 bool
 nsXPConnect::TestJSHolder(void* aHolder)
 {
+#ifdef DEBUG
     return mRuntime->TestJSHolder(aHolder);
+#else
+    return false;
+#endif
 }
-#endif
 
 NS_IMETHODIMP
 nsXPConnect::SetReportAllJSExceptions(bool newval)
 {
     // Ignore if the environment variable was set.
     if (gReportAllJSExceptions != 1)
         gReportAllJSExceptions = newval ? 2 : 0;
 
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -486,21 +486,17 @@ public:
             MOZ_CRASH();
 
         return gSelf;
     }
 
     static XPCJSRuntime* GetRuntimeInstance();
     XPCJSRuntime* GetRuntime() {return mRuntime;}
 
-    void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer) MOZ_OVERRIDE;
-    void RemoveJSHolder(void* aHolder) MOZ_OVERRIDE;
-
 #ifdef DEBUG
-    bool TestJSHolder(void* aHolder) MOZ_OVERRIDE;
     void SetObjectToUnlink(void* aObject);
     void AssertNoObjectsToTrace(void* aPossibleJSHolder);
 #endif
 
     static JSBool IsISupportsDescendant(nsIInterfaceInfo* info);
 
     nsIXPCSecurityManager* GetDefaultSecurityManager() const
     {
@@ -795,18 +791,18 @@ public:
     static void FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool isCompartmentGC);
 
     inline void AddVariantRoot(XPCTraceableVariant* variant);
     inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
     inline void AddObjectHolderRoot(XPCJSObjectHolder* holder);
 
     void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
     void RemoveJSHolder(void* aHolder);
+    bool TestJSHolder(void* aHolder);
 #ifdef DEBUG
-    bool TestJSHolder(void* aHolder);
     void SetObjectToUnlink(void* aObject) { mObjectToUnlink = aObject; }
     void AssertNoObjectsToTrace(void* aPossibleJSHolder);
 #endif
 
     static void SuspectWrappedNative(XPCWrappedNative *wrapper,
                                      nsCycleCollectionNoteRootCallback &cb);
 
     void DebugDump(int16_t depth);
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -2941,31 +2941,16 @@ nsCycleCollector::SizeOfIncludingThis(ns
     *aPurpleBufferSize = mPurpleBuf.SizeOfExcludingThis(aMallocSizeOf);
 
     // These fields are deliberately not measured:
     // - mResults: because it's tiny and only contains scalars.
     // - mJSRuntime: because it's non-owning and measured by JS reporters.
     // - mParams: because it only contains scalars.
 }
 
-// This is our special sentinel value that tells us that we've shut
-// down this thread's CC.
-static nsCycleCollector* const kSentinelCollector = (nsCycleCollector*)1;
-
-inline bool
-CollectorIsShutDown(nsCycleCollector* aCollector)
-{
-    return aCollector == kSentinelCollector;
-}
-
-inline bool
-HaveCollector(nsCycleCollector* aCollector)
-{
-    return aCollector && !CollectorIsShutDown(aCollector);
-}
 
 ////////////////////////////////////////////////////////////////////////
 // Module public API (exported in nsCycleCollector.h)
 // Just functions that redirect into the singleton, once it's built.
 ////////////////////////////////////////////////////////////////////////
 
 void
 nsCycleCollector_registerJSRuntime(nsCycleCollectionJSRuntime *rt)
@@ -2976,78 +2961,52 @@ nsCycleCollector_registerJSRuntime(nsCyc
         collector->RegisterJSRuntime(rt);
 }
 
 void
 nsCycleCollector_forgetJSRuntime()
 {
     nsCycleCollector *collector = sCollector.get();
 
-    if (CollectorIsShutDown(collector)) {
+    if (collector == (nsCycleCollector*)1) {
+        // This is our special sentinel value that tells us that we've shut
+        // down this thread's CC.
         return;
     }
 
     if (collector)
         collector->ForgetJSRuntime();
 }
 
-void
-cyclecollector::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
-{
-    nsCycleCollector *collector = sCollector.get();
-
-    MOZ_ASSERT(HaveCollector(collector));
-
-    collector->JSRuntime()->AddJSHolder(aHolder, aTracer);
-}
-
-void
-cyclecollector::RemoveJSHolder(void* aHolder)
-{
-    nsCycleCollector *collector = sCollector.get();
-
-    MOZ_ASSERT(HaveCollector(collector));
-
-    collector->JSRuntime()->RemoveJSHolder(aHolder);
-}
-
-#ifdef DEBUG
-bool
-cyclecollector::TestJSHolder(void* aHolder)
-{
-    nsCycleCollector *collector = sCollector.get();
-
-    MOZ_ASSERT(HaveCollector(collector));
-
-    return collector->JSRuntime()->TestJSHolder(aHolder);
-}
-#endif
-
 nsPurpleBufferEntry*
 NS_CycleCollectorSuspect2(void *n, nsCycleCollectionParticipant *cp)
 {
     nsCycleCollector *collector = sCollector.get();
 
     if (!collector) {
         MOZ_CRASH();
     }
 
-    if (CollectorIsShutDown(collector)) {
+    if (collector == (nsCycleCollector*)1) {
+        // This is our special sentinel value that tells us that we've shut
+        // down this thread's CC.
         return nullptr;
     }
 
     return collector->Suspect(n, cp);
 }
 
 uint32_t
 nsCycleCollector_suspectedCount()
 {
     nsCycleCollector *collector = sCollector.get();
 
-    if (CollectorIsShutDown(collector)) {
+    if (collector == (nsCycleCollector*)1) {
+        // This is our special sentinel value that tells us that we've shut
+        // down this thread's CC.
         return 0;
     }
 
     return collector ? collector->SuspectedCount() : 0;
 }
 
 bool
 nsCycleCollector_init()
@@ -3153,11 +3112,11 @@ nsCycleCollector_shutdown()
 
     if (collector) {
         PROFILER_LABEL("CC", "nsCycleCollector_shutdown");
         collector->CheckThreadSafety();
         collector->Shutdown();
         delete collector;
         // We want to be able to distinguish never having a collector from
         // having a shutdown collector.
-        sCollector.set(kSentinelCollector);
+        sCollector.set(reinterpret_cast<nsCycleCollector*>(1));
     }
 }
--- a/xpcom/base/nsCycleCollector.h
+++ b/xpcom/base/nsCycleCollector.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsCycleCollector_h__
 #define nsCycleCollector_h__
 
 class nsCycleCollectionJSRuntime;
 class nsICycleCollectorListener;
 class nsISupports;
-class nsScriptObjectTracer;
 
 // Contains various stats about the cycle collection.
 class nsCycleCollectorResults
 {
 public:
     nsCycleCollectorResults() :
         mForcedGC(false), mMergedZones(false),
         mVisitedRefCounted(0), mVisitedGCed(0),
@@ -59,21 +58,9 @@ void nsCycleCollector_forgetJSRuntime();
 { 0x58be81b4, 0x39d2, 0x437c, \
 { 0x94, 0xea, 0xae, 0xde, 0x2c, 0x62, 0x08, 0xd3 } }
 
 extern nsresult
 nsCycleCollectorLoggerConstructor(nsISupports* outer,
                                   const nsIID& aIID,
                                   void* *aInstancePtr);
 
-namespace mozilla {
-namespace cyclecollector {
-
-void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
-void RemoveJSHolder(void* aHolder);
-#ifdef DEBUG
-bool TestJSHolder(void* aHolder);
-#endif
-
-} // namespace cyclecollector
-} // namespace mozilla
-
 #endif // nsCycleCollector_h__
--- a/xpcom/glue/nsCycleCollectionJSRuntime.h
+++ b/xpcom/glue/nsCycleCollectionJSRuntime.h
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsCycleCollectionJSRuntime_h__
 #define nsCycleCollectionJSRuntime_h__
 
 class nsCycleCollectionParticipant;
 class nsCycleCollectionNoteRootCallback;
-class nsScriptObjectTracer;
 
 // Various methods the cycle collector needs to deal with Javascript.
 struct nsCycleCollectionJSRuntime
 {
   virtual nsresult BeginCycleCollection(nsCycleCollectionNoteRootCallback &aCb) = 0;
 
   /**
    * Called before/after transitioning to/from the main thread.
@@ -47,20 +46,15 @@ struct nsCycleCollectionJSRuntime
    */
   virtual void Collect(uint32_t aReason) = 0;
 
   /**
    * Get the JS cycle collection participant.
    */
   virtual nsCycleCollectionParticipant *GetParticipant() = 0;
 
-  virtual void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer) = 0;
-  virtual void RemoveJSHolder(void* aHolder) = 0;
-
 #ifdef DEBUG
-  virtual bool TestJSHolder(void* aHolder) = 0;
-
   virtual void SetObjectToUnlink(void* aObject) = 0;
   virtual void AssertNoObjectsToTrace(void* aPossibleJSHolder) = 0;
 #endif
 };
 
 #endif // nsCycleCollectionJSRuntime_h__