Bug 1535994 - Part 9: Move atomIndices to PerScriptData class. r=jorendorff
☠☠ backed out by 7fb3acf38591 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Wed, 10 Apr 2019 08:27:36 +0000
changeset 468766 fdd1177e499a08b4cde3e80992e288e5ee8084d5
parent 468765 db520471b4073f6ca3a9f671d522987f1298fa50
child 468767 e56d1810fb40cb7f3e312a55ebdfcd88bb4ef7b9
push id112755
push userdvarga@mozilla.com
push dateWed, 10 Apr 2019 22:06:41 +0000
treeherdermozilla-inbound@606f85641d0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1535994
milestone68.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 1535994 - Part 9: Move atomIndices to PerScriptData class. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D25739
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
js/src/vm/JSScript.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -94,32 +94,37 @@ static bool ParseNodeRequiresSpecialLine
 BytecodeEmitter::BytecodeSection::BytecodeSection(JSContext* cx)
     : code_(cx),
       notes_(cx),
       tryNoteList_(cx),
       scopeNoteList_(cx),
       resumeOffsetList_(cx) {}
 
 BytecodeEmitter::PerScriptData::PerScriptData(JSContext* cx)
-    : scopeList_(cx), numberList_(cx) {}
+    : scopeList_(cx),
+      numberList_(cx),
+      atomIndices_(cx->frontendCollectionPool()) {}
+
+bool BytecodeEmitter::PerScriptData::init(JSContext* cx) {
+  return atomIndices_.acquire(cx);
+}
 
 BytecodeEmitter::BytecodeEmitter(
     BytecodeEmitter* parent, SharedContext* sc, HandleScript script,
     Handle<LazyScript*> lazyScript, uint32_t lineNum, EmitterMode emitterMode,
     FieldInitializers fieldInitializers /* = FieldInitializers::Invalid() */)
     : sc(sc),
       cx(sc->cx_),
       parent(parent),
       script(cx, script),
       lazyScript(cx, lazyScript),
       bytecodeSection_(cx),
       perScriptData_(cx),
       currentLine_(lineNum),
       fieldInitializers_(fieldInitializers),
-      atomIndices(cx->frontendCollectionPool()),
       firstLine(lineNum),
       emitterMode(emitterMode) {
   MOZ_ASSERT_IF(emitterMode == LazyFunction, lazyScript);
 
   if (sc->isFunctionBox()) {
     // Functions have IC entries for type monitoring |this| and arguments.
     numICEntries = sc->asFunctionBox()->function()->nargs() + 1;
   }
@@ -148,17 +153,17 @@ BytecodeEmitter::BytecodeEmitter(Bytecod
   this->parser = ep_.ptr();
 }
 
 void BytecodeEmitter::initFromBodyPosition(TokenPos bodyPosition) {
   setScriptStartOffsetIfUnset(bodyPosition.begin);
   setFunctionBodyEndPos(bodyPosition.end);
 }
 
-bool BytecodeEmitter::init() { return atomIndices.acquire(cx); }
+bool BytecodeEmitter::init() { return perScriptData_.init(cx); }
 
 template <typename T>
 T* BytecodeEmitter::findInnermostNestableControl() const {
   return NestableControl::findNearest<T>(innermostNestableControl);
 }
 
 template <typename T, typename Predicate /* (T*) -> bool */>
 T* BytecodeEmitter::findInnermostNestableControl(Predicate predicate) const {
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -251,42 +251,52 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
 
  private:
   // Data that is not directly associated with specific opcode/index inside
   // bytecode, but referred from bytecode is stored in this class.
   class PerScriptData {
    public:
     explicit PerScriptData(JSContext* cx);
 
+    MOZ_MUST_USE bool init(JSContext* cx);
+
     // ---- Scope ----
 
     CGScopeList& scopeList() { return scopeList_; }
     const CGScopeList& scopeList() const { return scopeList_; }
 
     // ---- Literals ----
 
     CGNumberList& numberList() { return numberList_; }
     const CGNumberList& numberList() const { return numberList_; }
 
     CGObjectList& objectList() { return objectList_; }
     const CGObjectList& objectList() const { return objectList_; }
 
+    PooledMapPtr<AtomIndexMap>& atomIndices() { return atomIndices_; }
+    const PooledMapPtr<AtomIndexMap>& atomIndices() const {
+      return atomIndices_;
+    }
+
    private:
     // ---- Scope ----
 
     // List of emitted scopes.
     CGScopeList scopeList_;
 
     // ---- Literals ----
 
     // List of double and bigint values used by script.
     CGNumberList numberList_;
 
     // List of emitted objects.
     CGObjectList objectList_;
+
+    // Map from atom to index.
+    PooledMapPtr<AtomIndexMap> atomIndices_;
   };
 
   PerScriptData perScriptData_;
 
  public:
   PerScriptData& perScriptData() { return perScriptData_; }
   const PerScriptData& perScriptData() const { return perScriptData_; }
 
@@ -315,17 +325,16 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
   const FieldInitializers fieldInitializers_;
 
  public:
   // Private storage for parser wrapper. DO NOT REFERENCE INTERNALLY. May not be
   // initialized. Use |parser| instead.
   mozilla::Maybe<EitherParser> ep_ = {};
   BCEParserHandle* parser = nullptr;
 
-  PooledMapPtr<AtomIndexMap> atomIndices; /* literals indexed for mapping */
   unsigned firstLine = 0; /* first line, for JSScript::initFromEmitter */
 
   uint32_t maxFixedSlots = 0; /* maximum number of fixed frame slots so far */
 
   uint32_t bodyScopeIndex =
       UINT32_MAX; /* index into scopeList of the body scope */
 
   EmitterScope* varEmitterScope = nullptr;
@@ -504,25 +513,25 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
   Scope* innermostScope() const;
   Scope* bodyScope() const {
     MOZ_ASSERT(bodyScopeIndex < perScriptData().scopeList().length());
     return perScriptData().scopeList().vector[bodyScopeIndex];
   }
 
   MOZ_ALWAYS_INLINE
   MOZ_MUST_USE bool makeAtomIndex(JSAtom* atom, uint32_t* indexp) {
-    MOZ_ASSERT(atomIndices);
-    AtomIndexMap::AddPtr p = atomIndices->lookupForAdd(atom);
+    MOZ_ASSERT(perScriptData().atomIndices());
+    AtomIndexMap::AddPtr p = perScriptData().atomIndices()->lookupForAdd(atom);
     if (p) {
       *indexp = p->value();
       return true;
     }
 
-    uint32_t index = atomIndices->count();
-    if (!atomIndices->add(p, atom, index)) {
+    uint32_t index = perScriptData().atomIndices()->count();
+    if (!perScriptData().atomIndices()->add(p, atom, index)) {
       ReportOutOfMemory(cx);
       return false;
     }
 
     *indexp = index;
     return true;
   }
 
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -3560,17 +3560,17 @@ bool JSScript::fullyInitFromEmitter(JSCo
 
   // If initialization fails, we must call JSScript::freeScriptData in order to
   // neuter the script. Various things that iterate raw scripts in a GC arena
   // use the presense of this data to detect if initialization is complete.
   auto scriptDataGuard =
       mozilla::MakeScopeExit([&] { script->freeScriptData(); });
 
   /* The counts of indexed things must be checked during code generation. */
-  MOZ_ASSERT(bce->atomIndices->count() <= INDEX_LIMIT);
+  MOZ_ASSERT(bce->perScriptData().atomIndices()->count() <= INDEX_LIMIT);
   MOZ_ASSERT(bce->perScriptData().objectList().length <= INDEX_LIMIT);
 
   uint64_t nslots =
       bce->maxFixedSlots +
       static_cast<uint64_t>(bce->bytecodeSection().maxStackDepth());
   if (nslots > UINT32_MAX) {
     bce->reportError(nullptr, JSMSG_NEED_DIET, js_script_str);
     return false;
@@ -4518,34 +4518,34 @@ bool JSScript::hasBreakpointsAt(jsbyteco
     return false;
   }
 
   return site->enabledCount > 0;
 }
 
 /* static */ bool SharedScriptData::InitFromEmitter(
     JSContext* cx, js::HandleScript script, frontend::BytecodeEmitter* bce) {
-  uint32_t natoms = bce->atomIndices->count();
+  uint32_t natoms = bce->perScriptData().atomIndices()->count();
   uint32_t codeLength = bce->bytecodeSection().code().length();
 
   // The + 1 is to account for the final SN_MAKE_TERMINATOR that is appended
   // when the notes are copied to their final destination by copySrcNotes.
   uint32_t noteLength = bce->bytecodeSection().notes().length() + 1;
 
   // Create and initialize SharedScriptData
   if (!script->createSharedScriptData(cx, codeLength, noteLength, natoms)) {
     return false;
   }
 
   js::SharedScriptData* data = script->scriptData_;
 
   // Initialize trailing arrays
   std::copy_n(bce->bytecodeSection().code().begin(), codeLength, data->code());
   bce->copySrcNotes(data->notes(), noteLength);
-  InitAtomMap(*bce->atomIndices, data->atoms());
+  InitAtomMap(*bce->perScriptData().atomIndices(), data->atoms());
 
   return true;
 }
 
 void SharedScriptData::traceChildren(JSTracer* trc) {
   MOZ_ASSERT(refCount() != 0);
   for (uint32_t i = 0; i < natoms(); ++i) {
     TraceNullableEdge(trc, &atoms()[i], "atom");