From 12774ab2d8a2836e1c9d7d4c15f2a9ffbe13dcd9 Mon Sep 17 00:00:00 2001 From: "christian.plesner.hansen@gmail.com" Date: Tue, 2 Dec 2008 14:00:24 +0000 Subject: [PATCH] Fixed issue where regexps were parsed without having set up a zone scope, leading to zone exhaustion. Added assertion that a zone scope exists on zone allocation. git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@898 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/jsregexp.cc | 4 +++- src/v8-counters.h | 3 ++- src/zone-inl.h | 8 ++++++++ src/zone.cc | 4 ++-- src/zone.h | 5 ++++- test/cctest/test-ast.cc | 1 + 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/jsregexp.cc b/src/jsregexp.cc index bf9d4de..05b8aa0 100644 --- a/src/jsregexp.cc +++ b/src/jsregexp.cc @@ -207,12 +207,15 @@ Handle RegExpImpl::Compile(Handle re, JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); Handle cached = CompilationCache::LookupRegExp(pattern, flags); bool in_cache = !cached.is_null(); + LOG(RegExpCompileEvent(re, in_cache)); + Handle result; if (in_cache) { re->set_data(*cached); result = re; } else { FlattenString(pattern); + ZoneScope zone_scope(DELETE_ON_EXIT); RegExpParseResult parse_result; FlatStringReader reader(pattern); if (!ParseRegExp(&reader, flags.is_multiline(), &parse_result)) { @@ -258,7 +261,6 @@ Handle RegExpImpl::Compile(Handle re, } } - LOG(RegExpCompileEvent(re, in_cache)); return result; } diff --git a/src/v8-counters.h b/src/v8-counters.h index 0f5af8a..586e002 100644 --- a/src/v8-counters.h +++ b/src/v8-counters.h @@ -118,7 +118,8 @@ namespace v8 { namespace internal { SC(enum_cache_hits, V8.EnumCacheHits) \ SC(enum_cache_misses, V8.EnumCacheMisses) \ SC(reloc_info_count, V8.RelocInfoCount) \ - SC(reloc_info_size, V8.RelocInfoSize) + SC(reloc_info_size, V8.RelocInfoSize) \ + SC(zone_segment_bytes, V8.ZoneSegmentBytes) // This file contains all the v8 counters that are in use. diff --git a/src/zone-inl.h b/src/zone-inl.h index 6e64c42..fd66b64 100644 --- a/src/zone-inl.h +++ b/src/zone-inl.h @@ -29,12 +29,14 @@ #define V8_ZONE_INL_H_ #include "zone.h" +#include "v8-counters.h" namespace v8 { namespace internal { inline void* Zone::New(int size) { ASSERT(AssertNoZoneAllocation::allow_allocation()); + ASSERT(ZoneScope::nesting() > 0); // Round up the requested size to fit the alignment. size = RoundUp(size, kAlignment); @@ -53,6 +55,12 @@ bool Zone::excess_allocation() { } +void Zone::adjust_segment_bytes_allocated(int delta) { + segment_bytes_allocated_ += delta; + Counters::zone_segment_bytes.Set(segment_bytes_allocated_); +} + + } } // namespace v8::internal #endif // V8_ZONE_INL_H_ diff --git a/src/zone.cc b/src/zone.cc index f4908c5..cfa161a 100644 --- a/src/zone.cc +++ b/src/zone.cc @@ -65,7 +65,7 @@ class Segment { // of the segment chain. Returns the new segment. static Segment* New(int size) { Segment* result = reinterpret_cast(Malloced::New(size)); - Zone::segment_bytes_allocated_ += size; + Zone::adjust_segment_bytes_allocated(size); if (result != NULL) { result->next_ = head_; result->size_ = size; @@ -76,7 +76,7 @@ class Segment { // Deletes the given segment. Does not touch the segment chain. static void Delete(Segment* segment, int size) { - Zone::segment_bytes_allocated_ -= size; + Zone::adjust_segment_bytes_allocated(-size); Malloced::Delete(segment); } diff --git a/src/zone.h b/src/zone.h index 9721b07..612819e 100644 --- a/src/zone.h +++ b/src/zone.h @@ -65,8 +65,9 @@ class Zone { // the limit allows. static inline bool excess_allocation(); + static inline void adjust_segment_bytes_allocated(int delta); + private: - friend class Segment; // All pointers returned from New() have this alignment. static const int kAlignment = kPointerSize; @@ -183,6 +184,8 @@ class ZoneScope BASE_EMBEDDED { mode_ = DELETE_ON_EXIT; } + static int nesting() { return nesting_; } + private: ZoneScopeMode mode_; static int nesting_; diff --git a/test/cctest/test-ast.cc b/test/cctest/test-ast.cc index 7d10c82..8646289 100644 --- a/test/cctest/test-ast.cc +++ b/test/cctest/test-ast.cc @@ -38,6 +38,7 @@ TEST(List) { List* list = new List(0); CHECK_EQ(0, list->length()); + ZoneScope zone_scope(DELETE_ON_EXIT); Node* node = new EmptyStatement(); list->Add(node); CHECK_EQ(1, list->length()); -- 2.7.4