Bug 1723715 part 3 - Move RegExpStaticsObject to GlobalObjectData. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 09 Aug 2021 15:25:05 +0000
changeset 588234 1bcb3ef4165f4ae739248ac05b3fbc91d85520a5
parent 588233 d163b4821d8008641c8cd84c515e649b91ba900d
child 588235 ed50c6a66971df2b8aac9efd200e02b4abc0780f
push id147723
push userjdemooij@mozilla.com
push dateMon, 09 Aug 2021 15:36:39 +0000
treeherderautoland@5fbcd90b2e8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1723715
milestone92.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 1723715 part 3 - Move RegExpStaticsObject to GlobalObjectData. r=jonco RegExpStaticsObject just stores the RegExpStatics. It might be possible to store the RegExpStatics directly in the GlobalObjectData in a follow-up bug. Depends on D121982 Differential Revision: https://phabricator.services.mozilla.com/D121983
js/public/Class.h
js/src/vm/GlobalObject.cpp
js/src/vm/GlobalObject.h
--- a/js/public/Class.h
+++ b/js/public/Class.h
@@ -567,17 +567,17 @@ static const uint32_t JSCLASS_FOREGROUND
 // with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was
 // previously allowed, but is now an ES5 violation and thus unsupported.
 //
 // JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at
 // the beginning of every global object's slots for use by the
 // application.
 static const uint32_t JSCLASS_GLOBAL_APPLICATION_SLOTS = 5;
 static const uint32_t JSCLASS_GLOBAL_SLOT_COUNT =
-    JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 29;
+    JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 28;
 
 static constexpr uint32_t JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(uint32_t n) {
   return JSCLASS_IS_GLOBAL |
          JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + n);
 }
 
 static constexpr uint32_t JSCLASS_GLOBAL_FLAGS =
     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0);
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -896,28 +896,23 @@ JSObject* GlobalObject::getOrCreateRealm
   global->setReservedSlot(REALM_KEY_OBJECT, ObjectValue(*key));
   return key;
 }
 
 /* static */
 RegExpStatics* GlobalObject::getRegExpStatics(JSContext* cx,
                                               Handle<GlobalObject*> global) {
   MOZ_ASSERT(cx);
-  RegExpStaticsObject* resObj = nullptr;
-  const Value& val = global->getReservedSlot(REGEXP_STATICS);
-  if (!val.isObject()) {
-    MOZ_ASSERT(val.isUndefined());
+  RegExpStaticsObject* resObj = global->data().regExpStatics;
+  if (!resObj) {
     resObj = RegExpStatics::create(cx);
     if (!resObj) {
       return nullptr;
     }
-
-    global->initReservedSlot(REGEXP_STATICS, ObjectValue(*resObj));
-  } else {
-    resObj = &val.toObject().as<RegExpStaticsObject>();
+    global->data().regExpStatics.init(resObj);
   }
   return resObj->regExpStatics();
 }
 
 /* static */
 NativeObject* GlobalObject::getIntrinsicsHolder(JSContext* cx,
                                                 Handle<GlobalObject*> global) {
   Value slot = global->getReservedSlot(INTRINSICS);
@@ -1139,9 +1134,10 @@ JSObject* GlobalObject::createAsyncItera
 void GlobalObject::releaseData(JSFreeOp* fop) {
   GlobalObjectData* data = maybeData();
   setReservedSlot(GLOBAL_DATA_SLOT, PrivateValue(nullptr));
   fop->delete_(this, data, MemoryUse::GlobalObjectData);
 }
 
 void GlobalObjectData::trace(JSTracer* trc) {
   TraceEdge(trc, &emptyGlobalScope, "global-empty-scope");
+  TraceNullableEdge(trc, &regExpStatics, "global-regexp-statics");
 }
--- a/js/src/vm/GlobalObject.h
+++ b/js/src/vm/GlobalObject.h
@@ -48,31 +48,35 @@ class JS_PUBLIC_API RealmOptions;
 };
 
 namespace js {
 
 class GlobalScope;
 class GlobalLexicalEnvironmentObject;
 class PlainObject;
 class RegExpStatics;
+class RegExpStaticsObject;
 
 // Data attached to a GlobalObject. This is freed when clearing the Realm's
 // global_ only because this way we don't need to add a finalizer to all
 // GlobalObject JSClasses.
 class GlobalObjectData {
   friend class js::GlobalObject;
 
   GlobalObjectData(const GlobalObjectData&) = delete;
   void operator=(const GlobalObjectData&) = delete;
 
  public:
   GlobalObjectData() = default;
 
   HeapPtr<GlobalScope*> emptyGlobalScope;
 
+  // Global state for regular expressions.
+  HeapPtr<RegExpStaticsObject*> regExpStatics;
+
   void trace(JSTracer* trc);
 };
 
 /*
  * Global object slots are reserved as follows:
  *
  * [0, APPLICATION_SLOTS)
  *   Pre-reserved slots in all global objects set aside for the embedding's
@@ -128,17 +132,16 @@ class GlobalObject : public NativeObject
     WRAP_FOR_VALID_ITERATOR_PROTO,
     ITERATOR_HELPER_PROTO,
     ASYNC_ITERATOR_HELPER_PROTO,
     MODULE_PROTO,
     IMPORT_ENTRY_PROTO,
     EXPORT_ENTRY_PROTO,
     REQUESTED_MODULE_PROTO,
     MODULE_REQUEST_PROTO,
-    REGEXP_STATICS,
     INTRINSICS,
     FOR_OF_PIC_CHAIN,
     WINDOW_PROXY,
     GLOBAL_THIS_RESOLVED,
     SOURCE_URLS,
     REALM_KEY_OBJECT,
     ARRAY_SHAPE,