Bug 1720619 - Part 1: Make instantiation parameters more specific. r=tcampbell
authorTooru Fujisawa <arai_a@mac.com>
Mon, 18 Oct 2021 17:08:05 +0000
changeset 596227 ee26b692fa602ff512d0dd2a9a66bfff320b78de
parent 596226 ad9449ed493ecc944d5d0291de23bf5e707788b0
child 596228 a9b5bd39f725a3cf70e42c3d959d20e9a0eb787d
push id151686
push userarai_a@mac.com
push dateMon, 18 Oct 2021 17:10:42 +0000
treeherderautoland@a9b5bd39f725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1720619
milestone95.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 1720619 - Part 1: Make instantiation parameters more specific. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D120200
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/CompilationStencil.h
js/src/frontend/Stencil.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -405,17 +405,17 @@ bool frontend::InstantiateStencils(JSCon
 }
 
 bool frontend::PrepareForInstantiate(JSContext* cx, CompilationInput& input,
                                      const CompilationStencil& stencil,
                                      CompilationGCOutput& gcOutput) {
   AutoGeckoProfilerEntry pseudoFrame(cx, "stencil instantiate",
                                      JS::ProfilingCategoryPair::JS_Parsing);
 
-  return CompilationStencil::prepareForInstantiate(cx, input, stencil,
+  return CompilationStencil::prepareForInstantiate(cx, input.atomCache, stencil,
                                                    gcOutput);
 }
 
 template <typename Unit>
 static JSScript* CompileGlobalScriptImpl(
     JSContext* cx, const JS::ReadOnlyCompileOptions& options,
     JS::SourceText<Unit>& srcBuf, ScopeKind scopeKind) {
   Rooted<CompilationInput> input(cx, CompilationInput(options));
--- a/js/src/frontend/CompilationStencil.h
+++ b/js/src/frontend/CompilationStencil.h
@@ -743,18 +743,18 @@ struct CompilationStencil {
 
   bool isInitialStencil() const { return functionKey == NullFunctionKey; }
 
   [[nodiscard]] static bool instantiateStencilAfterPreparation(
       JSContext* cx, CompilationInput& input, const CompilationStencil& stencil,
       CompilationGCOutput& gcOutput);
 
   [[nodiscard]] static bool prepareForInstantiate(
-      JSContext* cx, CompilationInput& input, const CompilationStencil& stencil,
-      CompilationGCOutput& gcOutput);
+      JSContext* cx, CompilationAtomCache& atomCache,
+      const CompilationStencil& stencil, CompilationGCOutput& gcOutput);
 
   [[nodiscard]] static bool instantiateStencils(
       JSContext* cx, CompilationInput& input, const CompilationStencil& stencil,
       CompilationGCOutput& gcOutput);
 
   // Decode the special self-hosted stencil
   [[nodiscard]] bool instantiateSelfHostedForRuntime(
       JSContext* cx, CompilationAtomCache& atomCache) const;
--- a/js/src/frontend/Stencil.cpp
+++ b/js/src/frontend/Stencil.cpp
@@ -1101,20 +1101,19 @@ static JSFunction* CreateFunction(JSCont
   return fun;
 }
 
 static bool InstantiateAtoms(JSContext* cx, CompilationAtomCache& atomCache,
                              const CompilationStencil& stencil) {
   return InstantiateMarkedAtoms(cx, stencil.parserAtomData, atomCache);
 }
 
-static bool InstantiateScriptSourceObject(JSContext* cx,
-                                          CompilationInput& input,
-                                          const CompilationStencil& stencil,
-                                          CompilationGCOutput& gcOutput) {
+static bool InstantiateScriptSourceObject(
+    JSContext* cx, const JS::ReadOnlyCompileOptions& options,
+    const CompilationStencil& stencil, CompilationGCOutput& gcOutput) {
   MOZ_ASSERT(stencil.source);
 
   gcOutput.sourceObject = ScriptSourceObject::create(cx, stencil.source.get());
   if (!gcOutput.sourceObject) {
     return false;
   }
 
   // Off-thread compilations do all their GC heap allocation, including the
@@ -1123,17 +1122,17 @@ static bool InstantiateScriptSourceObjec
   // wrappers from the temporary compartment to the real compartment --- which
   // would then be inappropriate once we merged the temporary and real
   // compartments.
   //
   // Instead, we put off populating those SSO slots in off-thread compilations
   // until after we've merged compartments.
   if (!cx->isHelperThreadContext()) {
     Rooted<ScriptSourceObject*> sourceObject(cx, gcOutput.sourceObject);
-    if (!ScriptSourceObject::initFromOptions(cx, sourceObject, input.options)) {
+    if (!ScriptSourceObject::initFromOptions(cx, sourceObject, options)) {
       return false;
     }
   }
 
   return true;
 }
 
 // Instantiate ModuleObject. Further initialization is done after the associated
@@ -1532,57 +1531,59 @@ static void FunctionsFromExistingLazy(Co
   }
 }
 
 /* static */
 bool CompilationStencil::instantiateStencils(JSContext* cx,
                                              CompilationInput& input,
                                              const CompilationStencil& stencil,
                                              CompilationGCOutput& gcOutput) {
-  if (!prepareForInstantiate(cx, input, stencil, gcOutput)) {
+  if (!prepareForInstantiate(cx, input.atomCache, stencil, gcOutput)) {
     return false;
   }
 
   return instantiateStencilAfterPreparation(cx, input, stencil, gcOutput);
 }
 
 /* static */
 bool CompilationStencil::instantiateStencilAfterPreparation(
     JSContext* cx, CompilationInput& input, const CompilationStencil& stencil,
     CompilationGCOutput& gcOutput) {
   // Distinguish between the initial (possibly lazy) compile and any subsequent
   // delazification compiles. Delazification will update existing GC things.
   bool isInitialParse = stencil.isInitialStencil();
   MOZ_ASSERT(stencil.isInitialStencil() == input.isInitialStencil());
 
+  CompilationAtomCache& atomCache = input.atomCache;
+
   // Phase 1: Instantiate JSAtom/JSStrings.
-  if (!InstantiateAtoms(cx, input.atomCache, stencil)) {
+  if (!InstantiateAtoms(cx, atomCache, stencil)) {
     return false;
   }
 
   // Phase 2: Instantiate ScriptSourceObject, ModuleObject, JSFunctions.
   if (isInitialParse) {
-    if (!InstantiateScriptSourceObject(cx, input, stencil, gcOutput)) {
+    if (!InstantiateScriptSourceObject(cx, input.options, stencil, gcOutput)) {
       return false;
     }
 
     if (stencil.moduleMetadata) {
       // The enclosing script of a module is always the global scope. Fetch the
       // scope of the current global and update input data.
       MOZ_ASSERT(input.enclosingScope == nullptr);
       input.enclosingScope = &cx->global()->emptyGlobalScope();
       MOZ_ASSERT(input.enclosingScope->environmentChainLength() ==
                  ModuleScope::EnclosingEnvironmentChainLength);
 
-      if (!InstantiateModuleObject(cx, input.atomCache, stencil, gcOutput)) {
+      if (!InstantiateModuleObject(cx, atomCache, stencil, gcOutput)) {
         return false;
       }
     }
 
-    if (!InstantiateFunctions(cx, input.atomCache, stencil, gcOutput)) {
+    if (!InstantiateFunctions(cx, atomCache, stencil, gcOutput)) {
       return false;
     }
   } else {
     MOZ_ASSERT(
         stencil.scriptData[CompilationStencil::TopLevelIndex].isFunction());
 
     // FunctionKey is used when caching to map a delazification stencil to a
     // specific lazy script. It is not used by instantiation, but we should
@@ -1600,31 +1601,31 @@ bool CompilationStencil::instantiateSten
 
   // Phase 3: Instantiate js::Scopes.
   if (!InstantiateScopes(cx, input, stencil, gcOutput)) {
     return false;
   }
 
   // Phase 4: Instantiate (inner) BaseScripts.
   if (isInitialParse) {
-    if (!InstantiateScriptStencils(cx, input.atomCache, stencil, gcOutput)) {
+    if (!InstantiateScriptStencils(cx, atomCache, stencil, gcOutput)) {
       return false;
     }
   }
 
   // Phase 5: Finish top-level handling
   if (!InstantiateTopLevel(cx, input, stencil, gcOutput)) {
     return false;
   }
 
   // !! Must be infallible from here forward !!
 
   // Phase 6: Update lazy scripts.
   if (stencil.canLazilyParse) {
-    UpdateEmittedInnerFunctions(cx, input.atomCache, stencil, gcOutput);
+    UpdateEmittedInnerFunctions(cx, atomCache, stencil, gcOutput);
 
     if (isInitialParse) {
       LinkEnclosingLazyScript(stencil, gcOutput);
     }
   }
 
   return true;
 }
@@ -1820,25 +1821,25 @@ bool CompilationStencil::delazifySelfHos
   // Phase 6: Update lazy scripts.
   //  NOTE: Self-hosting is always fully parsed so there is nothing to do here.
 
   return true;
 }
 
 /* static */
 bool CompilationStencil::prepareForInstantiate(
-    JSContext* cx, CompilationInput& input, const CompilationStencil& stencil,
-    CompilationGCOutput& gcOutput) {
+    JSContext* cx, CompilationAtomCache& atomCache,
+    const CompilationStencil& stencil, CompilationGCOutput& gcOutput) {
   // Reserve the `gcOutput` vectors.
   if (!gcOutput.ensureReserved(cx, stencil.scriptData.size(),
                                stencil.scopeData.size())) {
     return false;
   }
 
-  return input.atomCache.allocate(cx, stencil.parserAtomData.size());
+  return atomCache.allocate(cx, stencil.parserAtomData.size());
 }
 
 bool CompilationStencil::serializeStencils(JSContext* cx,
                                            CompilationInput& input,
                                            JS::TranscodeBuffer& buf,
                                            bool* succeededOut) const {
   if (succeededOut) {
     *succeededOut = false;