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

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

Powered by Google App Engine
This is Rietveld 408576698