Bug 1588861 - Part 1: Store index into gcThings instead of RootedFunction for FunctionDeclarations inside modules. r=iain draft
authorcaroline <cullen.caroline@gmail.com>
Tue, 10 Dec 2019 02:54:03 +0000
changeset 2526014 9da2ce10c89caa723451f98681641d03f3968e21
parent 2525322 86afe431ec559c111ae1c1f94e4ede25776e9c50
child 2526015 2b8be80b21557986a0ed111565710120ea573d10
push id462910
push userreviewbot
push dateTue, 10 Dec 2019 02:54:32 +0000
treeherdertry@cd552cff989e [default view] [failures only]
reviewersiain
bugs1588861
milestone73.0a1
Bug 1588861 - Part 1: Store index into gcThings instead of RootedFunction for FunctionDeclarations inside modules. r=iain Differential Revision: https://phabricator.services.mozilla.com/D53754 Differential Diff: PHID-DIFF-ecd7yq7k4no5bsbzttyg
js/src/builtin/ModuleObject.cpp
js/src/builtin/ModuleObject.h
js/src/frontend/FunctionEmitter.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -686,22 +686,21 @@ void ModuleNamespaceObject::ProxyHandler
   if (self.hasBindings()) {
     fop->delete_(proxy, &self.bindings(), MemoryUse::ModuleBindingMap);
   }
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // FunctionDeclaration
 
-FunctionDeclaration::FunctionDeclaration(HandleAtom name, HandleFunction fun)
-    : name(name), fun(fun) {}
+FunctionDeclaration::FunctionDeclaration(HandleAtom name, uint32_t funIndex)
+    : name(name), funIndex(funIndex) {}
 
 void FunctionDeclaration::trace(JSTracer* trc) {
   TraceEdge(trc, &name, "FunctionDeclaration name");
-  TraceEdge(trc, &fun, "FunctionDeclaration fun");
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // ModuleObject
 
 /* static */ const JSClassOps ModuleObject::classOps_ = {
     nullptr, /* addProperty */
     nullptr, /* delProperty */
@@ -990,19 +989,19 @@ void ModuleObject::trace(JSTracer* trc, 
   }
 
   if (FunctionDeclarationVector* funDecls = module.functionDeclarations()) {
     funDecls->trace(trc);
   }
 }
 
 bool ModuleObject::noteFunctionDeclaration(JSContext* cx, HandleAtom name,
-                                           HandleFunction fun) {
+                                           uint32_t funIndex) {
   FunctionDeclarationVector* funDecls = functionDeclarations();
-  if (!funDecls->emplaceBack(name, fun)) {
+  if (!funDecls->emplaceBack(name, funIndex)) {
     ReportOutOfMemory(cx);
     return false;
   }
 
   return true;
 }
 
 /* static */
@@ -1019,22 +1018,22 @@ bool ModuleObject::instantiateFunctionDe
   FunctionDeclarationVector* funDecls = self->functionDeclarations();
   if (!funDecls) {
     JS_ReportErrorASCII(
         cx, "Module function declarations have already been instantiated");
     return false;
   }
 
   RootedModuleEnvironmentObject env(cx, &self->initialEnvironment());
-  RootedFunction fun(cx);
   RootedObject obj(cx);
   RootedValue value(cx);
-
+  RootedFunction fun(cx);
   for (const auto& funDecl : *funDecls) {
-    fun = funDecl.fun;
+    uint32_t funIndex = funDecl.funIndex;
+    fun.set(self->script()->getFunction(funIndex));
     obj = Lambda(cx, fun, env);
     if (!obj) {
       return false;
     }
 
     value = ObjectValue(*obj);
     if (!SetProperty(cx, env, funDecl.name->asPropertyName(), value)) {
       return false;
--- a/js/src/builtin/ModuleObject.h
+++ b/js/src/builtin/ModuleObject.h
@@ -204,21 +204,21 @@ class ModuleNamespaceObject : public Pro
  public:
   static const ProxyHandler proxyHandler;
 };
 
 typedef Rooted<ModuleNamespaceObject*> RootedModuleNamespaceObject;
 typedef Handle<ModuleNamespaceObject*> HandleModuleNamespaceObject;
 
 struct FunctionDeclaration {
-  FunctionDeclaration(HandleAtom name, HandleFunction fun);
+  FunctionDeclaration(HandleAtom name, uint32_t funIndex);
   void trace(JSTracer* trc);
 
   const HeapPtr<JSAtom*> name;
-  const HeapPtr<JSFunction*> fun;
+  const uint32_t funIndex;
 };
 
 // A vector of function bindings to be instantiated. This can be created in a
 // helper thread zone and so can't use ZoneAllocPolicy.
 using FunctionDeclarationVector =
     GCVector<FunctionDeclaration, 0, SystemAllocPolicy>;
 
 // Possible values for ModuleStatus are defined in SelfHostingDefines.h.
@@ -299,17 +299,17 @@ class ModuleObject : public NativeObject
 
   static ModuleNamespaceObject* GetOrCreateModuleNamespace(
       JSContext* cx, HandleModuleObject self);
 
   void setMetaObject(JSObject* obj);
 
   // For BytecodeEmitter.
   bool noteFunctionDeclaration(JSContext* cx, HandleAtom name,
-                               HandleFunction fun);
+                               uint32_t funIndex);
 
   // For intrinsic_InstantiateModuleFunctionDeclarations.
   static bool instantiateFunctionDeclarations(JSContext* cx,
                                               HandleModuleObject self);
 
   // For intrinsic_ExecuteModule.
   static bool execute(JSContext* cx, HandleModuleObject self,
                       MutableHandleValue rval);
--- a/js/src/frontend/FunctionEmitter.cpp
+++ b/js/src/frontend/FunctionEmitter.cpp
@@ -328,17 +328,17 @@ bool FunctionEmitter::emitTopLevelFuncti
   //                [stack]
 
   if (bce_->sc->isModuleContext()) {
     // For modules, we record the function and instantiate the binding
     // during ModuleInstantiate(), before the script is run.
 
     JS::Rooted<ModuleObject*> module(bce_->cx,
                                      bce_->sc->asModuleContext()->module());
-    if (!module->noteFunctionDeclaration(bce_->cx, name_, fun_)) {
+    if (!module->noteFunctionDeclaration(bce_->cx, name_, index)) {
       return false;
     }
     return true;
   }
 
   MOZ_ASSERT(bce_->sc->isGlobalContext() || bce_->sc->isEvalContext());
   MOZ_ASSERT(syntaxKind_ == FunctionSyntaxKind::Statement);
   MOZ_ASSERT(bce_->inPrologue());