Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/zone/zone.h

Issue 2401163002: Revert of Replaced different means of zone pooling/reusing by one zone segment pool (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/v8.gyp ('k') | src/zone/zone.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ZONE_ZONE_H_ 5 #ifndef V8_ZONE_ZONE_H_
6 #define V8_ZONE_ZONE_H_ 6 #define V8_ZONE_ZONE_H_
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 26 matching lines...) Expand all
37 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 37 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
38 // allocating new segments of memory on demand using malloc(). 38 // allocating new segments of memory on demand using malloc().
39 void* New(size_t size); 39 void* New(size_t size);
40 40
41 template <typename T> 41 template <typename T>
42 T* NewArray(size_t length) { 42 T* NewArray(size_t length) {
43 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T)); 43 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T));
44 return static_cast<T*>(New(length * sizeof(T))); 44 return static_cast<T*>(New(length * sizeof(T)));
45 } 45 }
46 46
47 // Deletes all objects and free all memory allocated in the Zone.
48 void DeleteAll();
49
47 // Returns true if more memory has been allocated in zones than 50 // Returns true if more memory has been allocated in zones than
48 // the limit allows. 51 // the limit allows.
49 bool excess_allocation() const { 52 bool excess_allocation() const {
50 return segment_bytes_allocated_ > kExcessLimit; 53 return segment_bytes_allocated_ > kExcessLimit;
51 } 54 }
52 55
53 size_t allocation_size() const { return allocation_size_; } 56 size_t allocation_size() const { return allocation_size_; }
54 57
55 AccountingAllocator* allocator() const { return allocator_; } 58 AccountingAllocator* allocator() const { return allocator_; }
56 59
(...skipping 10 matching lines...) Expand all
67 70
68 // Never allocate segments smaller than this size in bytes. 71 // Never allocate segments smaller than this size in bytes.
69 static const size_t kMinimumSegmentSize = 8 * KB; 72 static const size_t kMinimumSegmentSize = 8 * KB;
70 73
71 // Never allocate segments larger than this size in bytes. 74 // Never allocate segments larger than this size in bytes.
72 static const size_t kMaximumSegmentSize = 1 * MB; 75 static const size_t kMaximumSegmentSize = 1 * MB;
73 76
74 // Report zone excess when allocation exceeds this limit. 77 // Report zone excess when allocation exceeds this limit.
75 static const size_t kExcessLimit = 256 * MB; 78 static const size_t kExcessLimit = 256 * MB;
76 79
77 // Deletes all objects and free all memory allocated in the Zone.
78 void DeleteAll();
79
80 // The number of bytes allocated in this zone so far. 80 // The number of bytes allocated in this zone so far.
81 size_t allocation_size_; 81 size_t allocation_size_;
82 82
83 // The number of bytes allocated in segments. Note that this number 83 // The number of bytes allocated in segments. Note that this number
84 // includes memory allocated from the OS but not yet allocated from 84 // includes memory allocated from the OS but not yet allocated from
85 // the zone. 85 // the zone.
86 size_t segment_bytes_allocated_; 86 size_t segment_bytes_allocated_;
87 87
88 // Expand the Zone to hold at least 'size' more bytes and allocate 88 // Expand the Zone to hold at least 'size' more bytes and allocate
89 // the bytes. Returns the address of the newly allocated chunk of 89 // the bytes. Returns the address of the newly allocated chunk of
(...skipping 28 matching lines...) Expand all
118 // (unused) destructors for classes derived from ZoneObject, which 118 // (unused) destructors for classes derived from ZoneObject, which
119 // require the operator to be visible. MSVC requires the delete 119 // require the operator to be visible. MSVC requires the delete
120 // operator to be public. 120 // operator to be public.
121 121
122 // ZoneObjects should never be deleted individually; use 122 // ZoneObjects should never be deleted individually; use
123 // Zone::DeleteAll() to delete all zone objects in one go. 123 // Zone::DeleteAll() to delete all zone objects in one go.
124 void operator delete(void*, size_t) { UNREACHABLE(); } 124 void operator delete(void*, size_t) { UNREACHABLE(); }
125 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 125 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
126 }; 126 };
127 127
128 // The ZoneScope is used to automatically call DeleteAll() on a
129 // Zone when the ZoneScope is destroyed (i.e. goes out of scope)
130 class ZoneScope final {
131 public:
132 explicit ZoneScope(Zone* zone) : zone_(zone) {}
133 ~ZoneScope() { zone_->DeleteAll(); }
134
135 Zone* zone() const { return zone_; }
136
137 private:
138 Zone* zone_;
139 };
140
128 // The ZoneAllocationPolicy is used to specialize generic data 141 // The ZoneAllocationPolicy is used to specialize generic data
129 // structures to allocate themselves and their elements in the Zone. 142 // structures to allocate themselves and their elements in the Zone.
130 class ZoneAllocationPolicy final { 143 class ZoneAllocationPolicy final {
131 public: 144 public:
132 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) {} 145 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) {}
133 void* New(size_t size) { return zone()->New(size); } 146 void* New(size_t size) { return zone()->New(size); }
134 static void Delete(void* pointer) {} 147 static void Delete(void* pointer) {}
135 Zone* zone() const { return zone_; } 148 Zone* zone() const { return zone_; }
136 149
137 private: 150 private:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 226
214 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 227 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
215 228
216 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> 229 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy>
217 CustomMatcherZoneHashMap; 230 CustomMatcherZoneHashMap;
218 231
219 } // namespace internal 232 } // namespace internal
220 } // namespace v8 233 } // namespace v8
221 234
222 #endif // V8_ZONE_ZONE_H_ 235 #endif // V8_ZONE_ZONE_H_
OLDNEW
« no previous file with comments | « src/v8.gyp ('k') | src/zone/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698