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

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

Issue 2348303002: Replaced different means of zone pooling/reusing by one zone segment pool (Closed)
Patch Set: Added most recent changes from master 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
50 // Returns true if more memory has been allocated in zones than 47 // Returns true if more memory has been allocated in zones than
51 // the limit allows. 48 // the limit allows.
52 bool excess_allocation() const { 49 bool excess_allocation() const {
53 return segment_bytes_allocated_ > kExcessLimit; 50 return segment_bytes_allocated_ > kExcessLimit;
54 } 51 }
55 52
56 size_t allocation_size() const { return allocation_size_; } 53 size_t allocation_size() const { return allocation_size_; }
57 54
58 AccountingAllocator* allocator() const { return allocator_; } 55 AccountingAllocator* allocator() const { return allocator_; }
59 56
(...skipping 10 matching lines...) Expand all
70 67
71 // Never allocate segments smaller than this size in bytes. 68 // Never allocate segments smaller than this size in bytes.
72 static const size_t kMinimumSegmentSize = 8 * KB; 69 static const size_t kMinimumSegmentSize = 8 * KB;
73 70
74 // Never allocate segments larger than this size in bytes. 71 // Never allocate segments larger than this size in bytes.
75 static const size_t kMaximumSegmentSize = 1 * MB; 72 static const size_t kMaximumSegmentSize = 1 * MB;
76 73
77 // Report zone excess when allocation exceeds this limit. 74 // Report zone excess when allocation exceeds this limit.
78 static const size_t kExcessLimit = 256 * MB; 75 static const size_t kExcessLimit = 256 * MB;
79 76
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
141 // The ZoneAllocationPolicy is used to specialize generic data 128 // The ZoneAllocationPolicy is used to specialize generic data
142 // structures to allocate themselves and their elements in the Zone. 129 // structures to allocate themselves and their elements in the Zone.
143 class ZoneAllocationPolicy final { 130 class ZoneAllocationPolicy final {
144 public: 131 public:
145 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) {} 132 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) {}
146 void* New(size_t size) { return zone()->New(size); } 133 void* New(size_t size) { return zone()->New(size); }
147 static void Delete(void* pointer) {} 134 static void Delete(void* pointer) {}
148 Zone* zone() const { return zone_; } 135 Zone* zone() const { return zone_; }
149 136
150 private: 137 private:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 213
227 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 214 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
228 215
229 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> 216 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy>
230 CustomMatcherZoneHashMap; 217 CustomMatcherZoneHashMap;
231 218
232 } // namespace internal 219 } // namespace internal
233 } // namespace v8 220 } // namespace v8
234 221
235 #endif // V8_ZONE_ZONE_H_ 222 #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