Bug 1473213 (Part 3) - Refactor JSContext code for changing zones r=sfink
authorPaul Bone <pbone@mozilla.com>
Wed, 08 Aug 2018 12:05:59 +1000
changeset 431386 5f35c86a0d22072c5287f46f338bcbd36ea5d76c
parent 431385 8217b33680fa66e2553d27c9076a6bf429df3431
child 431387 f3796f1a571b6e11e247f366dc45cecd97d77729
push id34440
push userapavel@mozilla.com
push dateTue, 14 Aug 2018 16:15:57 +0000
treeherdermozilla-central@48a45df79f32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1473213
milestone63.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 1473213 (Part 3) - Refactor JSContext code for changing zones r=sfink * Introduce a setZone method that changes the zone and the freelist. * leaveAtomsZone() private
js/src/vm/JSContext-inl.h
js/src/vm/JSContext.h
--- a/js/src/vm/JSContext-inl.h
+++ b/js/src/vm/JSContext-inl.h
@@ -411,18 +411,29 @@ JSContext::enterRealm(JS::Realm* realm)
     realm->enter();
     setRealm(realm);
 }
 
 inline void
 JSContext::enterAtomsZone()
 {
     realm_ = nullptr;
-    zone_ = runtime_->unsafeAtomsZone();
-    if (helperThread()) {
+    setZone(runtime_->unsafeAtomsZone(), AtomsZone);
+}
+
+inline void
+JSContext::setZone(js::Zone *zone, JSContext::IsAtomsZone isAtomsZone)
+{
+    zone_ = zone;
+    if (zone == nullptr) {
+        freeLists_ = nullptr;
+        return;
+    }
+
+    if (isAtomsZone == AtomsZone && helperThread()) {
         MOZ_ASSERT(!zone_->wasGCStarted());
         freeLists_ = atomsZoneFreeLists_;
     } else {
         freeLists_ = &zone_->arenas.freeLists();
     }
 }
 
 inline void
@@ -479,21 +490,19 @@ JSContext::leaveAtomsZone(JS::Realm* old
 inline void
 JSContext::setRealm(JS::Realm* realm)
 {
     realm_ = realm;
     if (realm) {
         // This thread must have exclusive access to the zone.
         MOZ_ASSERT(CurrentThreadCanAccessZone(realm->zone()));
         MOZ_ASSERT(!realm->zone()->isAtomsZone());
-        zone_ = realm->zone();
-        freeLists_ = &zone_->arenas.freeLists();
+        setZone(realm->zone(), NotAtomsZone);
     } else {
-        zone_ = nullptr;
-        freeLists_ = nullptr;
+        setZone(nullptr, NotAtomsZone);
     }
 }
 
 inline void
 JSContext::setRealmForJitExceptionHandler(JS::Realm* realm)
 {
     // JIT code enters (same-compartment) realms without calling realm->enter()
     // so we don't call realm->leave() here.
--- a/js/src/vm/JSContext.h
+++ b/js/src/vm/JSContext.h
@@ -233,31 +233,37 @@ struct JSContext : public JS::RootingCon
      * should prefer using AutoRealm over JS::EnterRealm/JS::LeaveRealm.
      *
      * Also note that the JIT can enter (same-compartment) realms without going
      * through these methods - it will update cx->realm_ directly.
      */
   private:
     inline void setRealm(JS::Realm* realm);
     inline void enterRealm(JS::Realm* realm);
+
     inline void enterAtomsZone();
+    inline void leaveAtomsZone(JS::Realm* oldRealm);
+    enum IsAtomsZone {
+        AtomsZone,
+        NotAtomsZone
+    };
+    inline void setZone(js::Zone* zone, IsAtomsZone isAtomsZone);
 
     friend class js::AutoAllocInAtomsZone;
     friend class js::AutoRealm;
 
   public:
     inline void enterRealmOf(JSObject* target);
     inline void enterRealmOf(JSScript* target);
     inline void enterRealmOf(js::ObjectGroup* target);
     inline void enterNullRealm();
 
     inline void setRealmForJitExceptionHandler(JS::Realm* realm);
 
     inline void leaveRealm(JS::Realm* oldRealm);
-    inline void leaveAtomsZone(JS::Realm* oldRealm);
 
     void setHelperThread(js::HelperThread* helperThread);
     js::HelperThread* helperThread() const { return helperThread_; }
 
     bool isNurseryAllocSuppressed() const {
         return nurserySuppressions_;
     }