Commit 5b44c169 authored by Iain Ireland's avatar Iain Ireland Committed by Commit Bot

[regexp] Use ZoneVector in parser and compiler

For a variety of reasons related to OOM handling and custom
allocators, SpiderMonkey wants to be able to see all memory
allocations. To enforce this, we have a static analysis that verifies
that we don't link in malloc/new/etc in unexpected places. One
consequence of this is that we can't use STL containers without a
custom allocator, because they call operator new internally.

This is mostly not an issue in irregexp, which makes heavy use of zone
allocation. The main exceptions are a handful of uses of std::vector
in regexp-compiler.* and regexp-parser.*. If these vectors are
converted to ZoneVectors, then our static analysis is satisfied.

R=jgruber@chromium.org

Bug: v8:10303
Change-Id: I8b14a2eb54d3b20959e3fbe878f77effae124a2c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2091402Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66674}
parent 9b5141ca
...@@ -252,7 +252,7 @@ RegExpCompiler::CompilationResult RegExpCompiler::Assemble( ...@@ -252,7 +252,7 @@ RegExpCompiler::CompilationResult RegExpCompiler::Assemble(
#endif #endif
macro_assembler_ = macro_assembler; macro_assembler_ = macro_assembler;
std::vector<RegExpNode*> work_list; ZoneVector<RegExpNode*> work_list(zone());
work_list_ = &work_list; work_list_ = &work_list;
Label fail; Label fail;
macro_assembler_->PushBacktrack(&fail); macro_assembler_->PushBacktrack(&fail);
......
...@@ -576,7 +576,7 @@ class RegExpCompiler { ...@@ -576,7 +576,7 @@ class RegExpCompiler {
int next_register_; int next_register_;
int unicode_lookaround_stack_register_; int unicode_lookaround_stack_register_;
int unicode_lookaround_position_register_; int unicode_lookaround_position_register_;
std::vector<RegExpNode*>* work_list_; ZoneVector<RegExpNode*>* work_list_;
int recursion_depth_; int recursion_depth_;
RegExpMacroAssembler* macro_assembler_; RegExpMacroAssembler* macro_assembler_;
bool one_byte_; bool one_byte_;
......
...@@ -347,7 +347,8 @@ RegExpTree* RegExpParser::ParseDisjunction() { ...@@ -347,7 +347,8 @@ RegExpTree* RegExpParser::ParseDisjunction() {
if (unicode()) { if (unicode()) {
ZoneList<CharacterRange>* ranges = ZoneList<CharacterRange>* ranges =
new (zone()) ZoneList<CharacterRange>(2, zone()); new (zone()) ZoneList<CharacterRange>(2, zone());
std::vector<char> name_1, name_2; ZoneVector<char> name_1(zone());
ZoneVector<char> name_2(zone());
if (ParsePropertyClassName(&name_1, &name_2)) { if (ParsePropertyClassName(&name_1, &name_2)) {
if (AddPropertyClassRange(ranges, p == 'P', name_1, name_2)) { if (AddPropertyClassRange(ranges, p == 'P', name_1, name_2)) {
RegExpCharacterClass* cc = new (zone()) RegExpCharacterClass* cc = new (zone())
...@@ -1385,8 +1386,8 @@ bool IsUnicodePropertyValueCharacter(char c) { ...@@ -1385,8 +1386,8 @@ bool IsUnicodePropertyValueCharacter(char c) {
} // anonymous namespace } // anonymous namespace
bool RegExpParser::ParsePropertyClassName(std::vector<char>* name_1, bool RegExpParser::ParsePropertyClassName(ZoneVector<char>* name_1,
std::vector<char>* name_2) { ZoneVector<char>* name_2) {
DCHECK(name_1->empty()); DCHECK(name_1->empty());
DCHECK(name_2->empty()); DCHECK(name_2->empty());
// Parse the property class as follows: // Parse the property class as follows:
...@@ -1425,8 +1426,8 @@ bool RegExpParser::ParsePropertyClassName(std::vector<char>* name_1, ...@@ -1425,8 +1426,8 @@ bool RegExpParser::ParsePropertyClassName(std::vector<char>* name_1,
bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to, bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to,
bool negate, bool negate,
const std::vector<char>& name_1, const ZoneVector<char>& name_1,
const std::vector<char>& name_2) { const ZoneVector<char>& name_2) {
if (name_2.empty()) { if (name_2.empty()) {
// First attempt to interpret as general category property value name. // First attempt to interpret as general category property value name.
const char* name = name_1.data(); const char* name = name_1.data();
...@@ -1463,7 +1464,7 @@ bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to, ...@@ -1463,7 +1464,7 @@ bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to,
} }
} }
RegExpTree* RegExpParser::GetPropertySequence(const std::vector<char>& name_1) { RegExpTree* RegExpParser::GetPropertySequence(const ZoneVector<char>& name_1) {
if (!FLAG_harmony_regexp_sequence) return nullptr; if (!FLAG_harmony_regexp_sequence) return nullptr;
const char* name = name_1.data(); const char* name = name_1.data();
const uc32* sequence_list = nullptr; const uc32* sequence_list = nullptr;
...@@ -1529,19 +1530,19 @@ RegExpTree* RegExpParser::GetPropertySequence(const std::vector<char>& name_1) { ...@@ -1529,19 +1530,19 @@ RegExpTree* RegExpParser::GetPropertySequence(const std::vector<char>& name_1) {
#else // V8_INTL_SUPPORT #else // V8_INTL_SUPPORT
bool RegExpParser::ParsePropertyClassName(std::vector<char>* name_1, bool RegExpParser::ParsePropertyClassName(ZoneVector<char>* name_1,
std::vector<char>* name_2) { ZoneVector<char>* name_2) {
return false; return false;
} }
bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to, bool RegExpParser::AddPropertyClassRange(ZoneList<CharacterRange>* add_to,
bool negate, bool negate,
const std::vector<char>& name_1, const ZoneVector<char>& name_1,
const std::vector<char>& name_2) { const ZoneVector<char>& name_2) {
return false; return false;
} }
RegExpTree* RegExpParser::GetPropertySequence(const std::vector<char>& name) { RegExpTree* RegExpParser::GetPropertySequence(const ZoneVector<char>& name) {
return nullptr; return nullptr;
} }
...@@ -1710,7 +1711,8 @@ void RegExpParser::ParseClassEscape(ZoneList<CharacterRange>* ranges, ...@@ -1710,7 +1711,8 @@ void RegExpParser::ParseClassEscape(ZoneList<CharacterRange>* ranges,
if (unicode()) { if (unicode()) {
bool negate = Next() == 'P'; bool negate = Next() == 'P';
Advance(2); Advance(2);
std::vector<char> name_1, name_2; ZoneVector<char> name_1(zone);
ZoneVector<char> name_2(zone);
if (!ParsePropertyClassName(&name_1, &name_2) || if (!ParsePropertyClassName(&name_1, &name_2) ||
!AddPropertyClassRange(ranges, negate, name_1, name_2)) { !AddPropertyClassRange(ranges, negate, name_1, name_2)) {
ReportError(CStrVector("Invalid property name in character class")); ReportError(CStrVector("Invalid property name in character class"));
......
...@@ -177,13 +177,13 @@ class V8_EXPORT_PRIVATE RegExpParser { ...@@ -177,13 +177,13 @@ class V8_EXPORT_PRIVATE RegExpParser {
bool ParseUnicodeEscape(uc32* value); bool ParseUnicodeEscape(uc32* value);
bool ParseUnlimitedLengthHexNumber(int max_value, uc32* value); bool ParseUnlimitedLengthHexNumber(int max_value, uc32* value);
bool ParsePropertyClassName(std::vector<char>* name_1, bool ParsePropertyClassName(ZoneVector<char>* name_1,
std::vector<char>* name_2); ZoneVector<char>* name_2);
bool AddPropertyClassRange(ZoneList<CharacterRange>* add_to, bool negate, bool AddPropertyClassRange(ZoneList<CharacterRange>* add_to, bool negate,
const std::vector<char>& name_1, const ZoneVector<char>& name_1,
const std::vector<char>& name_2); const ZoneVector<char>& name_2);
RegExpTree* GetPropertySequence(const std::vector<char>& name_1); RegExpTree* GetPropertySequence(const ZoneVector<char>& name_1);
RegExpTree* ParseCharacterClass(const RegExpBuilder* state); RegExpTree* ParseCharacterClass(const RegExpBuilder* state);
uc32 ParseOctalLiteral(); uc32 ParseOctalLiteral();
......
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