Bug 1052042 - Move the pre-pop GC to AutoEntryScript. r=billm
authorBobby Holley <bobbyholley@gmail.com>
Wed, 13 Aug 2014 15:36:44 -0700
changeset 221000 05842b43f23b6ee10a8d75097ce0201cfa92d3de
parent 220999 d60846941972c0b4ed394e8a0801bd416b5c2ea3
child 221001 97a9985d440942e641dd7f6c8762f819f0158cbc
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1052042
milestone34.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 1052042 - Move the pre-pop GC to AutoEntryScript. r=billm
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
js/xpconnect/src/nsCxPusher.cpp
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -343,16 +343,24 @@ AutoEntryScript::AutoEntryScript(nsIGlob
   , ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true)
   , mWebIDLCallerPrincipal(nullptr)
 {
   MOZ_ASSERT(aGlobalObject);
   MOZ_ASSERT_IF(!aCx, aIsMainThread); // cx is mandatory off-main-thread.
   MOZ_ASSERT_IF(aCx && aIsMainThread, aCx == FindJSContext(aGlobalObject));
 }
 
+AutoEntryScript::~AutoEntryScript()
+{
+  // GC when we pop a script entry point. This is a useful heuristic that helps
+  // us out on certain (flawed) benchmarks like sunspider, because it lets us
+  // avoid GCing during the timing loop.
+  JS_MaybeGC(cx());
+}
+
 AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
   : ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ false)
   , mCallerOverride(nsContentUtils::GetCurrentJSContextForThread())
 {
 }
 
 AutoNoJSAPI::AutoNoJSAPI(bool aIsMainThread)
   : ScriptSettingsStackEntry()
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -196,16 +196,18 @@ private:
 class AutoEntryScript : public AutoJSAPI,
                         protected ScriptSettingsStackEntry {
 public:
   explicit AutoEntryScript(nsIGlobalObject* aGlobalObject,
                   bool aIsMainThread = NS_IsMainThread(),
                   // Note: aCx is mandatory off-main-thread.
                   JSContext* aCx = nullptr);
 
+  ~AutoEntryScript();
+
   void SetWebIDLCallerPrincipal(nsIPrincipal *aPrincipal) {
     mWebIDLCallerPrincipal = aPrincipal;
   }
 
 private:
   // It's safe to make this a weak pointer, since it's the subject principal
   // when we go on the stack, so can't go away until after we're gone.  In
   // particular, this is only used from the CallSetup constructor, and only in
--- a/js/xpconnect/src/nsCxPusher.cpp
+++ b/js/xpconnect/src/nsCxPusher.cpp
@@ -46,25 +46,16 @@ AutoCxPusher::AutoCxPusher(JSContext* cx
                                        : js::DefaultObjectForContextOrNull(cx);
     if (compartmentObject)
       mAutoCompartment.construct(cx, compartmentObject);
   }
 }
 
 AutoCxPusher::~AutoCxPusher()
 {
-  // GC when we pop a script entry point. This is a useful heuristic that helps
-  // us out on certain (flawed) benchmarks like sunspider, because it lets us
-  // avoid GCing during the timing loop.
-  //
-  // NB: We need to take care to only do this if we're in a compartment,
-  // otherwise JS_MaybeGC will segfault.
-  if (mScx && !mAutoCompartment.empty())
-    JS_MaybeGC(nsXPConnect::XPConnect()->GetCurrentJSContext());
-
   // Leave the compartment and request before popping.
   mAutoCompartment.destroyIfConstructed();
   mAutoRequest.destroyIfConstructed();
 
   // When we push a context, we may save the frame chain and pretend like we
   // haven't entered any compartment. This gets restored on Pop(), but we can
   // run into trouble if a Push/Pop are interleaved with a
   // JSAutoEnterCompartment. Make sure the compartment depth right before we