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

Side by Side Diff: src/zone.h

Issue 10443114: Progress towards making Zones independent of Isolates and Threads. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix build on ia32. 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Address position_; 136 Address position_;
137 Address limit_; 137 Address limit_;
138 138
139 int scope_nesting_; 139 int scope_nesting_;
140 140
141 Segment* segment_head_; 141 Segment* segment_head_;
142 Isolate* isolate_; 142 Isolate* isolate_;
143 }; 143 };
144 144
145 145
146 // The ZoneAllocationPolicy is used to specialize the generic data
147 // structures to allocate themselves and their elements in the Zone.
148 struct ZoneAllocationPolicy {
149 public:
150 ZoneAllocationPolicy(Zone* zone = NULL) : zone_(zone) { }
151 INLINE(void* New(size_t size));
152 INLINE(static void Delete(void *pointer)) { }
153
154 private:
155 Zone* zone_;
danno 2012/06/01 11:29:24 Put this back where it was later in the file. to m
156 };
157
158
146 // ZoneObject is an abstraction that helps define classes of objects 159 // ZoneObject is an abstraction that helps define classes of objects
147 // allocated in the Zone. Use it as a base class; see ast.h. 160 // allocated in the Zone. Use it as a base class; see ast.h.
148 class ZoneObject { 161 class ZoneObject {
149 public: 162 public:
150 // Allocate a new ZoneObject of 'size' bytes in the Zone. 163 // Allocate a new ZoneObject of 'size' bytes in the Zone.
151 INLINE(void* operator new(size_t size)); 164 INLINE(void* operator new(size_t size));
152 INLINE(void* operator new(size_t size, Zone* zone)); 165 INLINE(void* operator new(size_t size, Zone* zone));
153 166
154 // Ideally, the delete operator should be private instead of 167 // Ideally, the delete operator should be private instead of
155 // public, but unfortunately the compiler sometimes synthesizes 168 // public, but unfortunately the compiler sometimes synthesizes
156 // (unused) destructors for classes derived from ZoneObject, which 169 // (unused) destructors for classes derived from ZoneObject, which
157 // require the operator to be visible. MSVC requires the delete 170 // require the operator to be visible. MSVC requires the delete
158 // operator to be public. 171 // operator to be public.
159 172
160 // ZoneObjects should never be deleted individually; use 173 // ZoneObjects should never be deleted individually; use
161 // Zone::DeleteAll() to delete all zone objects in one go. 174 // Zone::DeleteAll() to delete all zone objects in one go.
162 void operator delete(void*, size_t) { UNREACHABLE(); } 175 void operator delete(void*, size_t) { UNREACHABLE(); }
163 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 176 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
164 }; 177 };
165 178
166 179
167 // The ZoneListAllocationPolicy is used to specialize the GenericList
168 // implementation to allocate ZoneLists and their elements in the
169 // Zone.
170 class ZoneListAllocationPolicy {
171 public:
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 };
178
179
180 // ZoneLists are growable lists with constant-time access to the 180 // ZoneLists are growable lists with constant-time access to the
181 // elements. The list itself and all its elements are allocated in the 181 // elements. The list itself and all its elements are allocated in the
182 // Zone. ZoneLists cannot be deleted individually; you can delete all 182 // Zone. ZoneLists cannot be deleted individually; you can delete all
183 // objects in the Zone by calling Zone::DeleteAll(). 183 // objects in the Zone by calling Zone::DeleteAll().
184 template<typename T> 184 template<typename T>
185 class ZoneList: public List<T, ZoneListAllocationPolicy> { 185 class ZoneList: public List<T, ZoneAllocationPolicy> {
186 public: 186 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 187 // Construct a new ZoneList with the given capacity; the length is
191 // always zero. The capacity must be non-negative. 188 // always zero. The capacity must be non-negative.
192 explicit ZoneList(int capacity) 189 explicit ZoneList(int capacity, Zone* zone = NULL)
193 : List<T, ZoneListAllocationPolicy>(capacity) { } 190 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { }
191
192 INLINE(void* operator new(size_t size, Zone* zone));
193 INLINE(void* operator new(size_t size));
194 194
195 // Construct a new ZoneList by copying the elements of the given ZoneList. 195 // Construct a new ZoneList by copying the elements of the given ZoneList.
196 explicit ZoneList(const ZoneList<T>& other) 196 explicit ZoneList(const ZoneList<T>& other, Zone* zone = NULL)
197 : List<T, ZoneListAllocationPolicy>(other.length()) { 197 : List<T, ZoneAllocationPolicy>(other.length(),
198 AddAll(other); 198 ZoneAllocationPolicy(zone)) {
199 AddAll(other, ZoneAllocationPolicy(zone));
200 }
201
202 // We override almost all List's public functions here so that the
danno 2012/06/01 11:29:24 It's not really overriding. You're adding convenie
203 // user's can pass a Zone instead of the (more inconvenient)
204 // ZoneAllocationPolicy.
205 INLINE(void Add(const T& element, Zone* zone = NULL)) {
206 List<T, ZoneAllocationPolicy>::Add(element, ZoneAllocationPolicy(zone));
207 }
208 INLINE(void AddAll(const List<T, ZoneAllocationPolicy>& other,
209 Zone* zone = NULL)) {
210 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone));
211 }
212 INLINE(void AddAll(const Vector<T>& other, Zone* zone = NULL)) {
213 List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone));
214 }
215 INLINE(void InsertAt(int index, const T& element, Zone* zone = NULL)) {
216 List<T, ZoneAllocationPolicy>::InsertAt(index, element,
217 ZoneAllocationPolicy(zone));
218 }
219 INLINE(Vector<T> AddBlock(T value, int count, Zone* zone = NULL)) {
220 return List<T, ZoneAllocationPolicy>::AddBlock(value, count,
221 ZoneAllocationPolicy(zone));
222 }
223 INLINE(void Allocate(int length, Zone* zone = NULL)) {
224 List<T, ZoneAllocationPolicy>::Allocate(length, ZoneAllocationPolicy(zone));
225 }
226 INLINE(void Initialize(int capacity, Zone* zone = NULL)) {
227 List<T, ZoneAllocationPolicy>::Initialize(capacity,
228 ZoneAllocationPolicy(zone));
199 } 229 }
200 230
201 void operator delete(void* pointer) { UNREACHABLE(); } 231 void operator delete(void* pointer) { UNREACHABLE(); }
202 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 232 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
203 }; 233 };
204 234
205 235
206 // ZoneScopes keep track of the current parsing and compilation 236 // ZoneScopes keep track of the current parsing and compilation
207 // nesting and cleans up generated ASTs in the Zone when exiting the 237 // nesting and cleans up generated ASTs in the Zone when exiting the
208 // outer-most scope. 238 // outer-most scope.
(...skipping 16 matching lines...) Expand all
225 private: 255 private:
226 Isolate* isolate_; 256 Isolate* isolate_;
227 ZoneScopeMode mode_; 257 ZoneScopeMode mode_;
228 }; 258 };
229 259
230 260
231 // A zone splay tree. The config type parameter encapsulates the 261 // A zone splay tree. The config type parameter encapsulates the
232 // different configurations of a concrete splay tree (see splay-tree.h). 262 // different configurations of a concrete splay tree (see splay-tree.h).
233 // The tree itself and all its elements are allocated in the Zone. 263 // The tree itself and all its elements are allocated in the Zone.
234 template <typename Config> 264 template <typename Config>
235 class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { 265 class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> {
236 public: 266 public:
237 ZoneSplayTree() 267 ZoneSplayTree()
238 : SplayTree<Config, ZoneListAllocationPolicy>() {} 268 : SplayTree<Config, ZoneAllocationPolicy>() {}
239 ~ZoneSplayTree(); 269 ~ZoneSplayTree();
240 }; 270 };
241 271
242 272
243 typedef TemplateHashMapImpl<ZoneListAllocationPolicy> ZoneHashMap; 273 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
244 274
245 } } // namespace v8::internal 275 } } // namespace v8::internal
246 276
247 #endif // V8_ZONE_H_ 277 #endif // V8_ZONE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698