OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Allocate 'size' bytes of memory in the Zone; expands the Zone by | 43 // Allocate 'size' bytes of memory in the Zone; expands the Zone by |
44 // allocating new segments of memory on demand using malloc(). | 44 // allocating new segments of memory on demand using malloc(). |
45 void* New(size_t size); | 45 void* New(size_t size); |
46 | 46 |
47 template <typename T> | 47 template <typename T> |
48 T* NewArray(size_t length) { | 48 T* NewArray(size_t length) { |
49 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T)); | 49 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T)); |
50 return static_cast<T*>(New(length * sizeof(T))); | 50 return static_cast<T*>(New(length * sizeof(T))); |
51 } | 51 } |
52 | 52 |
| 53 // Seals the zone to prevent any further allocation. |
| 54 void Seal() { sealed_ = true; } |
| 55 |
53 // Returns true if more memory has been allocated in zones than | 56 // Returns true if more memory has been allocated in zones than |
54 // the limit allows. | 57 // the limit allows. |
55 bool excess_allocation() const { | 58 bool excess_allocation() const { |
56 return segment_bytes_allocated_ > kExcessLimit; | 59 return segment_bytes_allocated_ > kExcessLimit; |
57 } | 60 } |
58 | 61 |
59 const char* name() const { return name_; } | 62 const char* name() const { return name_; } |
60 | 63 |
61 size_t allocation_size() const { return allocation_size_; } | 64 size_t allocation_size() const { return allocation_size_; } |
62 | 65 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // The free region in the current (front) segment is represented as | 110 // The free region in the current (front) segment is represented as |
108 // the half-open interval [position, limit). The 'position' variable | 111 // the half-open interval [position, limit). The 'position' variable |
109 // is guaranteed to be aligned as dictated by kAlignment. | 112 // is guaranteed to be aligned as dictated by kAlignment. |
110 Address position_; | 113 Address position_; |
111 Address limit_; | 114 Address limit_; |
112 | 115 |
113 AccountingAllocator* allocator_; | 116 AccountingAllocator* allocator_; |
114 | 117 |
115 Segment* segment_head_; | 118 Segment* segment_head_; |
116 const char* name_; | 119 const char* name_; |
| 120 bool sealed_; |
117 }; | 121 }; |
118 | 122 |
119 // ZoneObject is an abstraction that helps define classes of objects | 123 // ZoneObject is an abstraction that helps define classes of objects |
120 // allocated in the Zone. Use it as a base class; see ast.h. | 124 // allocated in the Zone. Use it as a base class; see ast.h. |
121 class ZoneObject { | 125 class ZoneObject { |
122 public: | 126 public: |
123 // Allocate a new ZoneObject of 'size' bytes in the Zone. | 127 // Allocate a new ZoneObject of 'size' bytes in the Zone. |
124 void* operator new(size_t size, Zone* zone) { return zone->New(size); } | 128 void* operator new(size_t size, Zone* zone) { return zone->New(size); } |
125 | 129 |
126 // Ideally, the delete operator should be private instead of | 130 // Ideally, the delete operator should be private instead of |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 234 |
231 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 235 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
232 | 236 |
233 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> | 237 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> |
234 CustomMatcherZoneHashMap; | 238 CustomMatcherZoneHashMap; |
235 | 239 |
236 } // namespace internal | 240 } // namespace internal |
237 } // namespace v8 | 241 } // namespace v8 |
238 | 242 |
239 #endif // V8_ZONE_ZONE_H_ | 243 #endif // V8_ZONE_ZONE_H_ |
OLD | NEW |