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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // Note: There is no need to initialize the Zone; the first time an | 58 // Note: There is no need to initialize the Zone; the first time an |
59 // allocation is attempted, a segment of memory will be requested | 59 // allocation is attempted, a segment of memory will be requested |
60 // through a call to malloc(). | 60 // through a call to malloc(). |
61 | 61 |
62 // Note: The implementation is inherently not thread safe. Do not use | 62 // Note: The implementation is inherently not thread safe. Do not use |
63 // from multi-threaded code. | 63 // from multi-threaded code. |
64 | 64 |
65 class Zone { | 65 class Zone { |
66 public: | 66 public: |
| 67 explicit Zone(Isolate* isolate); |
| 68 ~Zone() { DeleteKeptSegment(); } |
67 // Allocate 'size' bytes of memory in the Zone; expands the Zone by | 69 // Allocate 'size' bytes of memory in the Zone; expands the Zone by |
68 // allocating new segments of memory on demand using malloc(). | 70 // allocating new segments of memory on demand using malloc(). |
69 inline void* New(int size); | 71 inline void* New(int size); |
70 | 72 |
71 template <typename T> | 73 template <typename T> |
72 inline T* NewArray(int length); | 74 inline T* NewArray(int length); |
73 | 75 |
74 // Deletes all objects and free all memory allocated in the Zone. Keeps one | 76 // Deletes all objects and free all memory allocated in the Zone. Keeps one |
75 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one. | 77 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one. |
76 void DeleteAll(); | 78 void DeleteAll(); |
(...skipping 30 matching lines...) Expand all Loading... |
107 static const int kMaximumKeptSegmentSize = 64 * KB; | 109 static const int kMaximumKeptSegmentSize = 64 * KB; |
108 | 110 |
109 // Report zone excess when allocation exceeds this limit. | 111 // Report zone excess when allocation exceeds this limit. |
110 int zone_excess_limit_; | 112 int zone_excess_limit_; |
111 | 113 |
112 // The number of bytes allocated in segments. Note that this number | 114 // The number of bytes allocated in segments. Note that this number |
113 // includes memory allocated from the OS but not yet allocated from | 115 // includes memory allocated from the OS but not yet allocated from |
114 // the zone. | 116 // the zone. |
115 int segment_bytes_allocated_; | 117 int segment_bytes_allocated_; |
116 | 118 |
117 // Each isolate gets its own zone. | |
118 Zone(); | |
119 | |
120 // Expand the Zone to hold at least 'size' more bytes and allocate | 119 // Expand the Zone to hold at least 'size' more bytes and allocate |
121 // the bytes. Returns the address of the newly allocated chunk of | 120 // the bytes. Returns the address of the newly allocated chunk of |
122 // memory in the Zone. Should only be called if there isn't enough | 121 // memory in the Zone. Should only be called if there isn't enough |
123 // room in the Zone already. | 122 // room in the Zone already. |
124 Address NewExpand(int size); | 123 Address NewExpand(int size); |
125 | 124 |
126 // Creates a new segment, sets it size, and pushes it to the front | 125 // Creates a new segment, sets it size, and pushes it to the front |
127 // of the segment chain. Returns the new segment. | 126 // of the segment chain. Returns the new segment. |
128 Segment* NewSegment(int size); | 127 Segment* NewSegment(int size); |
129 | 128 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void operator delete(void* pointer) { UNREACHABLE(); } | 227 void operator delete(void* pointer) { UNREACHABLE(); } |
229 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 228 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } |
230 }; | 229 }; |
231 | 230 |
232 | 231 |
233 // ZoneScopes keep track of the current parsing and compilation | 232 // ZoneScopes keep track of the current parsing and compilation |
234 // nesting and cleans up generated ASTs in the Zone when exiting the | 233 // nesting and cleans up generated ASTs in the Zone when exiting the |
235 // outer-most scope. | 234 // outer-most scope. |
236 class ZoneScope BASE_EMBEDDED { | 235 class ZoneScope BASE_EMBEDDED { |
237 public: | 236 public: |
238 INLINE(ZoneScope(Isolate* isolate, ZoneScopeMode mode)); | 237 INLINE(ZoneScope(Zone* zone, ZoneScopeMode mode)); |
239 | 238 |
240 virtual ~ZoneScope(); | 239 virtual ~ZoneScope(); |
241 | 240 |
242 inline bool ShouldDeleteOnExit(); | 241 inline bool ShouldDeleteOnExit(); |
243 | 242 |
244 // For ZoneScopes that do not delete on exit by default, call this | 243 // For ZoneScopes that do not delete on exit by default, call this |
245 // method to request deletion on exit. | 244 // method to request deletion on exit. |
246 void DeleteOnExit() { | 245 void DeleteOnExit() { |
247 mode_ = DELETE_ON_EXIT; | 246 mode_ = DELETE_ON_EXIT; |
248 } | 247 } |
249 | 248 |
250 inline static int nesting(); | 249 inline static int nesting(); |
251 | 250 |
252 private: | 251 private: |
253 Isolate* isolate_; | 252 Zone* zone_; |
254 ZoneScopeMode mode_; | 253 ZoneScopeMode mode_; |
255 }; | 254 }; |
256 | 255 |
257 | 256 |
258 // A zone splay tree. The config type parameter encapsulates the | 257 // A zone splay tree. The config type parameter encapsulates the |
259 // different configurations of a concrete splay tree (see splay-tree.h). | 258 // different configurations of a concrete splay tree (see splay-tree.h). |
260 // The tree itself and all its elements are allocated in the Zone. | 259 // The tree itself and all its elements are allocated in the Zone. |
261 template <typename Config> | 260 template <typename Config> |
262 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { | 261 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { |
263 public: | 262 public: |
264 explicit ZoneSplayTree(Zone* zone) | 263 explicit ZoneSplayTree(Zone* zone) |
265 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} | 264 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} |
266 ~ZoneSplayTree(); | 265 ~ZoneSplayTree(); |
267 }; | 266 }; |
268 | 267 |
269 | 268 |
270 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 269 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
271 | 270 |
272 } } // namespace v8::internal | 271 } } // namespace v8::internal |
273 | 272 |
274 #endif // V8_ZONE_H_ | 273 #endif // V8_ZONE_H_ |
OLD | NEW |