Bug 1466083 part 2 - Replace JSRuntime::numCompartments with JSRuntime::numRealms. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 02 Jun 2018 11:58:28 +0200
changeset 475193 480eb5a4c02e9408c97ff7441d89e28d5ce57492
parent 475192 4975928725165a5d5918085f951a4ef2c37f1ad0
child 475194 f9b5ecb14d55f6f6cf6f494dca4a9225546e94b7
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1466083
milestone62.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 1466083 part 2 - Replace JSRuntime::numCompartments with JSRuntime::numRealms. r=luke
js/src/proxy/CrossCompartmentWrapper.cpp
js/src/vm/JSCompartment.cpp
js/src/vm/JSCompartment.h
js/src/vm/MemoryMetrics.cpp
js/src/vm/Runtime.cpp
js/src/vm/Runtime.h
--- a/js/src/proxy/CrossCompartmentWrapper.cpp
+++ b/js/src/proxy/CrossCompartmentWrapper.cpp
@@ -673,23 +673,22 @@ js::RemapAllWrappersForObject(JSContext*
 {
     MOZ_ASSERT(!IsInsideNursery(oldTargetArg));
     MOZ_ASSERT(!IsInsideNursery(newTargetArg));
 
     RootedValue origv(cx, ObjectValue(*oldTargetArg));
     RootedObject newTarget(cx, newTargetArg);
 
     AutoWrapperVector toTransplant(cx);
-    if (!toTransplant.reserve(cx->runtime()->numCompartments))
-        return false;
 
     for (CompartmentsIter c(cx->runtime()); !c.done(); c.next()) {
         if (WrapperMap::Ptr wp = c->lookupWrapper(origv)) {
             // We found a wrapper. Remember and root it.
-            toTransplant.infallibleAppend(WrapperValue(wp));
+            if (!toTransplant.append(WrapperValue(wp)))
+                return false;
         }
     }
 
     for (const WrapperValue& v : toTransplant)
         RemapWrapper(cx, &v.toObject(), newTarget);
 
     return true;
 }
--- a/js/src/vm/JSCompartment.cpp
+++ b/js/src/vm/JSCompartment.cpp
@@ -39,19 +39,17 @@ using namespace js;
 using namespace js::gc;
 using namespace js::jit;
 
 using mozilla::PodArrayZero;
 
 JSCompartment::JSCompartment(Zone* zone)
   : zone_(zone),
     runtime_(zone->runtimeFromAnyThread())
-{
-    runtime_->numCompartments++;
-}
+{}
 
 ObjectRealm::ObjectRealm(JS::Zone* zone)
   : innerViews(zone)
 {}
 
 ObjectRealm::~ObjectRealm()
 {
     MOZ_ASSERT(enumerators == iteratorSentinel_.get());
@@ -64,36 +62,36 @@ Realm::Realm(JS::Zone* zone, const JS::R
     global_(nullptr),
     objects_(zone),
     randomKeyGenerator_(runtime_->forkRandomKeyGenerator()),
     wasm(zone->runtimeFromMainThread()),
     performanceMonitoring(runtime_)
 {
     MOZ_ASSERT_IF(creationOptions_.mergeable(),
                   creationOptions_.invisibleToDebugger());
+
+    runtime_->numRealms++;
 }
 
 Realm::~Realm()
 {
     // Write the code coverage information in a file.
     JSRuntime* rt = runtimeFromMainThread();
     if (rt->lcovOutput().isEnabled())
         rt->lcovOutput().writeLCovResult(lcovOutput);
 
 #ifdef DEBUG
     // Avoid assertion destroying the unboxed layouts list if the embedding
     // leaked GC things.
     if (!runtime_->gc.shutdownCollectedEverything())
         objectGroups_.unboxedLayouts.clear();
 #endif
-}
 
-JSCompartment::~JSCompartment()
-{
-    runtime_->numCompartments--;
+    MOZ_ASSERT(runtime_->numRealms > 0);
+    runtime_->numRealms--;
 }
 
 bool
 JSCompartment::init(JSContext* cx)
 {
     if (!crossCompartmentWrappers.init(0)) {
         ReportOutOfMemory(cx);
         return false;
--- a/js/src/vm/JSCompartment.h
+++ b/js/src/vm/JSCompartment.h
@@ -613,17 +613,16 @@ struct JSCompartment
 #endif
 
   private:
     bool getNonWrapperObjectForCurrentCompartment(JSContext* cx, js::MutableHandleObject obj);
     bool getOrCreateWrapper(JSContext* cx, js::HandleObject existing, js::MutableHandleObject obj);
 
   protected:
     explicit JSCompartment(JS::Zone* zone);
-    ~JSCompartment();
 
     MOZ_MUST_USE bool init(JSContext* cx);
 
   public:
     MOZ_MUST_USE inline bool wrap(JSContext* cx, JS::MutableHandleValue vp);
 
     MOZ_MUST_USE bool wrap(JSContext* cx, js::MutableHandleString strp);
 #ifdef ENABLE_BIGINT
--- a/js/src/vm/MemoryMetrics.cpp
+++ b/js/src/vm/MemoryMetrics.cpp
@@ -757,17 +757,17 @@ FindNotableScriptSources(JS::RuntimeSize
     return true;
 }
 
 static bool
 CollectRuntimeStatsHelper(JSContext* cx, RuntimeStats* rtStats, ObjectPrivateVisitor* opv,
                           bool anonymize, IterateCellCallback statsCellCallback)
 {
     JSRuntime* rt = cx->runtime();
-    if (!rtStats->realmStatsVector.reserve(rt->numCompartments))
+    if (!rtStats->realmStatsVector.reserve(rt->numRealms))
         return false;
 
     size_t totalZones = rt->gc.zones().length() + 1; // + 1 for the atoms zone.
     if (!rtStats->zoneStatsVector.reserve(totalZones))
         return false;
 
     rtStats->gcHeapChunkTotal =
         size_t(JS_GetGCParameter(cx, JSGC_TOTAL_CHUNKS)) * gc::ChunkSize;
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -128,17 +128,17 @@ JSRuntime::JSRuntime(JSRuntime* parentRu
 #ifdef DEBUG
     activeThreadHasExclusiveAccess(false),
 #endif
     scriptDataLock(mutexid::RuntimeScriptData),
 #ifdef DEBUG
     activeThreadHasScriptDataAccess(false),
 #endif
     numActiveHelperThreadZones(0),
-    numCompartments(0),
+    numRealms(0),
     localeCallbacks(nullptr),
     defaultLocale(nullptr),
     profilingScripts(false),
     scriptAndCountsVector(nullptr),
     lcovOutput_(),
     jitRuntime_(nullptr),
     selfHostingGlobal_(nullptr),
     gc(thisFromCtor()),
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -506,20 +506,20 @@ struct JSRuntime : public js::MallocProv
     bool currentThreadHasScriptDataAccess() const {
         if (!hasHelperThreadZones())
             return CurrentThreadCanAccessRuntime(this) && activeThreadHasScriptDataAccess;
 
         return scriptDataLock.ownedByCurrentThread();
     }
 #endif
 
-    // How many compartments there are across all zones. This number includes
-    // off thread context compartments, so it isn't necessarily equal to the
-    // number of compartments visited by CompartmentsIter.
-    js::MainThreadData<size_t> numCompartments;
+    // How many realms there are across all zones. This number includes
+    // off-thread context realms, so it isn't necessarily equal to the
+    // number of realms visited by RealmsIter.
+    js::MainThreadData<size_t> numRealms;
 
     /* Locale-specific callbacks for string conversion. */
     js::MainThreadData<const JSLocaleCallbacks*> localeCallbacks;
 
     /* Default locale for Internationalization API */
     js::MainThreadData<char*> defaultLocale;
 
     /* If true, new scripts must be created with PC counter information. */