Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index c8ad03057c47a55f1658ecc024867c09d52865ce..50a1a5ad91e34cfb4813b13de43cfa33e0d896b7 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -2528,8 +2528,10 @@ class ReplacementStringBuilder { |
| class CompiledReplacement { |
| public: |
| - CompiledReplacement() |
| - : parts_(1), replacement_substrings_(0), simple_hint_(false) {} |
| + explicit CompiledReplacement(Zone* zone) |
| + : parts_(1, zone), replacement_substrings_(0, zone), |
| + simple_hint_(false), |
| + zone_(zone) {} |
| void Compile(Handle<String> replacement, |
| int capture_count, |
| @@ -2549,6 +2551,8 @@ class CompiledReplacement { |
| return simple_hint_; |
| } |
| + Zone* zone() const { return zone_; } |
| + |
| private: |
| enum PartType { |
| SUBJECT_PREFIX = 1, |
| @@ -2610,7 +2614,8 @@ class CompiledReplacement { |
| static bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts, |
| Vector<Char> characters, |
| int capture_count, |
| - int subject_length) { |
| + int subject_length, |
| + Zone* zone) { |
| int length = characters.length(); |
| int last = 0; |
| for (int i = 0; i < length; i++) { |
| @@ -2625,7 +2630,8 @@ class CompiledReplacement { |
| case '$': |
| if (i > last) { |
| // There is a substring before. Include the first "$". |
| - parts->Add(ReplacementPart::ReplacementSubString(last, next_index)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, next_index), |
| + zone); |
| last = next_index + 1; // Continue after the second "$". |
| } else { |
| // Let the next substring start with the second "$". |
| @@ -2635,25 +2641,25 @@ class CompiledReplacement { |
| break; |
| case '`': |
| if (i > last) { |
| - parts->Add(ReplacementPart::ReplacementSubString(last, i)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); |
| } |
| - parts->Add(ReplacementPart::SubjectPrefix()); |
| + parts->Add(ReplacementPart::SubjectPrefix(), zone); |
| i = next_index; |
| last = i + 1; |
| break; |
| case '\'': |
| if (i > last) { |
| - parts->Add(ReplacementPart::ReplacementSubString(last, i)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); |
| } |
| - parts->Add(ReplacementPart::SubjectSuffix(subject_length)); |
| + parts->Add(ReplacementPart::SubjectSuffix(subject_length), zone); |
| i = next_index; |
| last = i + 1; |
| break; |
| case '&': |
| if (i > last) { |
| - parts->Add(ReplacementPart::ReplacementSubString(last, i)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); |
| } |
| - parts->Add(ReplacementPart::SubjectMatch()); |
| + parts->Add(ReplacementPart::SubjectMatch(), zone); |
| i = next_index; |
| last = i + 1; |
| break; |
| @@ -2686,10 +2692,10 @@ class CompiledReplacement { |
| } |
| if (capture_ref > 0) { |
| if (i > last) { |
| - parts->Add(ReplacementPart::ReplacementSubString(last, i)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); |
| } |
| ASSERT(capture_ref <= capture_count); |
| - parts->Add(ReplacementPart::SubjectCapture(capture_ref)); |
| + parts->Add(ReplacementPart::SubjectCapture(capture_ref), zone); |
| last = next_index + 1; |
| } |
| i = next_index; |
| @@ -2703,10 +2709,10 @@ class CompiledReplacement { |
| } |
| if (length > last) { |
| if (last == 0) { |
| - parts->Add(ReplacementPart::ReplacementString()); |
| + parts->Add(ReplacementPart::ReplacementString(), zone); |
| return true; |
| } else { |
| - parts->Add(ReplacementPart::ReplacementSubString(last, length)); |
| + parts->Add(ReplacementPart::ReplacementSubString(last, length), zone); |
| } |
| } |
| return false; |
| @@ -2715,6 +2721,7 @@ class CompiledReplacement { |
| ZoneList<ReplacementPart> parts_; |
| ZoneList<Handle<String> > replacement_substrings_; |
| bool simple_hint_; |
| + Zone* zone_; |
| }; |
| @@ -2729,13 +2736,15 @@ void CompiledReplacement::Compile(Handle<String> replacement, |
| simple_hint_ = ParseReplacementPattern(&parts_, |
| content.ToAsciiVector(), |
| capture_count, |
| - subject_length); |
| + subject_length, |
| + zone()); |
| } else { |
| ASSERT(content.IsTwoByte()); |
| simple_hint_ = ParseReplacementPattern(&parts_, |
| content.ToUC16Vector(), |
| capture_count, |
| - subject_length); |
| + subject_length, |
| + zone()); |
| } |
| } |
| Isolate* isolate = replacement->GetIsolate(); |
| @@ -2747,12 +2756,12 @@ void CompiledReplacement::Compile(Handle<String> replacement, |
| int from = -tag; |
| int to = parts_[i].data; |
| replacement_substrings_.Add( |
| - isolate->factory()->NewSubString(replacement, from, to)); |
| + isolate->factory()->NewSubString(replacement, from, to), zone()); |
| parts_[i].tag = REPLACEMENT_SUBSTRING; |
| parts_[i].data = substring_index; |
| substring_index++; |
| } else if (tag == REPLACEMENT_STRING) { |
| - replacement_substrings_.Add(replacement); |
| + replacement_substrings_.Add(replacement, zone()); |
| parts_[i].data = substring_index; |
| substring_index++; |
| } |
| @@ -2801,7 +2810,8 @@ void CompiledReplacement::Apply(ReplacementStringBuilder* builder, |
| void FindAsciiStringIndices(Vector<const char> subject, |
| char pattern, |
| ZoneList<int>* indices, |
| - unsigned int limit) { |
| + unsigned int limit, |
| + Zone* zone) { |
| ASSERT(limit > 0); |
| // Collect indices of pattern in subject using memchr. |
| // Stop after finding at most limit values. |
| @@ -2812,7 +2822,7 @@ void FindAsciiStringIndices(Vector<const char> subject, |
| pos = reinterpret_cast<const char*>( |
| memchr(pos, pattern, subject_end - pos)); |
| if (pos == NULL) return; |
| - indices->Add(static_cast<int>(pos - subject_start)); |
| + indices->Add(static_cast<int>(pos - subject_start), zone); |
| pos++; |
| limit--; |
| } |
| @@ -2824,7 +2834,8 @@ void FindStringIndices(Isolate* isolate, |
| Vector<const SubjectChar> subject, |
| Vector<const PatternChar> pattern, |
| ZoneList<int>* indices, |
| - unsigned int limit) { |
| + unsigned int limit, |
| + Zone* zone) { |
| ASSERT(limit > 0); |
| // Collect indices of pattern in subject. |
| // Stop after finding at most limit values. |
| @@ -2834,7 +2845,7 @@ void FindStringIndices(Isolate* isolate, |
| while (limit > 0) { |
| index = search.Search(subject, index); |
| if (index < 0) return; |
| - indices->Add(index); |
| + indices->Add(index, zone); |
| index += pattern_length; |
| limit--; |
| } |
| @@ -2845,7 +2856,8 @@ void FindStringIndicesDispatch(Isolate* isolate, |
| String* subject, |
| String* pattern, |
| ZoneList<int>* indices, |
| - unsigned int limit) { |
| + unsigned int limit, |
| + Zone* zone) { |
| { |
| AssertNoAllocation no_gc; |
| String::FlatContent subject_content = subject->GetFlatContent(); |
| @@ -2860,20 +2872,23 @@ void FindStringIndicesDispatch(Isolate* isolate, |
| FindAsciiStringIndices(subject_vector, |
| pattern_vector[0], |
| indices, |
| - limit); |
| + limit, |
| + zone); |
| } else { |
| FindStringIndices(isolate, |
| subject_vector, |
| pattern_vector, |
| indices, |
| - limit); |
| + limit, |
| + zone); |
| } |
| } else { |
| FindStringIndices(isolate, |
| subject_vector, |
| pattern_content.ToUC16Vector(), |
| indices, |
| - limit); |
| + limit, |
| + zone); |
| } |
| } else { |
| Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); |
| @@ -2882,13 +2897,15 @@ void FindStringIndicesDispatch(Isolate* isolate, |
| subject_vector, |
| pattern_content.ToAsciiVector(), |
| indices, |
| - limit); |
| + limit, |
| + zone); |
| } else { |
| FindStringIndices(isolate, |
| subject_vector, |
| pattern_content.ToUC16Vector(), |
| indices, |
| - limit); |
| + limit, |
| + zone); |
| } |
| } |
| } |
| @@ -2967,12 +2984,13 @@ MUST_USE_RESULT static MaybeObject* StringReplaceAtomRegExpWithString( |
| Handle<String> subject, |
| Handle<JSRegExp> pattern_regexp, |
| Handle<String> replacement, |
| - Handle<JSArray> last_match_info) { |
| + Handle<JSArray> last_match_info, |
| + Zone* zone) { |
| ASSERT(subject->IsFlat()); |
| ASSERT(replacement->IsFlat()); |
| ZoneScope zone_space(isolate, DELETE_ON_EXIT); |
| - ZoneList<int> indices(8); |
| + ZoneList<int> indices(8, isolate->zone()); |
| ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); |
| String* pattern = |
| String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
| @@ -2980,7 +2998,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceAtomRegExpWithString( |
| int pattern_len = pattern->length(); |
| int replacement_len = replacement->length(); |
| - FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff); |
| + FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff, |
| + zone); |
| int matches = indices.length(); |
| if (matches == 0) return *subject; |
| @@ -3041,7 +3060,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( |
| String* subject, |
| JSRegExp* regexp, |
| String* replacement, |
| - JSArray* last_match_info) { |
| + JSArray* last_match_info, |
| + Zone* zone) { |
| ASSERT(subject->IsFlat()); |
| ASSERT(replacement->IsFlat()); |
| @@ -3067,8 +3087,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( |
| int capture_count = regexp_handle->CaptureCount(); |
| // CompiledReplacement uses zone allocation. |
| - ZoneScope zone(isolate, DELETE_ON_EXIT); |
| - CompiledReplacement compiled_replacement; |
| + ZoneScope zonescope(isolate, DELETE_ON_EXIT); |
| + CompiledReplacement compiled_replacement(isolate->zone()); |
| compiled_replacement.Compile(replacement_handle, |
| capture_count, |
| length); |
| @@ -3086,14 +3106,16 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( |
| subject_handle, |
| regexp_handle, |
| replacement_handle, |
| - last_match_info_handle); |
| + last_match_info_handle, |
| + zone); |
| } else { |
| return StringReplaceAtomRegExpWithString<SeqTwoByteString>( |
| isolate, |
| subject_handle, |
| regexp_handle, |
| replacement_handle, |
| - last_match_info_handle); |
| + last_match_info_handle, |
| + zone); |
| } |
| } |
| @@ -3176,7 +3198,8 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( |
| Isolate* isolate, |
| String* subject, |
| JSRegExp* regexp, |
| - JSArray* last_match_info) { |
| + JSArray* last_match_info, |
| + Zone* zone) { |
| ASSERT(subject->IsFlat()); |
| HandleScope handles(isolate); |
| @@ -3195,14 +3218,16 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( |
| subject_handle, |
| regexp_handle, |
| empty_string_handle, |
| - last_match_info_handle); |
| + last_match_info_handle, |
| + zone); |
| } else { |
| return StringReplaceAtomRegExpWithString<SeqTwoByteString>( |
| isolate, |
| subject_handle, |
| regexp_handle, |
| empty_string_handle, |
| - last_match_info_handle); |
| + last_match_info_handle, |
| + zone); |
| } |
| } |
| @@ -3361,13 +3386,14 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceRegExpWithString) { |
| ASSERT(last_match_info->HasFastObjectElements()); |
| + Zone* zone = isolate->zone(); |
| if (replacement->length() == 0) { |
| if (subject->HasOnlyAsciiChars()) { |
| return StringReplaceRegExpWithEmptyString<SeqAsciiString>( |
| - isolate, subject, regexp, last_match_info); |
| + isolate, subject, regexp, last_match_info, zone); |
| } else { |
| return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( |
| - isolate, subject, regexp, last_match_info); |
| + isolate, subject, regexp, last_match_info, zone); |
| } |
| } |
| @@ -3375,7 +3401,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceRegExpWithString) { |
| subject, |
| regexp, |
| replacement, |
| - last_match_info); |
| + last_match_info, |
| + zone); |
| } |
| @@ -3709,8 +3736,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { |
| } |
| int length = subject->length(); |
| + Zone* zone = isolate->zone(); |
| ZoneScope zone_space(isolate, DELETE_ON_EXIT); |
| - ZoneList<int> offsets(8); |
| + ZoneList<int> offsets(8, isolate->zone()); |
|
danno
2012/06/05 13:42:35
just zone
sanjoy
2012/06/05 14:21:39
Fixed.
|
| int start; |
| int end; |
| do { |
| @@ -3720,8 +3748,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { |
| start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value(); |
| end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value(); |
| } |
| - offsets.Add(start); |
| - offsets.Add(end); |
| + offsets.Add(start, zone); |
| + offsets.Add(end, zone); |
| if (start == end) if (++end > length) break; |
| match = RegExpImpl::Exec(regexp, subject, end, regexp_info, |
| isolate->zone()); |
| @@ -6427,17 +6455,18 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) { |
| static const int kMaxInitialListCapacity = 16; |
| + Zone* zone = isolate->zone(); |
| ZoneScope scope(isolate, DELETE_ON_EXIT); |
| // Find (up to limit) indices of separator and end-of-string in subject |
| int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); |
| - ZoneList<int> indices(initial_capacity); |
| + ZoneList<int> indices(initial_capacity, isolate->zone()); |
|
danno
2012/06/05 13:42:35
just zone
sanjoy
2012/06/05 14:21:39
Fixed.
|
| if (!pattern->IsFlat()) FlattenString(pattern); |
| - FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit); |
| + FindStringIndicesDispatch(isolate, *subject, *pattern, &indices, limit, zone); |
| if (static_cast<uint32_t>(indices.length()) < limit) { |
| - indices.Add(subject_length); |
| + indices.Add(subject_length, zone); |
| } |
| // The list indices now contains the end of each part to create. |
| @@ -9276,13 +9305,14 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { |
| ASSERT_EQ(1, args.length()); |
| CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| + Zone* zone = isolate->zone(); |
| source = Handle<String>(source->TryFlattenGetString()); |
| // Optimized fast case where we only have ASCII characters. |
| Handle<Object> result; |
| if (source->IsSeqAsciiString()) { |
| - result = JsonParser<true>::Parse(source); |
| + result = JsonParser<true>::Parse(source, zone); |
| } else { |
| - result = JsonParser<false>::Parse(source); |
| + result = JsonParser<false>::Parse(source, zone); |
| } |
| if (result.is_null()) { |
| // Syntax error or stack overflow in scanner. |
| @@ -12740,7 +12770,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { |
| CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); |
| CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); |
| - return *LiveEdit::CheckAndDropActivations(shared_array, do_drop); |
| + return *LiveEdit::CheckAndDropActivations(shared_array, do_drop, |
| + isolate->zone()); |
| } |
| // Compares 2 strings line-by-line, then token-wise and returns diff in form |