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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // The free region in the current (front) segment is represented as | 102 // The free region in the current (front) segment is represented as |
100 // the half-open interval [position, limit). The 'position' variable | 103 // the half-open interval [position, limit). The 'position' variable |
101 // is guaranteed to be aligned as dictated by kAlignment. | 104 // is guaranteed to be aligned as dictated by kAlignment. |
102 Address position_; | 105 Address position_; |
103 Address limit_; | 106 Address limit_; |
104 | 107 |
105 AccountingAllocator* allocator_; | 108 AccountingAllocator* allocator_; |
106 | 109 |
107 Segment* segment_head_; | 110 Segment* segment_head_; |
108 const char* name_; | 111 const char* name_; |
| 112 bool sealed_; |
109 }; | 113 }; |
110 | 114 |
111 // ZoneObject is an abstraction that helps define classes of objects | 115 // ZoneObject is an abstraction that helps define classes of objects |
112 // allocated in the Zone. Use it as a base class; see ast.h. | 116 // allocated in the Zone. Use it as a base class; see ast.h. |
113 class ZoneObject { | 117 class ZoneObject { |
114 public: | 118 public: |
115 // Allocate a new ZoneObject of 'size' bytes in the Zone. | 119 // Allocate a new ZoneObject of 'size' bytes in the Zone. |
116 void* operator new(size_t size, Zone* zone) { return zone->New(size); } | 120 void* operator new(size_t size, Zone* zone) { return zone->New(size); } |
117 | 121 |
118 // Ideally, the delete operator should be private instead of | 122 // Ideally, the delete operator should be private instead of |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 226 |
223 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 227 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
224 | 228 |
225 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> | 229 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> |
226 CustomMatcherZoneHashMap; | 230 CustomMatcherZoneHashMap; |
227 | 231 |
228 } // namespace internal | 232 } // namespace internal |
229 } // namespace v8 | 233 } // namespace v8 |
230 | 234 |
231 #endif // V8_ZONE_ZONE_H_ | 235 #endif // V8_ZONE_ZONE_H_ |
OLD | NEW |