Bug 1233121 - Refactor ObjectBox tracing r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 18 Dec 2015 12:10:42 +0000
changeset 277003 91138dad602dd5392e3f4968443af53db5676e70
parent 276932 fbb48f4efd215160f71372122752aad6ace8441a
child 277004 dde24faeb58077458f68716aec3f30504445097b
push id16724
push usercbook@mozilla.com
push dateMon, 21 Dec 2015 11:00:52 +0000
treeherderfx-team@3f3f0361567c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1233121
milestone46.0a1
Bug 1233121 - Refactor ObjectBox tracing r=terrence
js/src/frontend/ParseNode.cpp
js/src/frontend/ParseNode.h
js/src/frontend/Parser.cpp
js/src/frontend/SharedContext.h
--- a/js/src/frontend/ParseNode.cpp
+++ b/js/src/frontend/ParseNode.cpp
@@ -1157,27 +1157,37 @@ ObjectBox::asFunctionBox()
 
 ModuleBox*
 ObjectBox::asModuleBox()
 {
     MOZ_ASSERT(isModuleBox());
     return static_cast<ModuleBox*>(this);
 }
 
+/* static */ void
+ObjectBox::TraceList(JSTracer* trc, ObjectBox* listHead)
+{
+    for (ObjectBox* box = listHead; box; box = box->traceLink)
+        box->trace(trc);
+}
+
 void
 ObjectBox::trace(JSTracer* trc)
 {
-    ObjectBox* box = this;
-    while (box) {
-        TraceRoot(trc, &box->object, "parser.object");
-        if (box->isFunctionBox()) {
-            FunctionBox* funbox = box->asFunctionBox();
-            funbox->bindings.trace(trc);
-            if (funbox->enclosingStaticScope_)
-                TraceRoot(trc, &funbox->enclosingStaticScope_, "funbox-enclosingStaticScope");
-        } else if (box->isModuleBox()) {
-            ModuleBox* modulebox = box->asModuleBox();
-            modulebox->bindings.trace(trc);
-            modulebox->exportNames.trace(trc);
-        }
-        box = box->traceLink;
-    }
+    TraceRoot(trc, &object, "parser.object");
 }
+
+void
+FunctionBox::trace(JSTracer* trc)
+{
+    ObjectBox::trace(trc);
+    bindings.trace(trc);
+    if (enclosingStaticScope_)
+        TraceRoot(trc, &enclosingStaticScope_, "funbox-enclosingStaticScope");
+}
+
+void
+ModuleBox::trace(JSTracer* trc)
+{
+    ObjectBox::trace(trc);
+    bindings.trace(trc);
+    exportNames.trace(trc);
+}
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -1708,17 +1708,19 @@ class ObjectBox
   public:
     JSObject* object;
 
     ObjectBox(JSObject* object, ObjectBox* traceLink);
     bool isFunctionBox() { return object->is<JSFunction>(); }
     FunctionBox* asFunctionBox();
     bool isModuleBox() { return object->is<ModuleObject>(); }
     ModuleBox* asModuleBox();
-    void trace(JSTracer* trc);
+    virtual void trace(JSTracer* trc);
+
+    static void TraceList(JSTracer* trc, ObjectBox* listHead);
 
   protected:
     friend struct CGObjectList;
 
     ObjectBox* traceLink;
     ObjectBox* emitLink;
 
     ObjectBox(JSFunction* function, ObjectBox* traceLink);
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -847,17 +847,17 @@ Parser<SyntaxParseHandler>::newModuleBox
     MOZ_ALWAYS_FALSE(abortIfSyntaxParser());
     return nullptr;
 }
 
 template <typename ParseHandler>
 void
 Parser<ParseHandler>::trace(JSTracer* trc)
 {
-    traceListHead->trace(trc);
+    ObjectBox::TraceList(trc, traceListHead);
 }
 
 void
 MarkParser(JSTracer* trc, AutoGCRooter* parser)
 {
     static_cast<Parser<FullParseHandler>*>(parser)->trace(trc);
 }
 
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -406,31 +406,35 @@ class FunctionBox : public ObjectBox, pu
         // Note: this should be kept in sync with JSFunction::needsCallObject().
         return bindings.hasAnyAliasedBindings() ||
                hasExtensibleScope() ||
                needsDeclEnvObject() ||
                needsHomeObject()    ||
                isDerivedClassConstructor() ||
                isGenerator();
     }
+
+    void trace(JSTracer* trc) override;
 };
 
 class ModuleBox : public ObjectBox, public SharedContext
 {
   public:
     Bindings bindings;
     TraceableVector<JSAtom*> exportNames;
 
     template <typename ParseHandler>
     ModuleBox(ExclusiveContext* cx, ObjectBox* traceListHead, ModuleObject* module,
               ParseContext<ParseHandler>* pc);
 
     ObjectBox* toObjectBox() override { return this; }
     ModuleObject* module() const { return &object->as<ModuleObject>(); }
     JSObject* staticScope() const override { return module(); }
+
+    void trace(JSTracer* trc) override;
 };
 
 inline FunctionBox*
 SharedContext::asFunctionBox()
 {
     MOZ_ASSERT(isFunctionBox());
     return static_cast<FunctionBox*>(this);
 }