Bug 1661086 - Update function guessed names when updating ObjectGroup. r=mgaudet
authorTed Campbell <tcampbell@mozilla.com>
Tue, 25 Aug 2020 19:46:18 +0000
changeset 546198 67ca0e7de7547f5765e79010e6b3754b550faa64
parent 546197 81666c6d64bf17651ddc3445e6629ca652dcbb7d
child 546199 5fd46f578846a016065f43290336bb1400f89071
push id124966
push usertcampbell@mozilla.com
push dateTue, 25 Aug 2020 20:32:21 +0000
treeherderautoland@67ca0e7de754 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1661086
milestone82.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 1661086 - Update function guessed names when updating ObjectGroup. r=mgaudet This is needed since updating the function name will soon be fallible which is not allowed in UpdateEmittedInnerFunctions. Move the name updates to the same place that ObjectGroup updates happen which suffer the same OOM issue. If an OOM occurs here during delazification, the next attempt at recompile will compute the same name. Applying the name update early is not a problem and is what the frontend previously did before stencil. Differential Revision: https://phabricator.services.mozilla.com/D88174
js/src/frontend/Stencil.cpp
--- a/js/src/frontend/Stencil.cpp
+++ b/js/src/frontend/Stencil.cpp
@@ -405,18 +405,22 @@ static bool InstantiateScopes(JSContext*
 
   return true;
 }
 
 // JSFunctions have a default ObjectGroup when they are created. Once their
 // enclosing script is compiled, we have more precise heuristic information and
 // now compute their final group. These functions have not been exposed to
 // script before this point.
-static bool SetTypeForExposedFunctions(JSContext* cx,
-                                       CompilationInfo& compilationInfo) {
+//
+// As well, anonymous functions may have either an "inferred" or a "guessed"
+// name assigned to them. This name isn't known until the enclosing function is
+// compiled so we must update it here.
+static bool SetTypeAndNameForExposedFunctions(
+    JSContext* cx, CompilationInfo& compilationInfo) {
   for (auto item : compilationInfo.functionScriptStencils()) {
     auto& stencil = item.stencil;
     auto& fun = item.function;
     if (!stencil.functionFlags.hasBaseScript()) {
       continue;
     }
 
     // If the function was not referenced by enclosing script's bytecode, we do
@@ -424,16 +428,28 @@ static bool SetTypeForExposedFunctions(J
     if (!stencil.wasFunctionEmitted && !stencil.isStandaloneFunction) {
       continue;
     }
 
     if (!JSFunction::setTypeForScriptedFunction(cx, fun,
                                                 stencil.isSingletonFunction)) {
       return false;
     }
+
+    // Inferred and Guessed names are computed by BytecodeEmitter and so may
+    // need to be applied to existing JSFunctions during delazification.
+    if (fun->displayAtom() == nullptr) {
+      if (stencil.functionFlags.hasInferredName()) {
+        fun->setInferredName(stencil.functionAtom);
+      }
+
+      if (stencil.functionFlags.hasGuessedAtom()) {
+        fun->setGuessedAtom(stencil.functionAtom);
+      }
+    }
   }
 
   return true;
 }
 
 // Instantiate js::BaseScripts from ScriptStencils for inner functions of the
 // compilation. Note that standalone functions and functions being delazified
 // are handled below with other top-levels.
@@ -536,28 +552,16 @@ static void UpdateEmittedInnerFunctions(
       script->setEnclosingScope(scope);
       script->initTreatAsRunOnce(stencil.immutableFlags.hasFlag(
           ImmutableScriptFlagsEnum::TreatAsRunOnce));
 
       if (stencil.memberInitializers) {
         script->setMemberInitializers(*stencil.memberInitializers);
       }
     }
-
-    // Inferred and Guessed names are computed by BytecodeEmitter and so may
-    // need to be applied to existing JSFunctions during delazification.
-    if (fun->displayAtom() == nullptr) {
-      if (stencil.functionFlags.hasInferredName()) {
-        fun->setInferredName(stencil.functionAtom);
-      }
-
-      if (stencil.functionFlags.hasGuessedAtom()) {
-        fun->setGuessedAtom(stencil.functionAtom);
-      }
-    }
   }
 }
 
 // During initial parse we must link lazy-functions-inside-lazy-functions to
 // their enclosing script.
 static void LinkEnclosingLazyScript(CompilationInfo& compilationInfo) {
   for (auto item : compilationInfo.functionScriptStencils()) {
     auto& stencil = item.stencil;
@@ -621,17 +625,17 @@ bool CompilationInfo::instantiateStencil
       return false;
     }
   }
 
   if (!InstantiateScopes(cx, *this)) {
     return false;
   }
 
-  if (!SetTypeForExposedFunctions(cx, *this)) {
+  if (!SetTypeAndNameForExposedFunctions(cx, *this)) {
     return false;
   }
 
   if (!InstantiateScriptStencils(cx, *this)) {
     return false;
   }
 
   if (!InstantiateTopLevel(cx, *this)) {