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 21 matching lines...) Expand all Loading... |
32 #include "checks.h" | 32 #include "checks.h" |
33 #include "hashmap.h" | 33 #include "hashmap.h" |
34 #include "globals.h" | 34 #include "globals.h" |
35 #include "list.h" | 35 #include "list.h" |
36 #include "splay-tree.h" | 36 #include "splay-tree.h" |
37 | 37 |
38 namespace v8 { | 38 namespace v8 { |
39 namespace internal { | 39 namespace internal { |
40 | 40 |
41 | 41 |
42 // Zone scopes are in one of two modes. Either they delete the zone | |
43 // on exit or they do not. | |
44 enum ZoneScopeMode { | |
45 DELETE_ON_EXIT, | |
46 DONT_DELETE_ON_EXIT | |
47 }; | |
48 | |
49 class Segment; | 42 class Segment; |
50 class Isolate; | 43 class Isolate; |
51 | 44 |
52 // The Zone supports very fast allocation of small chunks of | 45 // The Zone supports very fast allocation of small chunks of |
53 // memory. The chunks cannot be deallocated individually, but instead | 46 // memory. The chunks cannot be deallocated individually, but instead |
54 // the Zone supports deallocating all chunks in one fast | 47 // the Zone supports deallocating all chunks in one fast |
55 // operation. The Zone is used to hold temporary data structures like | 48 // operation. The Zone is used to hold temporary data structures like |
56 // the abstract syntax tree, which is deallocated after compilation. | 49 // the abstract syntax tree, which is deallocated after compilation. |
57 | 50 |
58 // Note: There is no need to initialize the Zone; the first time an | 51 // Note: There is no need to initialize the Zone; the first time an |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 void operator delete(void* pointer) { UNREACHABLE(); } | 223 void operator delete(void* pointer) { UNREACHABLE(); } |
231 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 224 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
232 }; | 225 }; |
233 | 226 |
234 | 227 |
235 // ZoneScopes keep track of the current parsing and compilation | 228 // ZoneScopes keep track of the current parsing and compilation |
236 // nesting and cleans up generated ASTs in the Zone when exiting the | 229 // nesting and cleans up generated ASTs in the Zone when exiting the |
237 // outer-most scope. | 230 // outer-most scope. |
238 class ZoneScope BASE_EMBEDDED { | 231 class ZoneScope BASE_EMBEDDED { |
239 public: | 232 public: |
240 INLINE(ZoneScope(Zone* zone, ZoneScopeMode mode)); | 233 INLINE(ZoneScope(Zone* zone)); |
241 | 234 |
242 virtual ~ZoneScope(); | 235 virtual ~ZoneScope(); |
243 | 236 |
244 Zone* zone() const { return zone_; } | 237 Zone* zone() const { return zone_; } |
245 | 238 |
246 inline bool ShouldDeleteOnExit(); | 239 inline bool ShouldDeleteOnExit(); |
247 | 240 |
248 // For ZoneScopes that do not delete on exit by default, call this | |
249 // method to request deletion on exit. | |
250 void DeleteOnExit() { | |
251 mode_ = DELETE_ON_EXIT; | |
252 } | |
253 | |
254 inline static int nesting(); | 241 inline static int nesting(); |
255 | 242 |
256 private: | 243 private: |
257 Zone* zone_; | 244 Zone* zone_; |
258 ZoneScopeMode mode_; | |
259 }; | 245 }; |
260 | 246 |
261 | 247 |
262 // A zone splay tree. The config type parameter encapsulates the | 248 // A zone splay tree. The config type parameter encapsulates the |
263 // different configurations of a concrete splay tree (see splay-tree.h). | 249 // different configurations of a concrete splay tree (see splay-tree.h). |
264 // The tree itself and all its elements are allocated in the Zone. | 250 // The tree itself and all its elements are allocated in the Zone. |
265 template <typename Config> | 251 template <typename Config> |
266 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { | 252 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { |
267 public: | 253 public: |
268 explicit ZoneSplayTree(Zone* zone) | 254 explicit ZoneSplayTree(Zone* zone) |
269 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} | 255 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} |
270 ~ZoneSplayTree(); | 256 ~ZoneSplayTree(); |
271 }; | 257 }; |
272 | 258 |
273 | 259 |
274 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 260 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
275 | 261 |
276 } } // namespace v8::internal | 262 } } // namespace v8::internal |
277 | 263 |
278 #endif // V8_ZONE_H_ | 264 #endif // V8_ZONE_H_ |
OLD | NEW |