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

Side by Side Diff: src/zone.h

Issue 7374002: Refactor allocation policies. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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
« no previous file with comments | « src/x64/regexp-macro-assembler-x64.cc ('k') | src/zone-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 class AssertNoZoneAllocation { 152 class AssertNoZoneAllocation {
153 public: 153 public:
154 inline AssertNoZoneAllocation(); 154 inline AssertNoZoneAllocation();
155 inline ~AssertNoZoneAllocation(); 155 inline ~AssertNoZoneAllocation();
156 private: 156 private:
157 bool prev_; 157 bool prev_;
158 }; 158 };
159 159
160 160
161 // The ZoneListAllocationPolicy is used to specialize the GenericList 161 // The ZoneListAllocator is used to specialize the GenericList
162 // implementation to allocate ZoneLists and their elements in the 162 // implementation to allocate ZoneLists and their elements in the
163 // Zone. 163 // Zone.
164 class ZoneListAllocationPolicy { 164 class ZoneListAllocator {
165 public: 165 public:
166 explicit ZoneListAllocator(Zone* zone) : zone_(zone) {}
167
166 // Allocate 'size' bytes of memory in the zone. 168 // Allocate 'size' bytes of memory in the zone.
167 static void* New(int size); 169 void* New(int size);
168 170
169 // De-allocation attempts are silently ignored. 171 // De-allocation attempts are silently ignored.
170 static void Delete(void* p) { } 172 void Delete(void* p) { }
173
174 private:
175 Zone* zone_;
171 }; 176 };
172 177
173 178
174 // ZoneLists are growable lists with constant-time access to the 179 // ZoneLists are growable lists with constant-time access to the
175 // 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
176 // Zone. ZoneLists cannot be deleted individually; you can delete all 181 // Zone. ZoneLists cannot be deleted individually; you can delete all
177 // objects in the Zone by calling Zone::DeleteAll(). 182 // objects in the Zone by calling Zone::DeleteAll().
178 template<typename T> 183 template<typename T>
179 class ZoneList: public List<T, ZoneListAllocationPolicy> { 184 class ZoneList: public List<T, ZoneListAllocator> {
180 public: 185 public:
181 INLINE(void* operator new(size_t size));
182 INLINE(void* operator new(size_t size, Zone* zone)); 186 INLINE(void* operator new(size_t size, Zone* zone));
183 187
184 // Construct a new ZoneList with the given capacity; the length is 188 // Construct a new ZoneList with the given capacity; the length is
185 // always zero. The capacity must be non-negative. 189 // always zero. The capacity must be non-negative.
186 explicit ZoneList(int capacity) 190 ZoneList(Zone* zone, int capacity)
187 : List<T, ZoneListAllocationPolicy>(capacity) { } 191 : List<T, ZoneListAllocator>(capacity, ZoneListAllocator(zone)),
192 zone_(zone) { }
188 193
189 // Construct a new ZoneList by copying the elements of the given ZoneList. 194 // Construct a new ZoneList by copying the elements of the given ZoneList.
190 explicit ZoneList(const ZoneList<T>& other) 195 explicit ZoneList(const ZoneList<T>& other)
191 : List<T, ZoneListAllocationPolicy>(other.length()) { 196 : List<T, ZoneListAllocator>(other.length(), ZoneListAllocator(zone)),
197 zone_(other.zone()) {
192 AddAll(other); 198 AddAll(other);
193 } 199 }
200
201 static ZoneList* New(Zone* zone, int capacity);
202
203 Zone* zone() { return zone_; }
204
205 private:
206 // Malloc'ing a zone list doesn't make much sense.
207 void* operator new(size_t size);
208
209 Zone* zone_;
194 }; 210 };
195 211
196 212
197 // Introduce a convenience type for zone lists of map handles. 213 // Introduce a convenience type for zone lists of map handles.
198 typedef ZoneList<Handle<Map> > ZoneMapList; 214 typedef ZoneList<Handle<Map> > ZoneMapList;
199 215
200 216
201 // ZoneScopes keep track of the current parsing and compilation 217 // ZoneScopes keep track of the current parsing and compilation
202 // nesting and cleans up generated ASTs in the Zone when exiting the 218 // nesting and cleans up generated ASTs in the Zone when exiting the
203 // outer-most scope. 219 // outer-most scope.
(...skipping 16 matching lines...) Expand all
220 private: 236 private:
221 Isolate* isolate_; 237 Isolate* isolate_;
222 ZoneScopeMode mode_; 238 ZoneScopeMode mode_;
223 }; 239 };
224 240
225 241
226 // A zone splay tree. The config type parameter encapsulates the 242 // A zone splay tree. The config type parameter encapsulates the
227 // different configurations of a concrete splay tree (see splay-tree.h). 243 // different configurations of a concrete splay tree (see splay-tree.h).
228 // The tree itself and all its elements are allocated in the Zone. 244 // The tree itself and all its elements are allocated in the Zone.
229 template <typename Config> 245 template <typename Config>
230 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { 246 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocator> {
231 public: 247 public:
232 ZoneSplayTree() 248 explicit ZoneSplayTree(Zone* zone)
233 : SplayTree<Config, ZoneListAllocationPolicy>() {} 249 : SplayTree<Config, ZoneListAllocator>(ZoneListAllocator(zone)) {}
234 ~ZoneSplayTree(); 250 ~ZoneSplayTree();
235 }; 251 };
236 252
237 253
238 } } // namespace v8::internal 254 } } // namespace v8::internal
239 255
240 #endif // V8_ZONE_H_ 256 #endif // V8_ZONE_H_
OLDNEW
« no previous file with comments | « src/x64/regexp-macro-assembler-x64.cc ('k') | src/zone-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698