Commit 921c2476 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[zone] Cleanup zone allocations in src/regexp and tests

... by migrating old-style code
  MyObject* obj = new (zone) MyObject(...)

to the new style
  MyObject* obj = zone->New<MyObject>(...)

Bug: v8:10689
Change-Id: Icc60fdbf247ec05f9b5688b3d2d73d4fed06ea89
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2289770
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68784}
parent 3647f758
......@@ -106,7 +106,7 @@ class CharacterRange {
static inline ZoneList<CharacterRange>* List(Zone* zone,
CharacterRange range) {
ZoneList<CharacterRange>* list =
new (zone) ZoneList<CharacterRange>(1, zone);
zone->New<ZoneList<CharacterRange>>(1, zone);
list->Add(range, zone);
return list;
}
......
......@@ -166,6 +166,10 @@ class BytecodeSequenceNode {
Zone* zone_;
};
// These definitions are here in order to please the linker, which in debug mode
// sometimes requires static constants to be defined in .cc files.
constexpr int BytecodeSequenceNode::kDummyBytecode;
class RegExpBytecodePeephole {
public:
RegExpBytecodePeephole(Zone* zone, size_t buffer_size,
......@@ -281,12 +285,9 @@ BytecodeSequenceNode::BytecodeSequenceNode(int bytecode, Zone* zone)
start_offset_(0),
parent_(nullptr),
children_(ZoneUnorderedMap<int, BytecodeSequenceNode*>(zone)),
argument_mapping_(new (zone->New(sizeof(*argument_mapping_)))
ZoneVector<BytecodeArgumentMapping>(zone)),
argument_check_(new (zone->New(sizeof(*argument_check_)))
ZoneLinkedList<BytecodeArgumentCheck>(zone)),
argument_ignored_(new (zone->New(sizeof(*argument_ignored_)))
ZoneLinkedList<BytecodeArgument>(zone)),
argument_mapping_(zone->New<ZoneVector<BytecodeArgumentMapping>>(zone)),
argument_check_(zone->New<ZoneLinkedList<BytecodeArgumentCheck>>(zone)),
argument_ignored_(zone->New<ZoneLinkedList<BytecodeArgument>>(zone)),
zone_(zone) {}
BytecodeSequenceNode& BytecodeSequenceNode::FollowedBy(int bytecode) {
......@@ -294,8 +295,7 @@ BytecodeSequenceNode& BytecodeSequenceNode::FollowedBy(int bytecode) {
if (children_.find(bytecode) == children_.end()) {
BytecodeSequenceNode* new_node =
new (zone()->New(sizeof(BytecodeSequenceNode)))
BytecodeSequenceNode(bytecode, zone());
zone()->New<BytecodeSequenceNode>(bytecode, zone());
// If node is not the first in the sequence, set offsets and parent.
if (bytecode_ != kDummyBytecode) {
new_node->start_offset_ = start_offset_ + RegExpBytecodeLength(bytecode_);
......@@ -478,7 +478,7 @@ RegExpBytecodePeephole::RegExpBytecodePeephole(
Zone* zone, size_t buffer_size,
const ZoneUnorderedMap<int, int>& jump_edges)
: optimized_bytecode_buffer_(zone),
sequences_(new (zone->New(sizeof(*sequences_))) BytecodeSequenceNode(
sequences_(zone->New<BytecodeSequenceNode>(
BytecodeSequenceNode::kDummyBytecode, zone)),
jump_edges_(zone),
jump_edges_mapped_(zone),
......
This diff is collapsed.
This diff is collapsed.
......@@ -377,6 +377,7 @@ class ActionNode : public SeqRegExpNode {
: SeqRegExpNode(on_success), action_type_(action_type) {}
ActionType action_type_;
friend class DotPrinterImpl;
friend Zone;
};
class TextNode : public SeqRegExpNode {
......@@ -387,7 +388,7 @@ class TextNode : public SeqRegExpNode {
TextNode(RegExpCharacterClass* that, bool read_backward,
RegExpNode* on_success)
: SeqRegExpNode(on_success),
elms_(new (zone()) ZoneList<TextElement>(1, zone())),
elms_(zone()->New<ZoneList<TextElement>>(1, zone())),
read_backward_(read_backward) {
elms_->Add(TextElement::CharClass(that), zone());
}
......@@ -449,19 +450,19 @@ class AssertionNode : public SeqRegExpNode {
AFTER_NEWLINE
};
static AssertionNode* AtEnd(RegExpNode* on_success) {
return new (on_success->zone()) AssertionNode(AT_END, on_success);
return on_success->zone()->New<AssertionNode>(AT_END, on_success);
}
static AssertionNode* AtStart(RegExpNode* on_success) {
return new (on_success->zone()) AssertionNode(AT_START, on_success);
return on_success->zone()->New<AssertionNode>(AT_START, on_success);
}
static AssertionNode* AtBoundary(RegExpNode* on_success) {
return new (on_success->zone()) AssertionNode(AT_BOUNDARY, on_success);
return on_success->zone()->New<AssertionNode>(AT_BOUNDARY, on_success);
}
static AssertionNode* AtNonBoundary(RegExpNode* on_success) {
return new (on_success->zone()) AssertionNode(AT_NON_BOUNDARY, on_success);
return on_success->zone()->New<AssertionNode>(AT_NON_BOUNDARY, on_success);
}
static AssertionNode* AfterNewline(RegExpNode* on_success) {
return new (on_success->zone()) AssertionNode(AFTER_NEWLINE, on_success);
return on_success->zone()->New<AssertionNode>(AFTER_NEWLINE, on_success);
}
void Accept(NodeVisitor* visitor) override;
void Emit(RegExpCompiler* compiler, Trace* trace) override;
......@@ -473,6 +474,8 @@ class AssertionNode : public SeqRegExpNode {
AssertionType assertion_type() { return assertion_type_; }
private:
friend Zone;
void EmitBoundaryCheck(RegExpCompiler* compiler, Trace* trace);
enum IfPrevious { kIsNonWord, kIsWord };
void BacktrackIfPrevious(RegExpCompiler* compiler, Trace* trace,
......@@ -586,8 +589,8 @@ class ChoiceNode : public RegExpNode {
public:
explicit ChoiceNode(int expected_size, Zone* zone)
: RegExpNode(zone),
alternatives_(new (zone)
ZoneList<GuardedAlternative>(expected_size, zone)),
alternatives_(
zone->New<ZoneList<GuardedAlternative>>(expected_size, zone)),
not_at_start_(false),
being_calculated_(false) {}
void Accept(NodeVisitor* visitor) override;
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ class BufferedZoneList {
void Add(T* value, Zone* zone) {
if (last_ != nullptr) {
if (list_ == nullptr) {
list_ = new (zone) ZoneList<T*>(initial_size, zone);
list_ = zone->New<ZoneList<T*>>(initial_size, zone);
}
list_->Add(last_, zone);
}
......@@ -82,7 +82,7 @@ class BufferedZoneList {
ZoneList<T*>* GetList(Zone* zone) {
if (list_ == nullptr) {
list_ = new (zone) ZoneList<T*>(initial_size, zone);
list_ = zone->New<ZoneList<T*>>(initial_size, zone);
}
if (last_ != nullptr) {
list_->Add(last_, zone);
......@@ -250,7 +250,7 @@ class V8_EXPORT_PRIVATE RegExpParser {
const ZoneVector<uc16>* capture_name,
JSRegExp::Flags flags, Zone* zone)
: previous_state_(previous_state),
builder_(new (zone) RegExpBuilder(zone, flags)),
builder_(zone->New<RegExpBuilder>(zone, flags)),
group_type_(group_type),
lookaround_type_(lookaround_type),
disjunction_capture_index_(disjunction_capture_index),
......
......@@ -508,7 +508,7 @@ static bool NotWord(uc16 c) {
static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* ranges =
new(&zone) ZoneList<CharacterRange>(2, &zone);
zone.New<ZoneList<CharacterRange>>(2, &zone);
CharacterRange::AddClassEscape(c, ranges, &zone);
for (uc32 i = 0; i < (1 << 16); i++) {
bool in_class = false;
......@@ -1415,7 +1415,7 @@ static void TestRangeCaseIndependence(Isolate* isolate, CharacterRange input,
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
int count = expected.length();
ZoneList<CharacterRange>* list =
new(&zone) ZoneList<CharacterRange>(count, &zone);
zone.New<ZoneList<CharacterRange>>(count, &zone);
list->Add(input, &zone);
CharacterRange::AddCaseEquivalents(isolate, &zone, list, false);
list->Remove(0); // Remove the input before checking results.
......@@ -1486,8 +1486,7 @@ static bool InClass(uc32 c,
TEST(UnicodeRangeSplitter) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* base =
new(&zone) ZoneList<CharacterRange>(1, &zone);
ZoneList<CharacterRange>* base = zone.New<ZoneList<CharacterRange>>(1, &zone);
base->Add(CharacterRange::Everything(), &zone);
UnicodeRangeSplitter splitter(base);
// BMP
......@@ -1530,8 +1529,7 @@ TEST(UnicodeRangeSplitter) {
TEST(CanonicalizeCharacterSets) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* list =
new(&zone) ZoneList<CharacterRange>(4, &zone);
ZoneList<CharacterRange>* list = zone.New<ZoneList<CharacterRange>>(4, &zone);
CharacterSet set(list);
list->Add(CharacterRange::Range(10, 20), &zone);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment