OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Segment* segment_head_; | 141 Segment* segment_head_; |
142 Isolate* isolate_; | 142 Isolate* isolate_; |
143 }; | 143 }; |
144 | 144 |
145 | 145 |
146 // ZoneObject is an abstraction that helps define classes of objects | 146 // ZoneObject is an abstraction that helps define classes of objects |
147 // allocated in the Zone. Use it as a base class; see ast.h. | 147 // allocated in the Zone. Use it as a base class; see ast.h. |
148 class ZoneObject { | 148 class ZoneObject { |
149 public: | 149 public: |
150 // Allocate a new ZoneObject of 'size' bytes in the Zone. | 150 // Allocate a new ZoneObject of 'size' bytes in the Zone. |
151 INLINE(void* operator new(size_t size)); | |
152 INLINE(void* operator new(size_t size, Zone* zone)); | 151 INLINE(void* operator new(size_t size, Zone* zone)); |
153 | 152 |
154 // Ideally, the delete operator should be private instead of | 153 // Ideally, the delete operator should be private instead of |
155 // public, but unfortunately the compiler sometimes synthesizes | 154 // public, but unfortunately the compiler sometimes synthesizes |
156 // (unused) destructors for classes derived from ZoneObject, which | 155 // (unused) destructors for classes derived from ZoneObject, which |
157 // require the operator to be visible. MSVC requires the delete | 156 // require the operator to be visible. MSVC requires the delete |
158 // operator to be public. | 157 // operator to be public. |
159 | 158 |
160 // ZoneObjects should never be deleted individually; use | 159 // ZoneObjects should never be deleted individually; use |
161 // Zone::DeleteAll() to delete all zone objects in one go. | 160 // Zone::DeleteAll() to delete all zone objects in one go. |
162 void operator delete(void*, size_t) { UNREACHABLE(); } | 161 void operator delete(void*, size_t) { UNREACHABLE(); } |
163 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 162 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
164 }; | 163 }; |
165 | 164 |
166 | 165 |
167 // The ZoneAllocationPolicy is used to specialize generic data | 166 // The ZoneAllocationPolicy is used to specialize generic data |
168 // structures to allocate themselves and their elements in the Zone. | 167 // structures to allocate themselves and their elements in the Zone. |
169 struct ZoneAllocationPolicy { | 168 struct ZoneAllocationPolicy { |
170 public: | 169 public: |
171 explicit ZoneAllocationPolicy(Zone* zone = NULL) : zone_(zone) { } | 170 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { } |
172 INLINE(void* New(size_t size)); | 171 INLINE(void* New(size_t size)); |
173 INLINE(static void Delete(void *pointer)) { } | 172 INLINE(static void Delete(void *pointer)) { } |
174 | 173 |
175 private: | 174 private: |
176 Zone* zone_; | 175 Zone* zone_; |
177 }; | 176 }; |
178 | 177 |
179 | 178 |
180 // ZoneLists are growable lists with constant-time access to the | 179 // ZoneLists are growable lists with constant-time access to the |
181 // elements. The list itself and all its elements are allocated in the | 180 // elements. The list itself and all its elements are allocated in the |
182 // Zone. ZoneLists cannot be deleted individually; you can delete all | 181 // Zone. ZoneLists cannot be deleted individually; you can delete all |
183 // objects in the Zone by calling Zone::DeleteAll(). | 182 // objects in the Zone by calling Zone::DeleteAll(). |
184 template<typename T> | 183 template<typename T> |
185 class ZoneList: public List<T, ZoneAllocationPolicy> { | 184 class ZoneList: public List<T, ZoneAllocationPolicy> { |
186 public: | 185 public: |
187 // Construct a new ZoneList with the given capacity; the length is | 186 // Construct a new ZoneList with the given capacity; the length is |
188 // always zero. The capacity must be non-negative. | 187 // always zero. The capacity must be non-negative. |
189 explicit ZoneList(int capacity, Zone* zone = NULL) | 188 explicit ZoneList(int capacity, Zone* zone) |
190 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { } | 189 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { } |
191 | 190 |
192 INLINE(void* operator new(size_t size, Zone* zone)); | 191 INLINE(void* operator new(size_t size, Zone* zone)); |
193 INLINE(void* operator new(size_t size)); | |
194 | 192 |
195 // Construct a new ZoneList by copying the elements of the given ZoneList. | 193 // Construct a new ZoneList by copying the elements of the given ZoneList. |
196 explicit ZoneList(const ZoneList<T>& other, Zone* zone = NULL) | 194 explicit ZoneList(const ZoneList<T>& other, Zone* zone) |
197 : List<T, ZoneAllocationPolicy>(other.length(), | 195 : List<T, ZoneAllocationPolicy>(other.length(), |
198 ZoneAllocationPolicy(zone)) { | 196 ZoneAllocationPolicy(zone)) { |
199 AddAll(other, ZoneAllocationPolicy(zone)); | 197 AddAll(other, ZoneAllocationPolicy(zone)); |
200 } | 198 } |
201 | 199 |
202 // We add some convenience wrappers so that we can pass in a Zone | 200 // We add some convenience wrappers so that we can pass in a Zone |
203 // instead of a (less convenient) ZoneAllocationPolicy. | 201 // instead of a (less convenient) ZoneAllocationPolicy. |
204 INLINE(void Add(const T& element, Zone* zone = NULL)) { | 202 INLINE(void Add(const T& element, Zone* zone)) { |
205 List<T, ZoneAllocationPolicy>::Add(element, ZoneAllocationPolicy(zone)); | 203 List<T, ZoneAllocationPolicy>::Add(element, ZoneAllocationPolicy(zone)); |
206 } | 204 } |
207 INLINE(void AddAll(const List<T, ZoneAllocationPolicy>& other, | 205 INLINE(void AddAll(const List<T, ZoneAllocationPolicy>& other, |
208 Zone* zone = NULL)) { | 206 Zone* zone)) { |
209 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); | 207 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); |
210 } | 208 } |
211 INLINE(void AddAll(const Vector<T>& other, Zone* zone = NULL)) { | 209 INLINE(void AddAll(const Vector<T>& other, Zone* zone)) { |
212 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); | 210 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); |
213 } | 211 } |
214 INLINE(void InsertAt(int index, const T& element, Zone* zone = NULL)) { | 212 INLINE(void InsertAt(int index, const T& element, Zone* zone)) { |
215 List<T, ZoneAllocationPolicy>::InsertAt(index, element, | 213 List<T, ZoneAllocationPolicy>::InsertAt(index, element, |
216 ZoneAllocationPolicy(zone)); | 214 ZoneAllocationPolicy(zone)); |
217 } | 215 } |
218 INLINE(Vector<T> AddBlock(T value, int count, Zone* zone = NULL)) { | 216 INLINE(Vector<T> AddBlock(T value, int count, Zone* zone)) { |
219 return List<T, ZoneAllocationPolicy>::AddBlock(value, count, | 217 return List<T, ZoneAllocationPolicy>::AddBlock(value, count, |
220 ZoneAllocationPolicy(zone)); | 218 ZoneAllocationPolicy(zone)); |
221 } | 219 } |
222 INLINE(void Allocate(int length, Zone* zone = NULL)) { | 220 INLINE(void Allocate(int length, Zone* zone)) { |
223 List<T, ZoneAllocationPolicy>::Allocate(length, ZoneAllocationPolicy(zone)); | 221 List<T, ZoneAllocationPolicy>::Allocate(length, ZoneAllocationPolicy(zone)); |
224 } | 222 } |
225 INLINE(void Initialize(int capacity, Zone* zone = NULL)) { | 223 INLINE(void Initialize(int capacity, Zone* zone)) { |
226 List<T, ZoneAllocationPolicy>::Initialize(capacity, | 224 List<T, ZoneAllocationPolicy>::Initialize(capacity, |
227 ZoneAllocationPolicy(zone)); | 225 ZoneAllocationPolicy(zone)); |
228 } | 226 } |
229 | 227 |
230 void operator delete(void* pointer) { UNREACHABLE(); } | 228 void operator delete(void* pointer) { UNREACHABLE(); } |
231 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 229 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
232 }; | 230 }; |
233 | 231 |
234 | 232 |
235 // ZoneScopes keep track of the current parsing and compilation | 233 // ZoneScopes keep track of the current parsing and compilation |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 : SplayTree<Config, ZoneAllocationPolicy>() {} | 265 : SplayTree<Config, ZoneAllocationPolicy>() {} |
268 ~ZoneSplayTree(); | 266 ~ZoneSplayTree(); |
269 }; | 267 }; |
270 | 268 |
271 | 269 |
272 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 270 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
273 | 271 |
274 } } // namespace v8::internal | 272 } } // namespace v8::internal |
275 | 273 |
276 #endif // V8_ZONE_H_ | 274 #endif // V8_ZONE_H_ |
OLD | NEW |