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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // require the operator to be visible. MSVC requires the delete | 157 // require the operator to be visible. MSVC requires the delete |
158 // operator to be public. | 158 // operator to be public. |
159 | 159 |
160 // ZoneObjects should never be deleted individually; use | 160 // ZoneObjects should never be deleted individually; use |
161 // Zone::DeleteAll() to delete all zone objects in one go. | 161 // Zone::DeleteAll() to delete all zone objects in one go. |
162 void operator delete(void*, size_t) { UNREACHABLE(); } | 162 void operator delete(void*, size_t) { UNREACHABLE(); } |
163 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 163 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
164 }; | 164 }; |
165 | 165 |
166 | 166 |
167 // The ZoneListAllocationPolicy is used to specialize the GenericList | 167 // The ZoneAllocationPolicy is used to specialize the generic data |
danno
2012/06/04 13:46:17
nit: should be just "specialize generic data"
sanjoy
2012/06/04 13:58:53
Done.
| |
168 // implementation to allocate ZoneLists and their elements in the | 168 // structures to allocate themselves and their elements in the Zone. |
169 // Zone. | 169 struct ZoneAllocationPolicy { |
170 class ZoneListAllocationPolicy { | |
171 public: | 170 public: |
172 // Allocate 'size' bytes of memory in the zone. | 171 explicit ZoneAllocationPolicy(Zone* zone = NULL) : zone_(zone) { } |
173 static void* New(int size); | 172 INLINE(void* New(size_t size)); |
173 INLINE(static void Delete(void *pointer)) { } | |
174 | 174 |
175 // De-allocation attempts are silently ignored. | 175 private: |
176 static void Delete(void* p) { } | 176 Zone* zone_; |
177 }; | 177 }; |
178 | 178 |
179 | 179 |
180 // ZoneLists are growable lists with constant-time access to the | 180 // ZoneLists are growable lists with constant-time access to the |
181 // elements. The list itself and all its elements are allocated in the | 181 // elements. The list itself and all its elements are allocated in the |
182 // Zone. ZoneLists cannot be deleted individually; you can delete all | 182 // Zone. ZoneLists cannot be deleted individually; you can delete all |
183 // objects in the Zone by calling Zone::DeleteAll(). | 183 // objects in the Zone by calling Zone::DeleteAll(). |
184 template<typename T> | 184 template<typename T> |
185 class ZoneList: public List<T, ZoneListAllocationPolicy> { | 185 class ZoneList: public List<T, ZoneAllocationPolicy> { |
186 public: | 186 public: |
187 INLINE(void* operator new(size_t size)); | |
188 INLINE(void* operator new(size_t size, Zone* zone)); | |
189 | |
190 // Construct a new ZoneList with the given capacity; the length is | 187 // Construct a new ZoneList with the given capacity; the length is |
191 // always zero. The capacity must be non-negative. | 188 // always zero. The capacity must be non-negative. |
192 explicit ZoneList(int capacity) | 189 explicit ZoneList(int capacity, Zone* zone = NULL) |
193 : List<T, ZoneListAllocationPolicy>(capacity) { } | 190 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { } |
191 | |
192 INLINE(void* operator new(size_t size, Zone* zone)); | |
193 INLINE(void* operator new(size_t size)); | |
194 | 194 |
195 // Construct a new ZoneList by copying the elements of the given ZoneList. | 195 // Construct a new ZoneList by copying the elements of the given ZoneList. |
196 explicit ZoneList(const ZoneList<T>& other) | 196 explicit ZoneList(const ZoneList<T>& other, Zone* zone = NULL) |
197 : List<T, ZoneListAllocationPolicy>(other.length()) { | 197 : List<T, ZoneAllocationPolicy>(other.length(), |
198 AddAll(other); | 198 ZoneAllocationPolicy(zone)) { |
199 AddAll(other, ZoneAllocationPolicy(zone)); | |
200 } | |
201 | |
202 // We add some convenience wrappers where so that we can pass in a | |
danno
2012/06/04 13:46:17
nit: should be just "wrappers so that"
sanjoy
2012/06/04 13:58:53
Done.
| |
203 // Zone instead of a (less convenient) ZoneAllocationPolicy. | |
204 INLINE(void Add(const T& element, Zone* zone = NULL)) { | |
205 List<T, ZoneAllocationPolicy>::Add(element, ZoneAllocationPolicy(zone)); | |
206 } | |
207 INLINE(void AddAll(const List<T, ZoneAllocationPolicy>& other, | |
208 Zone* zone = NULL)) { | |
209 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); | |
210 } | |
211 INLINE(void AddAll(const Vector<T>& other, Zone* zone = NULL)) { | |
212 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); | |
213 } | |
214 INLINE(void InsertAt(int index, const T& element, Zone* zone = NULL)) { | |
215 List<T, ZoneAllocationPolicy>::InsertAt(index, element, | |
216 ZoneAllocationPolicy(zone)); | |
217 } | |
218 INLINE(Vector<T> AddBlock(T value, int count, Zone* zone = NULL)) { | |
219 return List<T, ZoneAllocationPolicy>::AddBlock(value, count, | |
220 ZoneAllocationPolicy(zone)); | |
221 } | |
222 INLINE(void Allocate(int length, Zone* zone = NULL)) { | |
223 List<T, ZoneAllocationPolicy>::Allocate(length, ZoneAllocationPolicy(zone)); | |
224 } | |
225 INLINE(void Initialize(int capacity, Zone* zone = NULL)) { | |
226 List<T, ZoneAllocationPolicy>::Initialize(capacity, | |
227 ZoneAllocationPolicy(zone)); | |
199 } | 228 } |
200 | 229 |
201 void operator delete(void* pointer) { UNREACHABLE(); } | 230 void operator delete(void* pointer) { UNREACHABLE(); } |
202 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 231 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
203 }; | 232 }; |
204 | 233 |
205 | 234 |
206 // ZoneScopes keep track of the current parsing and compilation | 235 // ZoneScopes keep track of the current parsing and compilation |
207 // nesting and cleans up generated ASTs in the Zone when exiting the | 236 // nesting and cleans up generated ASTs in the Zone when exiting the |
208 // outer-most scope. | 237 // outer-most scope. |
(...skipping 16 matching lines...) Expand all Loading... | |
225 private: | 254 private: |
226 Isolate* isolate_; | 255 Isolate* isolate_; |
227 ZoneScopeMode mode_; | 256 ZoneScopeMode mode_; |
228 }; | 257 }; |
229 | 258 |
230 | 259 |
231 // A zone splay tree. The config type parameter encapsulates the | 260 // A zone splay tree. The config type parameter encapsulates the |
232 // different configurations of a concrete splay tree (see splay-tree.h). | 261 // different configurations of a concrete splay tree (see splay-tree.h). |
233 // The tree itself and all its elements are allocated in the Zone. | 262 // The tree itself and all its elements are allocated in the Zone. |
234 template <typename Config> | 263 template <typename Config> |
235 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { | 264 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { |
236 public: | 265 public: |
237 ZoneSplayTree() | 266 ZoneSplayTree() |
238 : SplayTree<Config, ZoneListAllocationPolicy>() {} | 267 : SplayTree<Config, ZoneAllocationPolicy>() {} |
239 ~ZoneSplayTree(); | 268 ~ZoneSplayTree(); |
240 }; | 269 }; |
241 | 270 |
242 | 271 |
243 typedef TemplateHashMapImpl<ZoneListAllocationPolicy> ZoneHashMap; | 272 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
244 | 273 |
245 } } // namespace v8::internal | 274 } } // namespace v8::internal |
246 | 275 |
247 #endif // V8_ZONE_H_ | 276 #endif // V8_ZONE_H_ |
OLD | NEW |