Reviewers: Sven Panne,

Description:
thread isolate in PreallocatedStorageAllocationPolicy

[email protected]
BUG=

Please review this at https://codereview.chromium.org/23479015/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/allocation-inl.h
  M src/allocation.h
  M src/isolate.cc
  M src/list.h
  M src/string-stream.cc
  M src/zone.h
  M test/cctest/test-list.cc


Index: src/allocation-inl.h
diff --git a/src/allocation-inl.h b/src/allocation-inl.h
index d32db4b17fc18c314f3ce51adb087cfa2333c038..d215b176b10359fd1fceedd7e656bccc94dafb28 100644
--- a/src/allocation-inl.h
+++ b/src/allocation-inl.h
@@ -35,12 +35,12 @@ namespace internal {


 void* PreallocatedStorageAllocationPolicy::New(size_t size) {
-  return Isolate::Current()->PreallocatedStorageNew(size);
+  return isolate_->PreallocatedStorageNew(size);
 }


 void PreallocatedStorageAllocationPolicy::Delete(void* p) {
-  return Isolate::Current()->PreallocatedStorageDelete(p);
+  return isolate_->PreallocatedStorageDelete(p);
 }


Index: src/allocation.h
diff --git a/src/allocation.h b/src/allocation.h
index 45bde4c4cb07068a05e301d2124990637d82609d..b70087955cbdaad42da9feee1af97d5e472c9414 100644
--- a/src/allocation.h
+++ b/src/allocation.h
@@ -104,6 +104,7 @@ char* StrNDup(const char* str, int n);
 // and free. Used as the default policy for lists.
 class FreeStoreAllocationPolicy {
  public:
+  typedef FreeStoreAllocationPolicy Deleter;
   INLINE(void* New(size_t size)) { return Malloced::New(size); }
   INLINE(static void Delete(void* p)) { Malloced::Delete(p); }
 };
@@ -131,9 +132,21 @@ class PreallocatedStorage {
 };


-struct PreallocatedStorageAllocationPolicy {
+class Isolate;
+
+
+class PreallocatedStorageAllocationPolicy {
+ public:
+  typedef PreallocatedStorageAllocationPolicy Deleter;
+  INLINE(explicit PreallocatedStorageAllocationPolicy(Isolate* isolate))
+    : isolate_(isolate) { }
+  INLINE(PreallocatedStorageAllocationPolicy(
+      const PreallocatedStorageAllocationPolicy& policy))
+    : isolate_(policy.isolate_) { }
   INLINE(void* New(size_t size));
-  INLINE(static void Delete(void* ptr));
+  INLINE(void Delete(void* ptr));
+ private:
+  Isolate* isolate_;
 };


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 0e7b6d55d1521965efb3c4b7a04974e66c19d3cd..69199305ca11a7c269993b3dae0133252ebf56ab 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -2059,7 +2059,7 @@ Isolate::~Isolate() {
   delete eternal_handles_;
   eternal_handles_ = NULL;

-  delete string_stream_debug_object_cache_;
+  DebugObjectCache::Delete(string_stream_debug_object_cache_);
   string_stream_debug_object_cache_ = NULL;

   delete external_reference_table_;
Index: src/list.h
diff --git a/src/list.h b/src/list.h
index 0e4e35bb41b78b3ff5aa8b106ea284d1e4ded91c..d0262546bd78a91cad61849cd95985f4643f1fb9 100644
--- a/src/list.h
+++ b/src/list.h
@@ -48,13 +48,15 @@ namespace internal {
 // template <typename T,
// class AllocationPolicy = FreeStoreAllocationPolicy> class List;
 template <typename T, class AllocationPolicy>
-class List {
+class List : private AllocationPolicy::Deleter {
  public:
-  explicit List(AllocationPolicy allocator = AllocationPolicy()) {
+  explicit List(AllocationPolicy allocator = AllocationPolicy())
+    : AllocationPolicy::Deleter(allocator) {
     Initialize(0, allocator);
   }
   INLINE(explicit List(int capacity,
-                       AllocationPolicy allocator = AllocationPolicy())) {
+                       AllocationPolicy allocator = AllocationPolicy()))
+    : AllocationPolicy::Deleter(allocator) {
     Initialize(capacity, allocator);
   }
   INLINE(~List()) { DeleteData(data_); }
@@ -71,7 +73,7 @@ class List {
     return allocator.New(static_cast<int>(size));
   }
   INLINE(void operator delete(void* p)) {
-    AllocationPolicy::Delete(p);
+    AllocationPolicy::Deleter::Delete(p);
   }

   // Please the MSVC compiler.  We should never have to execute this.
@@ -79,6 +81,11 @@ class List {
     UNREACHABLE();
   }

+  // Delete via the instance Deleter
+  static void Delete(List* p) {
+    p->AllocationPolicy::Deleter::Delete(p);
+  }
+
   // Returns a reference to the element at index i.  This reference is
   // not safe to use after operations that can change the list's
   // backing store (e.g. Add).
@@ -179,7 +186,7 @@ class List {
     return static_cast<T*>(allocator.New(n * sizeof(T)));
   }
   INLINE(void DeleteData(T* data))  {
-    AllocationPolicy::Delete(data);
+    this->AllocationPolicy::Deleter::Delete(data);
   }

   // Increase the capacity of a full list, and add an element.
Index: src/string-stream.cc
diff --git a/src/string-stream.cc b/src/string-stream.cc
index 9c4394ed7f01d1e3e3f1b405a616e1701664433a..8ab1244364310e4b997cae276975a358bd9598f2 100644
--- a/src/string-stream.cc
+++ b/src/string-stream.cc
@@ -204,7 +204,9 @@ void StringStream::PrintObject(Object* o) {
     }
     if (debug_object_cache->length() < kMentionedObjectCacheMaxSize) {
       Add("#%d#", debug_object_cache->length());
-      debug_object_cache->Add(HeapObject::cast(o));
+      HeapObject* ho = HeapObject::cast(o);
+      PreallocatedStorageAllocationPolicy policy(ho->GetIsolate());
+      debug_object_cache->Add(ho, policy);
     } else {
       Add("@%p", o);
     }
@@ -299,8 +301,9 @@ void StringStream::ClearMentionedObjectCache() {
   Isolate* isolate = Isolate::Current();
   isolate->set_string_stream_current_security_token(NULL);
   if (isolate->string_stream_debug_object_cache() == NULL) {
+    PreallocatedStorageAllocationPolicy policy(isolate);
     isolate->set_string_stream_debug_object_cache(
-        new List<HeapObject*, PreallocatedStorageAllocationPolicy>(0));
+        new(policy) DebugObjectCache(policy));
   }
   isolate->string_stream_debug_object_cache()->Clear();
 }
Index: src/zone.h
diff --git a/src/zone.h b/src/zone.h
index bd7cc39b0c4f224b0646792fbd8ed262fdc5f986..34fb7387eacce42d5e01a5ac7b470e33f8199ca1 100644
--- a/src/zone.h
+++ b/src/zone.h
@@ -174,6 +174,11 @@ struct ZoneScope {
 // structures to allocate themselves and their elements in the Zone.
 struct ZoneAllocationPolicy {
  public:
+  class Deleter {
+   public:
+    INLINE(explicit Deleter(const ZoneAllocationPolicy&)) {}
+    INLINE(static void Delete(void *pointer)) { }
+  };
   explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { }
   INLINE(void* New(size_t size));
   INLINE(static void Delete(void *pointer)) { }
Index: test/cctest/test-list.cc
diff --git a/test/cctest/test-list.cc b/test/cctest/test-list.cc
index a29972b583bb7754cb33b8bcba9580c3620958b7..ca15bf99b6bb42efbcd9d351958176e580bb1e29 100644
--- a/test/cctest/test-list.cc
+++ b/test/cctest/test-list.cc
@@ -35,6 +35,8 @@ using namespace v8::internal;
 // Use a testing allocator that clears memory before deletion.
 class ZeroingAllocationPolicy {
  public:
+  typedef ZeroingAllocationPolicy Deleter;
+
   void* New(size_t size) {
     // Stash the size in the first word to use for Delete.
     size_t true_size = size + sizeof(size_t);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to