Bug 1508063 - Part 1: Move BinASTParserBase into its own files. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Thu, 29 Nov 2018 01:03:45 +0900
changeset 504947 2abc868cd4169ab888b5a5e7d7ebd5687b06232d
parent 504946 141af7d07a50aa91d40d993020cfe2703450cf23
child 504948 391d7669e9b28c4475ead6f5f6771dfa1fd05deb
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1508063
milestone65.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 1508063 - Part 1: Move BinASTParserBase into its own files. r=Yoric
js/src/frontend/BinASTParserBase.cpp
js/src/frontend/BinASTParserBase.h
js/src/frontend/BinSource.cpp
js/src/frontend/BinSource.h
js/src/frontend/moz.build
new file mode 100644
--- /dev/null
+++ b/js/src/frontend/BinASTParserBase.cpp
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "frontend/BinASTParserBase.h"
+
+#include "vm/JSContext-inl.h"
+
+namespace js {
+namespace frontend {
+
+using UsedNamePtr = UsedNameTracker::UsedNameMap::Ptr;
+
+BinASTParserBase::BinASTParserBase(JSContext* cx, LifoAlloc& alloc, UsedNameTracker& usedNames,
+                                   HandleScriptSourceObject sourceObject,
+                                   Handle<LazyScript*> lazyScript)
+  : AutoGCRooter(cx, AutoGCRooter::Tag::BinParser)
+  , cx_(cx)
+  , alloc_(alloc)
+  , traceListHead_(nullptr)
+  , usedNames_(usedNames)
+  , nodeAlloc_(cx, alloc)
+  , keepAtoms_(cx)
+  , sourceObject_(cx, sourceObject)
+  , lazyScript_(cx, lazyScript)
+  , parseContext_(nullptr)
+  , factory_(cx, alloc, nullptr, SourceKind::Binary)
+{
+    MOZ_ASSERT_IF(lazyScript, lazyScript->isBinAST());
+    cx->frontendCollectionPool().addActiveCompilation();
+    tempPoolMark_ = alloc.mark();
+}
+
+BinASTParserBase::~BinASTParserBase()
+{
+    alloc_.release(tempPoolMark_);
+
+    /*
+     * The parser can allocate enormous amounts of memory for large functions.
+     * Eagerly free the memory now (which otherwise won't be freed until the
+     * next GC) to avoid unnecessary OOMs.
+     */
+    alloc_.freeAllIfHugeAndUnused();
+
+    cx_->frontendCollectionPool().removeActiveCompilation();
+}
+
+bool
+BinASTParserBase::hasUsedName(HandlePropertyName name)
+{
+    if (UsedNamePtr p = usedNames_.lookup(name)) {
+        return p->value().isUsedInScript(parseContext_->scriptId());
+    }
+
+    return false;
+}
+
+} // namespace frontend
+} // namespace js
new file mode 100644
--- /dev/null
+++ b/js/src/frontend/BinASTParserBase.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef frontend_BinASTParserBase_h
+#define frontend_BinASTParserBase_h
+
+#include <stddef.h>
+
+#include "ds/LifoAlloc.h"
+#include "frontend/BinTokenReaderMultipart.h"
+#include "frontend/BinTokenReaderTester.h"
+#include "frontend/FullParseHandler.h"
+#include "frontend/ParseContext.h"
+#include "frontend/ParseNode.h"
+#include "frontend/SharedContext.h"
+#include "js/RootingAPI.h"
+#include "js/TracingAPI.h"
+#include "js/Utility.h"
+#include "vm/JSContext.h"
+#include "vm/JSScript.h"
+
+namespace js {
+namespace frontend {
+
+class BinASTParserBase : private JS::AutoGCRooter
+{
+  public:
+    BinASTParserBase(JSContext* cx, LifoAlloc& alloc, UsedNameTracker& usedNames,
+                     HandleScriptSourceObject sourceObject, Handle<LazyScript*> lazyScript);
+    ~BinASTParserBase();
+
+  public:
+    // Names
+
+    bool hasUsedName(HandlePropertyName name);
+
+    // --- GC.
+
+    virtual void doTrace(JSTracer* trc) {}
+
+    void trace(JSTracer* trc) {
+        TraceListNode::TraceList(trc, traceListHead_);
+        doTrace(trc);
+    }
+
+
+  public:
+    ParseNode* allocParseNode(size_t size) {
+        MOZ_ASSERT(size == sizeof(ParseNode));
+        return static_cast<ParseNode*>(nodeAlloc_.allocNode());
+    }
+
+    JS_DECLARE_NEW_METHODS(new_, allocParseNode, inline)
+
+    // Needs access to AutoGCRooter.
+    friend void TraceBinParser(JSTracer* trc, JS::AutoGCRooter* parser);
+
+  protected:
+    JSContext* cx_;
+
+    // ---- Memory-related stuff
+  protected:
+    LifoAlloc& alloc_;
+    TraceListNode* traceListHead_;
+    UsedNameTracker& usedNames_;
+  private:
+    LifoAlloc::Mark tempPoolMark_;
+    ParseNodeAllocator nodeAlloc_;
+
+    // ---- Parsing-related stuff
+  protected:
+    // Root atoms and objects allocated for the parse tree.
+    AutoKeepAtoms keepAtoms_;
+
+    RootedScriptSourceObject sourceObject_;
+    Rooted<LazyScript*> lazyScript_;
+    ParseContext* parseContext_;
+    FullParseHandler factory_;
+
+    friend class BinParseContext;
+};
+
+} // namespace frontend
+} // namespace js
+
+#endif // frontend_BinASTParserBase_h
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -72,49 +72,16 @@
 //
 // They should be treated lazily (whenever we open a subscope), like bindings.
 
 namespace js {
 namespace frontend {
 
 using UsedNamePtr = UsedNameTracker::UsedNameMap::Ptr;
 
-BinASTParserBase::BinASTParserBase(JSContext* cx, LifoAlloc& alloc, UsedNameTracker& usedNames,
-                                   HandleScriptSourceObject sourceObject, Handle<LazyScript*> lazyScript)
-  : AutoGCRooter(cx, AutoGCRooter::Tag::BinParser)
-  , cx_(cx)
-  , alloc_(alloc)
-  , traceListHead_(nullptr)
-  , usedNames_(usedNames)
-  , nodeAlloc_(cx, alloc)
-  , keepAtoms_(cx)
-  , sourceObject_(cx, sourceObject)
-  , lazyScript_(cx, lazyScript)
-  , parseContext_(nullptr)
-  , factory_(cx, alloc, nullptr, SourceKind::Binary)
-{
-    MOZ_ASSERT_IF(lazyScript, lazyScript->isBinAST());
-    cx->frontendCollectionPool().addActiveCompilation();
-    tempPoolMark_ = alloc.mark();
-}
-
-BinASTParserBase::~BinASTParserBase()
-{
-    alloc_.release(tempPoolMark_);
-
-    /*
-     * The parser can allocate enormous amounts of memory for large functions.
-     * Eagerly free the memory now (which otherwise won't be freed until the
-     * next GC) to avoid unnecessary OOMs.
-     */
-    alloc_.freeAllIfHugeAndUnused();
-
-    cx_->frontendCollectionPool().removeActiveCompilation();
-}
-
 // ------------- Toplevel constructions
 
 template<typename Tok> JS::Result<ParseNode*>
 BinASTParser<Tok>::parse(GlobalSharedContext* globalsc, const Vector<uint8_t>& data,
                          BinASTSourceMetadata** metadataPtr)
 {
     return parse(globalsc, data.begin(), data.length(), metadataPtr);
 }
@@ -796,26 +763,16 @@ BinASTParser<Tok>::reportExtraWarningErr
     if (options().werrorOption) {
         ReportCompileError(cx_, std::move(metadata), std::move(notes), JSREPORT_STRICT, errorNumber, *args);
         return false;
     }
 
     return ReportCompileWarning(cx_, std::move(metadata), std::move(notes), JSREPORT_STRICT | JSREPORT_WARNING, errorNumber, *args);
 }
 
-bool
-BinASTParserBase::hasUsedName(HandlePropertyName name)
-{
-    if (UsedNamePtr p = usedNames_.lookup(name)) {
-        return p->value().isUsedInScript(parseContext_->scriptId());
-    }
-
-    return false;
-}
-
 void
 TraceBinParser(JSTracer* trc, JS::AutoGCRooter* parser)
 {
     static_cast<BinASTParserBase*>(parser)->trace(trc);
 }
 
 template<typename Tok>
 void
--- a/js/src/frontend/BinSource.h
+++ b/js/src/frontend/BinSource.h
@@ -12,91 +12,33 @@
  *
  * At the time of this writing, this parser implements the grammar of ES5
  * and trusts its input (in particular, variable declarations).
  */
 
 #include "mozilla/Maybe.h"
 
 #include "frontend/BCEParserHandle.h"
+#include "frontend/BinASTParserBase.h"
 #include "frontend/BinToken.h"
 #include "frontend/BinTokenReaderMultipart.h"
 #include "frontend/BinTokenReaderTester.h"
 #include "frontend/FullParseHandler.h"
 #include "frontend/ParseContext.h"
 #include "frontend/ParseNode.h"
 #include "frontend/SharedContext.h"
 
 #include "js/CompileOptions.h"
 #include "js/GCHashTable.h"
 #include "js/GCVector.h"
 #include "js/Result.h"
 
 namespace js {
 namespace frontend {
 
-class BinASTParserBase: private JS::AutoGCRooter
-{
-  public:
-    BinASTParserBase(JSContext* cx, LifoAlloc& alloc, UsedNameTracker& usedNames,
-                     HandleScriptSourceObject sourceObject, Handle<LazyScript*> lazyScript);
-    ~BinASTParserBase();
-
-  public:
-    // Names
-
-
-    bool hasUsedName(HandlePropertyName name);
-
-    // --- GC.
-
-    virtual void doTrace(JSTracer* trc) {}
-
-    void trace(JSTracer* trc) {
-        TraceListNode::TraceList(trc, traceListHead_);
-        doTrace(trc);
-    }
-
-
-  public:
-    ParseNode* allocParseNode(size_t size) {
-        MOZ_ASSERT(size == sizeof(ParseNode));
-        return static_cast<ParseNode*>(nodeAlloc_.allocNode());
-    }
-
-    JS_DECLARE_NEW_METHODS(new_, allocParseNode, inline)
-
-    // Needs access to AutoGCRooter.
-    friend void TraceBinParser(JSTracer* trc, JS::AutoGCRooter* parser);
-
-  protected:
-    JSContext* cx_;
-
-    // ---- Memory-related stuff
-  protected:
-    LifoAlloc& alloc_;
-    TraceListNode* traceListHead_;
-    UsedNameTracker& usedNames_;
-  private:
-    LifoAlloc::Mark tempPoolMark_;
-    ParseNodeAllocator nodeAlloc_;
-
-    // ---- Parsing-related stuff
-  protected:
-    // Root atoms and objects allocated for the parse tree.
-    AutoKeepAtoms keepAtoms_;
-
-    RootedScriptSourceObject sourceObject_;
-    Rooted<LazyScript*> lazyScript_;
-    ParseContext* parseContext_;
-    FullParseHandler factory_;
-
-    friend class BinParseContext;
-};
-
 /**
  * The parser for a Binary AST.
  *
  * By design, this parser never needs to backtrack or look ahead. Errors are not
  * recoverable.
  */
 template<typename Tok>
 class BinASTParser : public BinASTParserBase, public ErrorReporter, public BCEParserHandle
--- a/js/src/frontend/moz.build
+++ b/js/src/frontend/moz.build
@@ -62,25 +62,27 @@ SOURCES += [
 
 if CONFIG['JS_BUILD_BINAST']:
     # Using SOURCES, as UNIFIED_SOURCES causes mysterious bugs on 32-bit platforms.
     # These parts of BinAST are designed only to test evolutions of the
     # specification.
     SOURCES += ['BinTokenReaderTester.cpp']
     # These parts of BinAST should eventually move to release.
     SOURCES += [
+        'BinASTParserBase.cpp',
         'BinSource-auto.cpp',
         'BinSource.cpp',
         'BinSourceRuntimeSupport.cpp',
         'BinToken.cpp',
         'BinTokenReaderBase.cpp',
         'BinTokenReaderMultipart.cpp',
     ]
 
     # Instrument BinAST files for fuzzing as we have a fuzzing target for BinAST.
     if CONFIG['FUZZING_INTERFACES'] and CONFIG['LIBFUZZER']:
         include('/tools/fuzzing/libfuzzer-flags.mozbuild')
 
+        SOURCES['BinASTParserBase.cpp'].flags += libfuzzer_flags
         SOURCES['BinSource-auto.cpp'].flags += libfuzzer_flags
         SOURCES['BinSource.cpp'].flags += libfuzzer_flags
         SOURCES['BinToken.cpp'].flags += libfuzzer_flags
         SOURCES['BinTokenReaderBase.cpp'].flags += libfuzzer_flags
         SOURCES['BinTokenReaderMultipart.cpp'].flags += libfuzzer_flags