Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: src/zone.h

Issue 17827005: Get rid of ZoneScope completely. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // 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
52 // allocation is attempted, a segment of memory will be requested 52 // allocation is attempted, a segment of memory will be requested
53 // through a call to malloc(). 53 // through a call to malloc().
54 54
55 // Note: The implementation is inherently not thread safe. Do not use 55 // Note: The implementation is inherently not thread safe. Do not use
56 // from multi-threaded code. 56 // from multi-threaded code.
57 57
58 class Zone { 58 class Zone {
59 public: 59 public:
60 explicit Zone(Isolate* isolate); 60 explicit Zone(Isolate* isolate);
61 ~Zone() { DeleteKeptSegment(); } 61 ~Zone();
62 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 62 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
63 // allocating new segments of memory on demand using malloc(). 63 // allocating new segments of memory on demand using malloc().
64 inline void* New(int size); 64 inline void* New(int size);
65 65
66 template <typename T> 66 template <typename T>
67 inline T* NewArray(int length); 67 inline T* NewArray(int length);
68 68
69 // Deletes all objects and free all memory allocated in the Zone. Keeps one
70 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one.
71 void DeleteAll();
72
73 // Deletes the last small segment kept around by DeleteAll().
74 void DeleteKeptSegment();
75
76 // Returns true if more memory has been allocated in zones than 69 // Returns true if more memory has been allocated in zones than
77 // the limit allows. 70 // the limit allows.
78 inline bool excess_allocation(); 71 inline bool excess_allocation();
79 72
80 inline void adjust_segment_bytes_allocated(int delta); 73 inline void adjust_segment_bytes_allocated(int delta);
81 74
82 inline unsigned allocation_size() { return allocation_size_; } 75 inline unsigned allocation_size() { return allocation_size_; }
83 76
84 inline Isolate* isolate() { return isolate_; } 77 inline Isolate* isolate() { return isolate_; }
85 78
86 private: 79 private:
87 friend class Isolate; 80 friend class Isolate;
88 friend class ZoneScope;
89 81
90 // All pointers returned from New() have this alignment. In addition, if the 82 // All pointers returned from New() have this alignment. In addition, if the
91 // object being allocated has a size that is divisible by 8 then its alignment 83 // object being allocated has a size that is divisible by 8 then its alignment
92 // will be 8. 84 // will be 8.
93 static const int kAlignment = kPointerSize; 85 static const int kAlignment = kPointerSize;
94 86
95 // Never allocate segments smaller than this size in bytes. 87 // Never allocate segments smaller than this size in bytes.
96 static const int kMinimumSegmentSize = 8 * KB; 88 static const int kMinimumSegmentSize = 8 * KB;
97 89
98 // Never allocate segments larger than this size in bytes. 90 // Never allocate segments larger than this size in bytes.
99 static const int kMaximumSegmentSize = 1 * MB; 91 static const int kMaximumSegmentSize = 1 * MB;
100 92
101 // Never keep segments larger than this size in bytes around.
102 static const int kMaximumKeptSegmentSize = 64 * KB;
103
104 // Report zone excess when allocation exceeds this limit. 93 // Report zone excess when allocation exceeds this limit.
105 int zone_excess_limit_; 94 int zone_excess_limit_;
106 95
107 // The number of bytes allocated in this zone so far. 96 // The number of bytes allocated in this zone so far.
108 unsigned allocation_size_; 97 unsigned allocation_size_;
109 98
110 // The number of bytes allocated in segments. Note that this number 99 // The number of bytes allocated in segments. Note that this number
111 // includes memory allocated from the OS but not yet allocated from 100 // includes memory allocated from the OS but not yet allocated from
112 // the zone. 101 // the zone.
113 int segment_bytes_allocated_; 102 int segment_bytes_allocated_;
(...skipping 10 matching lines...) Expand all
124 113
125 // Deletes the given segment. Does not touch the segment chain. 114 // Deletes the given segment. Does not touch the segment chain.
126 void DeleteSegment(Segment* segment, int size); 115 void DeleteSegment(Segment* segment, int size);
127 116
128 // The free region in the current (front) segment is represented as 117 // The free region in the current (front) segment is represented as
129 // the half-open interval [position, limit). The 'position' variable 118 // the half-open interval [position, limit). The 'position' variable
130 // is guaranteed to be aligned as dictated by kAlignment. 119 // is guaranteed to be aligned as dictated by kAlignment.
131 Address position_; 120 Address position_;
132 Address limit_; 121 Address limit_;
133 122
134 int scope_nesting_;
135
136 Segment* segment_head_; 123 Segment* segment_head_;
137 Isolate* isolate_; 124 Isolate* isolate_;
138 }; 125 };
139 126
140 127
141 // ZoneObject is an abstraction that helps define classes of objects 128 // ZoneObject is an abstraction that helps define classes of objects
142 // allocated in the Zone. Use it as a base class; see ast.h. 129 // allocated in the Zone. Use it as a base class; see ast.h.
143 class ZoneObject { 130 class ZoneObject {
144 public: 131 public:
145 // Allocate a new ZoneObject of 'size' bytes in the Zone. 132 // Allocate a new ZoneObject of 'size' bytes in the Zone.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 INLINE(void Initialize(int capacity, Zone* zone)) { 205 INLINE(void Initialize(int capacity, Zone* zone)) {
219 List<T, ZoneAllocationPolicy>::Initialize(capacity, 206 List<T, ZoneAllocationPolicy>::Initialize(capacity,
220 ZoneAllocationPolicy(zone)); 207 ZoneAllocationPolicy(zone));
221 } 208 }
222 209
223 void operator delete(void* pointer) { UNREACHABLE(); } 210 void operator delete(void* pointer) { UNREACHABLE(); }
224 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 211 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
225 }; 212 };
226 213
227 214
228 // ZoneScopes keep track of the current parsing and compilation
229 // nesting and cleans up generated ASTs in the Zone when exiting the
230 // outer-most scope.
231 class ZoneScope BASE_EMBEDDED {
232 public:
233 INLINE(ZoneScope(Zone* zone));
234
235 virtual ~ZoneScope();
236
237 Zone* zone() const { return zone_; }
238
239 inline bool ShouldDeleteOnExit();
240
241 inline static int nesting();
242
243 private:
244 Zone* zone_;
245 };
246
247
248 // A zone splay tree. The config type parameter encapsulates the 215 // A zone splay tree. The config type parameter encapsulates the
249 // different configurations of a concrete splay tree (see splay-tree.h). 216 // different configurations of a concrete splay tree (see splay-tree.h).
250 // The tree itself and all its elements are allocated in the Zone. 217 // The tree itself and all its elements are allocated in the Zone.
251 template <typename Config> 218 template <typename Config>
252 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { 219 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> {
253 public: 220 public:
254 explicit ZoneSplayTree(Zone* zone) 221 explicit ZoneSplayTree(Zone* zone)
255 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} 222 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {}
256 ~ZoneSplayTree(); 223 ~ZoneSplayTree();
257 }; 224 };
258 225
259 226
260 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 227 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
261 228
262 } } // namespace v8::internal 229 } } // namespace v8::internal
263 230
264 #endif // V8_ZONE_H_ 231 #endif // V8_ZONE_H_
OLDNEW
« src/runtime.cc ('K') | « src/stub-cache.cc ('k') | src/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698