Fixed issue where regexps were parsed without having set up a zone
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 2 Dec 2008 14:00:24 +0000 (14:00 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 2 Dec 2008 14:00:24 +0000 (14:00 +0000)
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
src/v8-counters.h
src/zone-inl.h
src/zone.cc
src/zone.h
test/cctest/test-ast.cc

index bf9d4de..05b8aa0 100644 (file)
@@ -207,12 +207,15 @@ Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
   JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
   Handle<FixedArray> cached = CompilationCache::LookupRegExp(pattern, flags);
   bool in_cache = !cached.is_null();
+  LOG(RegExpCompileEvent(re, in_cache));
+
   Handle<Object> 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<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
     }
   }
 
-  LOG(RegExpCompileEvent(re, in_cache));
   return result;
 }
 
index 0f5af8a..586e002 100644 (file)
@@ -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.
index 6e64c42..fd66b64 100644 (file)
 #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_
index f4908c5..cfa161a 100644 (file)
@@ -65,7 +65,7 @@ class Segment {
   // of the segment chain. Returns the new segment.
   static Segment* New(int size) {
     Segment* result = reinterpret_cast<Segment*>(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);
   }
 
index 9721b07..612819e 100644 (file)
@@ -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_;
index 7d10c82..8646289 100644 (file)
@@ -38,6 +38,7 @@ TEST(List) {
   List<Node*>* list = new List<Node*>(0);
   CHECK_EQ(0, list->length());
 
+  ZoneScope zone_scope(DELETE_ON_EXIT);
   Node* node = new EmptyStatement();
   list->Add(node);
   CHECK_EQ(1, list->length());