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

Side by Side Diff: src/zone.h

Issue 10448007: Split an allocation policy into an allocator and a deallocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed the issues pointed out. Created 8 years, 7 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 class ZoneAllocator {
168 public:
169 INLINE(void* New(int size));
170 };
171
172
173 // De-allocation attempts are silently ignored.
174 class ZoneDeallocator {
175 public:
176 INLINE(void Delete(void* ptr)) { }
177 };
178
179
180 // The ZoneAllocationPolicy is used to specialize the generic List
168 // implementation to allocate ZoneLists and their elements in the 181 // implementation to allocate ZoneLists and their elements in the
169 // Zone. 182 // Zone.
170 class ZoneListAllocationPolicy { 183 struct ZoneAllocationPolicy {
171 public: 184 typedef ZoneAllocator Allocator;
172 // Allocate 'size' bytes of memory in the zone. 185 typedef ZoneDeallocator Deallocator;
173 static void* New(int size);
174
175 // De-allocation attempts are silently ignored.
176 static void Delete(void* p) { }
177 }; 186 };
178 187
179
180 // ZoneLists are growable lists with constant-time access to the 188 // ZoneLists are growable lists with constant-time access to the
181 // elements. The list itself and all its elements are allocated in the 189 // elements. The list itself and all its elements are allocated in the
182 // Zone. ZoneLists cannot be deleted individually; you can delete all 190 // Zone. ZoneLists cannot be deleted individually; you can delete all
183 // objects in the Zone by calling Zone::DeleteAll(). 191 // objects in the Zone by calling Zone::DeleteAll().
184 template<typename T> 192 template<typename T>
185 class ZoneList: public List<T, ZoneListAllocationPolicy> { 193 class ZoneList: public List<T, ZoneAllocationPolicy> {
186 public: 194 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 195 // Construct a new ZoneList with the given capacity; the length is
191 // always zero. The capacity must be non-negative. 196 // always zero. The capacity must be non-negative.
192 explicit ZoneList(int capacity) 197 explicit ZoneList(int capacity)
193 : List<T, ZoneListAllocationPolicy>(capacity) { } 198 : List<T, ZoneAllocationPolicy>(capacity) { }
199
200 INLINE(void* operator new(size_t size, Zone* zone));
201 INLINE(void* operator new(size_t size));
194 202
195 // Construct a new ZoneList by copying the elements of the given ZoneList. 203 // Construct a new ZoneList by copying the elements of the given ZoneList.
196 explicit ZoneList(const ZoneList<T>& other) 204 explicit ZoneList(const ZoneList<T>& other, ZoneAllocator alloc)
197 : List<T, ZoneListAllocationPolicy>(other.length()) { 205 : List<T, ZoneAllocationPolicy>(other.length()) {
198 AddAll(other); 206 AddAll(other, alloc);
199 } 207 }
200 208
201 void operator delete(void* pointer) { UNREACHABLE(); } 209 void operator delete(void* pointer) { UNREACHABLE(); }
202 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 210 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
203 }; 211 };
204 212
205 213
206 // ZoneScopes keep track of the current parsing and compilation 214 // ZoneScopes keep track of the current parsing and compilation
207 // nesting and cleans up generated ASTs in the Zone when exiting the 215 // nesting and cleans up generated ASTs in the Zone when exiting the
208 // outer-most scope. 216 // outer-most scope.
(...skipping 16 matching lines...) Expand all
225 private: 233 private:
226 Isolate* isolate_; 234 Isolate* isolate_;
227 ZoneScopeMode mode_; 235 ZoneScopeMode mode_;
228 }; 236 };
229 237
230 238
231 // A zone splay tree. The config type parameter encapsulates the 239 // A zone splay tree. The config type parameter encapsulates the
232 // different configurations of a concrete splay tree (see splay-tree.h). 240 // different configurations of a concrete splay tree (see splay-tree.h).
233 // The tree itself and all its elements are allocated in the Zone. 241 // The tree itself and all its elements are allocated in the Zone.
234 template <typename Config> 242 template <typename Config>
235 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { 243 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> {
236 public: 244 public:
237 ZoneSplayTree() 245 ZoneSplayTree()
238 : SplayTree<Config, ZoneListAllocationPolicy>() {} 246 : SplayTree<Config, ZoneAllocationPolicy>() {}
239 ~ZoneSplayTree(); 247 ~ZoneSplayTree();
240 }; 248 };
241 249
242 250
243 typedef TemplateHashMapImpl<ZoneListAllocationPolicy> ZoneHashMap; 251 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
244 252
245 } } // namespace v8::internal 253 } } // namespace v8::internal
246 254
247 #endif // V8_ZONE_H_ 255 #endif // V8_ZONE_H_
OLDNEW
« src/splay-tree-inl.h ('K') | « src/v8globals.h ('k') | src/zone-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698