Bug 1568245 - Replace JSScript::realm with JSScript::global. r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Mon, 23 Sep 2019 19:50:40 +0000
changeset 494590 39ce2fcdbbffad7a1d4a0154ef8c8ebcfb42aa40
parent 494589 3fc7370ce4501c545dd23343fc7bda9cd4b5cc58
child 494591 e35199501a974eb8c6582d4c5a0e87e3d4932f68
push id96103
push usertcampbell@mozilla.com
push dateMon, 23 Sep 2019 20:53:43 +0000
treeherderautoland@e35199501a97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1568245
milestone71.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 1568245 - Replace JSScript::realm with JSScript::global. r=jandem The realm can be read off the global object and we can remove one step in the mergeRealms code. Differential Revision: https://phabricator.services.mozilla.com/D40519
js/src/gc/GC.cpp
js/src/vm/JSScript-inl.h
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -7765,23 +7765,16 @@ void GCRuntime::mergeRealms(Realm* sourc
 
   // Release any relocated arenas which we may be holding on to as they might
   // be in the source zone
   releaseHeldRelocatedArenas();
 
   // Fixup realm pointers in source to refer to target, and make sure
   // type information generations are in sync.
 
-  for (auto script = source->zone()->cellIterUnsafe<JSScript>(); !script.done();
-       script.next()) {
-    MOZ_ASSERT(script->realm() == source);
-    script->realm_ = target;
-    MOZ_ASSERT(!script->hasJitScript());
-  }
-
   GlobalObject* global = target->maybeGlobal();
   MOZ_ASSERT(global);
 
   for (auto group = source->zone()->cellIterUnsafe<ObjectGroup>();
        !group.done(); group.next()) {
     // Replace placeholder object prototypes with the correct prototype in
     // the target realm.
     TaggedProto proto(group->proto());
--- a/js/src/vm/JSScript-inl.h
+++ b/js/src/vm/JSScript-inl.h
@@ -163,17 +163,17 @@ inline JSPrincipals* JSScript::principal
 inline bool JSScript::ensureHasAnalyzedArgsUsage(JSContext* cx) {
   if (analyzedArgsUsage()) {
     return true;
   }
   return js::jit::AnalyzeArgumentsUsage(cx, this);
 }
 
 inline bool JSScript::isDebuggee() const {
-  return realm_->debuggerObservesAllExecution() || hasDebugScript();
+  return realm()->debuggerObservesAllExecution() || hasDebugScript();
 }
 
 inline bool JSScript::hasBaselineScript() const {
   return hasJitScript() && jitScript()->hasBaselineScript();
 }
 
 inline bool JSScript::hasIonScript() const {
   return hasJitScript() && jitScript()->hasIonScript();
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -3801,24 +3801,24 @@ void PrivateScriptData::trace(JSTracer* 
       // due to OOM triggering the ClearEdgesTracer.
       elem = JS::GCCellPtr();
     } else if (thing != elem.asCell()) {
       elem = JS::GCCellPtr(thing, elem.kind());
     }
   }
 }
 
-JSScript::JSScript(JS::Realm* realm, uint8_t* stubEntry,
+JSScript::JSScript(HandleObject global, uint8_t* stubEntry,
                    HandleScriptSourceObject sourceObject, uint32_t sourceStart,
                    uint32_t sourceEnd, uint32_t toStringStart,
                    uint32_t toStringEnd)
     : js::BaseScript(stubEntry, sourceObject, sourceStart, sourceEnd,
                      toStringStart, toStringEnd),
-      realm_(realm) {
-  MOZ_ASSERT(JS::GetCompartmentForRealm(realm) == sourceObject->compartment());
+      global_(global) {
+  MOZ_ASSERT(global->compartment() == sourceObject->compartment());
 }
 
 /* static */
 JSScript* JSScript::New(JSContext* cx, HandleScriptSourceObject sourceObject,
                         uint32_t sourceStart, uint32_t sourceEnd,
                         uint32_t toStringStart, uint32_t toStringEnd) {
   void* script = Allocate<JSScript>(cx);
   if (!script) {
@@ -3827,17 +3827,17 @@ JSScript* JSScript::New(JSContext* cx, H
 
 #ifndef JS_CODEGEN_NONE
   uint8_t* stubEntry = cx->runtime()->jitRuntime()->interpreterStub().value;
 #else
   uint8_t* stubEntry = nullptr;
 #endif
 
   return new (script)
-      JSScript(cx->realm(), stubEntry, sourceObject, sourceStart, sourceEnd,
+      JSScript(cx->global(), stubEntry, sourceObject, sourceStart, sourceEnd,
                toStringStart, toStringEnd);
 }
 
 static bool ShouldTrackRecordReplayProgress(JSScript* script) {
   // Progress is only tracked when recording or replaying, and only for
   // scripts associated with the main thread's runtime. Whether self hosted
   // scripts execute may depend on performed Ion optimizations (for example,
   // self hosted TypedObject logic), so they are ignored.
@@ -4839,19 +4839,17 @@ void JSScript::traceChildren(JSTracer* t
   if (jit::JitScript* jitScript = maybeJitScript()) {
     jitScript->trace(trc);
   }
 
   if (maybeLazyScript()) {
     TraceManuallyBarrieredEdge(trc, &lazyScript, "lazyScript");
   }
 
-  JSObject* global = realm()->unsafeUnbarrieredMaybeGlobal();
-  MOZ_ASSERT(global);
-  TraceManuallyBarrieredEdge(trc, &global, "script_global");
+  TraceEdge(trc, &global_, "global");
 
   if (trc->isMarkingTracer()) {
     GCMarker::fromTracer(trc)->markImplicitEdges(this);
   }
 }
 
 void LazyScript::finalize(JSFreeOp* fop) {
   if (lazyData_) {
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -2330,17 +2330,17 @@ class JSScript : public js::BaseScript {
  private:
   // Shareable script data
   RefPtr<js::RuntimeScriptData> scriptData_ = {};
 
   // Unshared variable-length data
   js::PrivateScriptData* data_ = nullptr;
 
  public:
-  JS::Realm* realm_ = nullptr;
+  js::GCPtrObject global_ = {};
 
  private:
   // JIT and type inference data for this script. May be purged on GC.
   js::jit::JitScript* jitScript_ = nullptr;
 
   /* Information used to re-lazify a lazily-parsed interpreted function. */
   js::LazyScript* lazyScript = nullptr;
 
@@ -2396,17 +2396,17 @@ class JSScript : public js::BaseScript {
       js::frontend::BytecodeEmitter* bce);
 
   friend JSScript* js::detail::CopyScript(
       JSContext* cx, js::HandleScript src,
       js::HandleScriptSourceObject sourceObject,
       js::MutableHandle<JS::GCVector<js::Scope*>> scopes);
 
  private:
-  JSScript(JS::Realm* realm, uint8_t* stubEntry,
+  JSScript(js::HandleObject global, uint8_t* stubEntry,
            js::HandleScriptSourceObject sourceObject, uint32_t sourceStart,
            uint32_t sourceEnd, uint32_t toStringStart, uint32_t toStringend);
 
   static JSScript* New(JSContext* cx, js::HandleScriptSourceObject sourceObject,
                        uint32_t sourceStart, uint32_t sourceEnd,
                        uint32_t toStringStart, uint32_t toStringEnd);
 
  public:
@@ -2439,21 +2439,19 @@ class JSScript : public js::BaseScript {
   void assertValidJumpTargets() const;
 
  public:
 #endif
 
  public:
   inline JSPrincipals* principals();
 
-  JS::Compartment* compartment() const {
-    return JS::GetCompartmentForRealm(realm_);
-  }
+  JS::Realm* realm() const { return global_->nonCCWRealm(); }
+  JS::Compartment* compartment() const { return global_->compartment(); }
   JS::Compartment* maybeCompartment() const { return compartment(); }
-  JS::Realm* realm() const { return realm_; }
 
   js::RuntimeScriptData* scriptData() { return scriptData_; }
   js::ImmutableScriptData* immutableScriptData() const {
     return scriptData_->isd_.get();
   }
 
   // Script bytecode is immutable after creation.
   jsbytecode* code() const {