From 8223953e6660f551573ca3ed78f491c07b74286e Mon Sep 17 00:00:00 2001 From: Oana Pop Rus Date: Wed, 6 Nov 2019 19:45:33 +0200 Subject: [PATCH] Backed out changeset 8719c4f31ad8 (bug 1580338) for spidermonkey in TraceKind.h on a CLOSED TREE --- js/src/builtin/ReflectParse.cpp | 2 +- js/src/frontend/BytecodeEmitter.cpp | 3 +- js/src/frontend/BytecodeSection.cpp | 9 ------ js/src/frontend/BytecodeSection.h | 15 +--------- js/src/frontend/FullParseHandler.h | 4 --- js/src/frontend/ParseNode.cpp | 14 --------- js/src/frontend/ParseNode.h | 43 ++-------------------------- js/src/frontend/Parser.cpp | 30 ------------------- js/src/jit-test/tests/oomDeferred.js | 22 -------------- js/src/vm/RegExpObject.cpp | 20 ------------- js/src/vm/RegExpObject.h | 13 --------- 11 files changed, 7 insertions(+), 168 deletions(-) delete mode 100644 js/src/jit-test/tests/oomDeferred.js diff --git a/js/src/builtin/ReflectParse.cpp b/js/src/builtin/ReflectParse.cpp index 8046ddca4267..88f0aa6c1d2a 100644 --- a/js/src/builtin/ReflectParse.cpp +++ b/js/src/builtin/ReflectParse.cpp @@ -3167,7 +3167,7 @@ bool ASTSerializer::literal(ParseNode* pn, MutableHandleValue dst) { break; case ParseNodeKind::RegExpExpr: { - RootedObject re1(cx, pn->as().getOrCreate(cx)); + RootedObject re1(cx, pn->as().objbox()->object()); LOCAL_ASSERT(re1 && re1->is()); RootedObject re2(cx, CloneRegExpObject(cx, re1.as())); diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 2b646b69bc4d..438936312c37 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -9851,8 +9851,9 @@ bool BytecodeEmitter::emitTree( break; case ParseNodeKind::RegExpExpr: { + ObjectBox* obj = pn->as().objbox(); uint32_t index; - if (!perScriptData().gcThingList().append(&pn->as(), &index)) { + if (!perScriptData().gcThingList().append(obj, &index)) { return false; } if (!emitRegExp(index)) { diff --git a/js/src/frontend/BytecodeSection.cpp b/js/src/frontend/BytecodeSection.cpp index 2baafef60578..eb5ca720bb53 100644 --- a/js/src/frontend/BytecodeSection.cpp +++ b/js/src/frontend/BytecodeSection.cpp @@ -72,15 +72,6 @@ bool GCThingList::finish(JSContext* cx, mozilla::Span array) { array[i] = JS::GCCellPtr(obj); return true; } - - bool operator()(RegExpCreationData& data) { - RegExpObject* regexp = data.createRegExp(cx); - if (!regexp) { - return false; - } - array[i] = JS::GCCellPtr(regexp); - return true; - } }; for (uint32_t i = 0; i < length(); i++) { diff --git a/js/src/frontend/BytecodeSection.h b/js/src/frontend/BytecodeSection.h index 6930edbbe6fd..1da52bf8479e 100644 --- a/js/src/frontend/BytecodeSection.h +++ b/js/src/frontend/BytecodeSection.h @@ -45,7 +45,7 @@ class ObjectBox; struct MOZ_STACK_CLASS GCThingList { using ListType = mozilla::Variant; + ObjLiteralCreationData>; JS::RootedVector vector; // Last emitted object. @@ -79,15 +79,6 @@ struct MOZ_STACK_CLASS GCThingList { *index = vector.length(); return vector.append(mozilla::AsVariant(std::move(objlit))); } - MOZ_MUST_USE bool append(RegExpLiteral* literal, uint32_t* index) { - *index = vector.length(); - if (literal->isDeferred()) { - return vector.append( - mozilla::AsVariant(std::move(literal->creationData()))); - } - return vector.append(mozilla::AsVariant( - StackGCCellPtr(JS::GCCellPtr(literal->objbox()->object())))); - } MOZ_MUST_USE bool append(ObjectBox* obj, uint32_t* index); uint32_t length() const { return vector.length(); } @@ -395,10 +386,6 @@ namespace JS { template <> struct GCPolicy : JS::IgnoreGCPolicy {}; - -template <> -struct GCPolicy - : JS::IgnoreGCPolicy {}; } // namespace JS #endif /* frontend_BytecodeSection_h */ diff --git a/js/src/frontend/FullParseHandler.h b/js/src/frontend/FullParseHandler.h index db12a8fa84c4..e8ba4eb6c88d 100644 --- a/js/src/frontend/FullParseHandler.h +++ b/js/src/frontend/FullParseHandler.h @@ -221,10 +221,6 @@ class FullParseHandler { return new_(objbox, pos); } - RegExpLiteralType newRegExp(const TokenPos& pos) { - return new_(pos); - } - ConditionalExpressionType newConditional(Node cond, Node thenExpr, Node elseExpr) { return new_(cond, thenExpr, elseExpr); diff --git a/js/src/frontend/ParseNode.cpp b/js/src/frontend/ParseNode.cpp index cea2e6b3f7f8..e2b80e4695dc 100644 --- a/js/src/frontend/ParseNode.cpp +++ b/js/src/frontend/ParseNode.cpp @@ -12,7 +12,6 @@ #include "jsnum.h" #include "frontend/Parser.h" -#include "vm/RegExpObject.h" #include "vm/JSContext-inl.h" @@ -408,19 +407,6 @@ bool BigIntLiteral::isZero() { BigInt* BigIntLiteral::value() { return box()->value(); } -RegExpObject* RegExpCreationData::createRegExp(JSContext* cx) const { - MOZ_ASSERT(buf_); - return RegExpObject::createSyntaxChecked(cx, buf_.get(), length_, flags_, - TenuredObject); -} - -RegExpObject* RegExpLiteral::getOrCreate(JSContext* cx) const { - if (data_.is()) { - return &objbox()->object()->as(); - } - return data_.as().createRegExp(cx); -} - FunctionBox* ObjectBox::asFunctionBox() { MOZ_ASSERT(isFunctionBox()); diff --git a/js/src/frontend/ParseNode.h b/js/src/frontend/ParseNode.h index e4e8251258d4..e26d3f03da51 100644 --- a/js/src/frontend/ParseNode.h +++ b/js/src/frontend/ParseNode.h @@ -1893,49 +1893,14 @@ class BooleanLiteral : public NullaryNode { } }; -// This owns a set of characters, previously syntax checked as a RegExp. Used -// to avoid allocating the RegExp on the GC heap during parsing. -class RegExpCreationData { - UniquePtr buf_; - size_t length_ = 0; - JS::RegExpFlags flags_; - - public: - RegExpCreationData() = default; - - MOZ_MUST_USE bool init(JSContext* cx, mozilla::Range range, - JS::RegExpFlags flags) { - length_ = range.length(); - buf_ = js::DuplicateString(cx, range.begin().get(), range.length()); - if (!buf_) { - return false; - } - flags_ = flags; - return true; - } - - RegExpObject* createRegExp(JSContext* cx) const; -}; - class RegExpLiteral : public ParseNode { - mozilla::Variant data_; + ObjectBox* objbox_; public: RegExpLiteral(ObjectBox* reobj, const TokenPos& pos) - : ParseNode(ParseNodeKind::RegExpExpr, pos), data_(reobj) {} + : ParseNode(ParseNodeKind::RegExpExpr, pos), objbox_(reobj) {} - explicit RegExpLiteral(const TokenPos& pos) - : ParseNode(ParseNodeKind::RegExpExpr, pos), data_(mozilla::Nothing()) {} - - void init(RegExpCreationData data) { - data_ = mozilla::AsVariant(std::move(data)); - } - - bool isDeferred() const { return data_.is(); } - - ObjectBox* objbox() const { return data_.as(); } - - RegExpObject* getOrCreate(JSContext* cx) const; + ObjectBox* objbox() const { return objbox_; } #ifdef DEBUG void dumpImpl(GenericPrinter& out, int indent); @@ -1951,8 +1916,6 @@ class RegExpLiteral : public ParseNode { bool accept(Visitor& visitor) { return true; } - - RegExpCreationData& creationData() { return data_.as(); } }; class PropertyAccess : public BinaryNode { diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 043516c8c0d3..0fb6264f50b7 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -9629,38 +9629,8 @@ RegExpLiteral* Parser::newRegExp() { // Create the regexp and check its syntax. const auto& chars = tokenStream.getCharBuffer(); - mozilla::Range range(chars.begin(), chars.length()); RegExpFlags flags = anyChars.currentToken().regExpFlags(); - if (this->getTreeHolder().isDeferred()) { - { - LifoAllocScope allocScope(&cx_->tempLifoAlloc()); - // Verify that the Regexp will syntax parse when the time comes to - // instantiate it. - if (!irregexp::ParsePatternSyntax(anyChars, allocScope.alloc(), range, - flags.unicode())) { - return nullptr; - } - } - - // With RegExpCreationData stack allocated, it is responsible for cleanup - // until the data is moved into, after the potentially OOMing operations - // are done, at which point the responsibility for cleanup becomes the - // deferred allocation list, stored in the ParseInfo. - RegExpCreationData data; - if (!data.init(cx_, range, flags)) { - return nullptr; - } - - RegExpLiteral* node = handler_.newRegExp(pos()); - if (!node) { - return nullptr; - } - - node->init(std::move(data)); - return node; - } - Rooted reobj(cx_); reobj = RegExpObject::create(cx_, chars.begin(), chars.length(), flags, anyChars, TenuredObject); diff --git a/js/src/jit-test/tests/oomDeferred.js b/js/src/jit-test/tests/oomDeferred.js deleted file mode 100644 index 5c67eda40fbc..000000000000 --- a/js/src/jit-test/tests/oomDeferred.js +++ /dev/null @@ -1,22 +0,0 @@ -// |jit-test| --no-ion; skip-if: !('oomTest' in this) - -// Ion is too slow executing this test, hence the --no-ion above - -var test = () => { - var ng = newGlobal({deferredParserAlloc: true}); - - function foo() { - var x = /hi/; - var y = 128n; - function inner(a, b) { - return a + b; - } - var a = inner(y, y); - return x.exec(a.toString()); - } - - ng.evaluate(foo.toString()); - ng.evaluate('foo()'); -}; -test(); -oomTest(test); diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index ddae5e80f35b..64848d0f63f9 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -249,26 +249,6 @@ RegExpObject* RegExpObject::create(JSContext* cx, HandleAtom source, return nullptr; } - return createSyntaxChecked(cx, source, flags, newKind); -} - -RegExpObject* RegExpObject::createSyntaxChecked(JSContext* cx, - const char16_t* chars, - size_t length, - RegExpFlags flags, - NewObjectKind newKind) { - RootedAtom source(cx, AtomizeChars(cx, chars, length)); - if (!source) { - return nullptr; - } - - return createSyntaxChecked(cx, source, flags, newKind); -} - -RegExpObject* RegExpObject::createSyntaxChecked(JSContext* cx, - HandleAtom source, - RegExpFlags flags, - NewObjectKind newKind) { Rooted regexp(cx, RegExpAlloc(cx, newKind)); if (!regexp) { return nullptr; diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h index a74fb596cd0d..7f0eed408683 100644 --- a/js/src/vm/RegExpObject.h +++ b/js/src/vm/RegExpObject.h @@ -65,9 +65,6 @@ class RegExpObject : public NativeObject { static_assert(RegExpObject::FLAGS_SLOT == REGEXP_FLAGS_SLOT, "FLAGS_SLOT values should be in sync with self-hosted JS"); - static RegExpObject* create(JSContext* cx, HandleAtom source, - NewObjectKind newKind); - public: static const unsigned RESERVED_SLOTS = 3; static const unsigned PRIVATE_SLOT = 3; @@ -83,16 +80,6 @@ class RegExpObject : public NativeObject { static RegExpObject* create(JSContext* cx, const CharT* chars, size_t length, JS::RegExpFlags flags, NewObjectKind newKind); - // This variant assumes that the characters have already previously been - // syntax checked. - static RegExpObject* createSyntaxChecked(JSContext* cx, const char16_t* chars, - size_t length, JS::RegExpFlags flags, - NewObjectKind newKind); - - static RegExpObject* createSyntaxChecked(JSContext* cx, HandleAtom source, - JS::RegExpFlags flags, - NewObjectKind newKind); - template static RegExpObject* create(JSContext* cx, const CharT* chars, size_t length, JS::RegExpFlags flags,