Bug 1466083 part 4 - Use UniquePtr instead of ScopedJSDeletePtr when allocating Zones and Realms. r=jwalden
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 02 Jun 2018 11:58:28 +0200
changeset 420977 aabf0f4dc6131c3c036a38f1f370b17b5a105d48
parent 420976 f9b5ecb14d55f6f6cf6f494dca4a9225546e94b7
child 420978 266765d448e3723e3ae4c249ad86309be760e1c7
push id34083
push userapavel@mozilla.com
push dateSat, 02 Jun 2018 23:03:25 +0000
treeherdermozilla-central@1f62ecdf59b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
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 4 - Use UniquePtr instead of ScopedJSDeletePtr when allocating Zones and Realms. r=jwalden
js/src/gc/GC.cpp
js/src/jsapi.cpp
js/src/vm/Runtime.cpp
js/src/vm/Stopwatch.cpp
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -7934,17 +7934,17 @@ AutoPrepareForTracing::AutoPrepareForTra
 }
 
 Realm*
 js::NewRealm(JSContext* cx, JSPrincipals* principals, const JS::RealmOptions& options)
 {
     JSRuntime* rt = cx->runtime();
     JS_AbortIfWrongThread(cx);
 
-    ScopedJSDeletePtr<Zone> zoneHolder;
+    UniquePtr<Zone> zoneHolder;
 
     Zone* zone = nullptr;
     JS::ZoneSpecifier zoneSpec = options.creationOptions().zoneSpecifier();
     switch (zoneSpec) {
       case JS::SystemZone:
         // systemZone might be null here, in which case we'll make a zone and
         // set this field below.
         zone = rt->gc.systemZone;
@@ -7953,39 +7953,39 @@ js::NewRealm(JSContext* cx, JSPrincipals
         zone = options.creationOptions().zone();
         MOZ_ASSERT(zone);
         break;
       case JS::NewZone:
         break;
     }
 
     if (!zone) {
-        zone = cx->new_<Zone>(cx->runtime());
-        if (!zone)
+        zoneHolder = cx->make_unique<Zone>(cx->runtime());
+        if (!zoneHolder)
             return nullptr;
 
-        zoneHolder.reset(zone);
-
         const JSPrincipals* trusted = rt->trustedPrincipals();
         bool isSystem = principals && principals == trusted;
-        if (!zone->init(isSystem)) {
+        if (!zoneHolder->init(isSystem)) {
             ReportOutOfMemory(cx);
             return nullptr;
         }
-    }
-
-    ScopedJSDeletePtr<Realm> realm(cx->new_<Realm>(zone, options));
+
+        zone = zoneHolder.get();
+    }
+
+    UniquePtr<Realm> realm = cx->make_unique<Realm>(zone, options);
     if (!realm || !realm->init(cx))
         return nullptr;
 
     // Set up the principals.
-    JS::SetRealmPrincipals(realm, principals);
+    JS::SetRealmPrincipals(realm.get(), principals);
 
     JSCompartment* comp = realm->compartment();
-    if (!comp->realms().append(realm)) {
+    if (!comp->realms().append(realm.get())) {
         ReportOutOfMemory(cx);
         return nullptr;
     }
 
     AutoLockGC lock(rt);
 
     if (!zone->compartments().append(comp)) {
         ReportOutOfMemory(cx);
@@ -8001,18 +8001,18 @@ js::NewRealm(JSContext* cx, JSPrincipals
         // Lazily set the runtime's sytem zone.
         if (zoneSpec == JS::SystemZone) {
             MOZ_RELEASE_ASSERT(!rt->gc.systemZone);
             rt->gc.systemZone = zone;
             zone->isSystem = true;
         }
     }
 
-    zoneHolder.forget();
-    return realm.forget();
+    mozilla::Unused << zoneHolder.release();
+    return realm.release();
 }
 
 void
 gc::MergeRealms(Realm* source, Realm* target)
 {
     JSRuntime* rt = source->runtimeFromMainThread();
     rt->gc.mergeRealms(source, target);
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3462,18 +3462,20 @@ JS_HoldPrincipals(JSPrincipals* principa
 {
     ++principals->refcount;
 }
 
 JS_PUBLIC_API(void)
 JS_DropPrincipals(JSContext* cx, JSPrincipals* principals)
 {
     int rc = --principals->refcount;
-    if (rc == 0)
+    if (rc == 0) {
+        JS::AutoSuppressGCAnalysis nogc;
         cx->runtime()->destroyPrincipals(principals);
+    }
 }
 
 JS_PUBLIC_API(void)
 JS_SetSecurityCallbacks(JSContext* cx, const JSSecurityCallbacks* scb)
 {
     MOZ_ASSERT(scb != &NullSecurityCallbacks);
     cx->runtime()->securityCallbacks = scb ? scb : &NullSecurityCallbacks;
 }
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -209,22 +209,21 @@ JSRuntime::init(JSContext* cx, uint32_t 
 
     defaultFreeOp_ = js_new<js::FreeOp>(this);
     if (!defaultFreeOp_)
         return false;
 
     if (!gc.init(maxbytes, maxNurseryBytes))
         return false;
 
-    ScopedJSDeletePtr<Zone> atomsZone(js_new<Zone>(this));
+    UniquePtr<Zone> atomsZone = MakeUnique<Zone>(this);
     if (!atomsZone || !atomsZone->init(true))
         return false;
 
-    gc.atomsZone = atomsZone.get();
-    atomsZone.forget();
+    gc.atomsZone = atomsZone.release();
 
     if (!symbolRegistry_.ref().init())
         return false;
 
     if (!scriptDataTable_.ref().init())
         return false;
 
     /* The garbage collector depends on everything before this point being initialized. */
--- a/js/src/vm/Stopwatch.cpp
+++ b/js/src/vm/Stopwatch.cpp
@@ -583,16 +583,17 @@ PerformanceGroup::AddRef()
 void
 PerformanceGroup::Release()
 {
     MOZ_ASSERT(refCount_ > 0);
     --refCount_;
     if (refCount_ > 0)
         return;
 
+    JS::AutoSuppressGCAnalysis nogc;
     this->Delete();
 }
 
 JS_PUBLIC_API(bool)
 SetStopwatchStartCallback(JSContext* cx, StopwatchStartCallback cb, void* closure)
 {
     cx->runtime()->performanceMonitoring().setStopwatchStartCallback(cb, closure);
     return true;