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

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: Make TemplateHashMapImpl consistent with the rest of the approach. 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
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 // implementation to allocate ZoneLists and their elements in the
169 // Zone.
170 class ZoneListAllocationPolicy {
171 public: 168 public:
172 // Allocate 'size' bytes of memory in the zone. 169 INLINE(void* New(int size));
173 static void* New(int size);
174
175 // De-allocation attempts are silently ignored.
176 static void Delete(void* p) { }
177 }; 170 };
178 171
179 172
173 class ZoneDeallocator {
174 public:
175 INLINE(void Delete(void* ptr)) { }
176 };
177
178
179 struct ZoneAllocationPolicy {
180 typedef ZoneAllocator Alloc;
danno 2012/05/25 11:03:37 Please use the full words for "Allocator" and "Dea
181 typedef ZoneDeallocator Dealloc;
182 };
183
180 // ZoneLists are growable lists with constant-time access to the 184 // ZoneLists are growable lists with constant-time access to the
181 // elements. The list itself and all its elements are allocated in the 185 // elements. The list itself and all its elements are allocated in the
182 // Zone. ZoneLists cannot be deleted individually; you can delete all 186 // Zone. ZoneLists cannot be deleted individually; you can delete all
183 // objects in the Zone by calling Zone::DeleteAll(). 187 // objects in the Zone by calling Zone::DeleteAll().
184 template<typename T> 188 template<typename T>
185 class ZoneList: public List<T, ZoneListAllocationPolicy> { 189 class ZoneList: public List<T, ZoneAllocationPolicy> {
186 public: 190 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 191 // Construct a new ZoneList with the given capacity; the length is
191 // always zero. The capacity must be non-negative. 192 // always zero. The capacity must be non-negative.
192 explicit ZoneList(int capacity) 193 explicit ZoneList(int capacity)
193 : List<T, ZoneListAllocationPolicy>(capacity) { } 194 : List<T, ZoneAllocationPolicy>(capacity) { }
195
196 INLINE(void* operator new(size_t size, Zone* zone));
197 INLINE(void* operator new(size_t size));
194 198
195 // Construct a new ZoneList by copying the elements of the given ZoneList. 199 // Construct a new ZoneList by copying the elements of the given ZoneList.
196 explicit ZoneList(const ZoneList<T>& other) 200 explicit ZoneList(const ZoneList<T>& other, ZoneAllocator alloc)
197 : List<T, ZoneListAllocationPolicy>(other.length()) { 201 : List<T, ZoneAllocationPolicy>(other.length()) {
198 AddAll(other); 202 AddAll(other, alloc);
199 } 203 }
200 204
201 void operator delete(void* pointer) { UNREACHABLE(); } 205 void operator delete(void* pointer) { UNREACHABLE(); }
202 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 206 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
203 }; 207 };
204 208
205 209
206 // ZoneScopes keep track of the current parsing and compilation 210 // ZoneScopes keep track of the current parsing and compilation
207 // nesting and cleans up generated ASTs in the Zone when exiting the 211 // nesting and cleans up generated ASTs in the Zone when exiting the
208 // outer-most scope. 212 // outer-most scope.
(...skipping 16 matching lines...) Expand all
225 private: 229 private:
226 Isolate* isolate_; 230 Isolate* isolate_;
227 ZoneScopeMode mode_; 231 ZoneScopeMode mode_;
228 }; 232 };
229 233
230 234
231 // A zone splay tree. The config type parameter encapsulates the 235 // A zone splay tree. The config type parameter encapsulates the
232 // different configurations of a concrete splay tree (see splay-tree.h). 236 // different configurations of a concrete splay tree (see splay-tree.h).
233 // The tree itself and all its elements are allocated in the Zone. 237 // The tree itself and all its elements are allocated in the Zone.
234 template <typename Config> 238 template <typename Config>
235 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { 239 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> {
236 public: 240 public:
237 ZoneSplayTree() 241 ZoneSplayTree()
238 : SplayTree<Config, ZoneListAllocationPolicy>() {} 242 : SplayTree<Config, ZoneAllocationPolicy>() {}
239 ~ZoneSplayTree(); 243 ~ZoneSplayTree();
240 }; 244 };
241 245
242 246
243 typedef TemplateHashMapImpl<ZoneListAllocationPolicy> ZoneHashMap; 247 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
244 248
245 } } // namespace v8::internal 249 } } // namespace v8::internal
246 250
247 #endif // V8_ZONE_H_ 251 #endif // V8_ZONE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698