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);
}
// 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); }
};
};
-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_;
};
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_;
// 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_); }
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.
UNREACHABLE();
}
+ // Delete via the instance Deleter
+ static void Delete(List* p) {
+ if (p == NULL) return;
+ p->~List();
+ 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).
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.
}
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);
}
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();
}
// 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)) { }
// 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);