OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_VISITING_H_ | 5 #ifndef V8_OBJECTS_VISITING_H_ |
6 #define V8_OBJECTS_VISITING_H_ | 6 #define V8_OBJECTS_VISITING_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/heap/heap.h" | 9 #include "src/heap/heap.h" |
10 #include "src/heap/spaces.h" | 10 #include "src/heap/spaces.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 } | 184 } |
185 | 185 |
186 private: | 186 private: |
187 base::AtomicWord callbacks_[StaticVisitorBase::kVisitorIdCount]; | 187 base::AtomicWord callbacks_[StaticVisitorBase::kVisitorIdCount]; |
188 }; | 188 }; |
189 | 189 |
190 | 190 |
191 template <typename StaticVisitor, typename BodyDescriptor, typename ReturnType> | 191 template <typename StaticVisitor, typename BodyDescriptor, typename ReturnType> |
192 class FlexibleBodyVisitor : public AllStatic { | 192 class FlexibleBodyVisitor : public AllStatic { |
193 public: | 193 public: |
194 INLINE(static ReturnType Visit(Map* map, HeapObject* object)) { | 194 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object) { |
195 int object_size = BodyDescriptor::SizeOf(map, object); | 195 int object_size = BodyDescriptor::SizeOf(map, object); |
196 BodyDescriptor::template IterateBody<StaticVisitor>(object, object_size); | 196 BodyDescriptor::template IterateBody<StaticVisitor>(object, object_size); |
197 return static_cast<ReturnType>(object_size); | 197 return static_cast<ReturnType>(object_size); |
198 } | 198 } |
199 | 199 |
200 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object, | |
ulan
2015/11/12 12:27:27
Is this leftover from the previous patch?
| |
201 StaticVisitor* v) { | |
202 int object_size = BodyDescriptor::SizeOf(map, object); | |
203 BodyDescriptor::template IterateBody(object, object_size, v); | |
204 return static_cast<ReturnType>(object_size); | |
205 } | |
206 | |
200 // This specialization is only suitable for objects containing pointer fields. | 207 // This specialization is only suitable for objects containing pointer fields. |
201 template <int object_size> | 208 template <int object_size> |
202 static inline ReturnType VisitSpecialized(Map* map, HeapObject* object) { | 209 V8_INLINE static ReturnType VisitSpecialized(Map* map, HeapObject* object) { |
203 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); | 210 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); |
204 DCHECK(!FLAG_unbox_double_fields || map->HasFastPointerLayout()); | 211 DCHECK(!FLAG_unbox_double_fields || map->HasFastPointerLayout()); |
205 StaticVisitor::VisitPointers( | 212 BodyDescriptor::template IteratePointers<StaticVisitor>( |
206 object->GetHeap(), object, | 213 object->GetHeap(), object, BodyDescriptor::kStartOffset, object_size); |
207 HeapObject::RawField(object, BodyDescriptor::kStartOffset), | 214 return static_cast<ReturnType>(object_size); |
208 HeapObject::RawField(object, object_size)); | 215 } |
216 | |
217 // This specialization is only suitable for objects containing pointer fields. | |
218 template <int object_size> | |
219 V8_INLINE static ReturnType VisitSpecialized(Map* map, HeapObject* object, | |
220 StaticVisitor* v) { | |
221 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); | |
222 DCHECK(!FLAG_unbox_double_fields || map->HasFastPointerLayout()); | |
223 BodyDescriptor::template IteratePointers( | |
224 object, BodyDescriptor::kStartOffset, object_size, v); | |
209 return static_cast<ReturnType>(object_size); | 225 return static_cast<ReturnType>(object_size); |
210 } | 226 } |
211 }; | 227 }; |
212 | 228 |
213 | 229 |
214 template <typename StaticVisitor, typename BodyDescriptor, typename ReturnType> | 230 template <typename StaticVisitor, typename BodyDescriptor, typename ReturnType> |
215 class FixedBodyVisitor : public AllStatic { | 231 class FixedBodyVisitor : public AllStatic { |
216 public: | 232 public: |
217 INLINE(static ReturnType Visit(Map* map, HeapObject* object)) { | 233 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object) { |
218 BodyDescriptor::template IterateBody<StaticVisitor>(object); | 234 BodyDescriptor::template IterateBody<StaticVisitor>(object); |
219 return static_cast<ReturnType>(BodyDescriptor::kSize); | 235 return static_cast<ReturnType>(BodyDescriptor::kSize); |
220 } | 236 } |
237 | |
238 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object, | |
239 StaticVisitor* v) { | |
240 BodyDescriptor::template IterateBody(object, v); | |
241 return static_cast<ReturnType>(BodyDescriptor::kSize); | |
242 } | |
221 }; | 243 }; |
222 | 244 |
223 | 245 |
246 template <typename StaticVisitor, typename BodyDescriptor, typename ReturnType> | |
247 class DataBodyVisitor { | |
248 public: | |
249 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object) { | |
250 int object_size = BodyDescriptor::SizeOf(map, object); | |
251 return static_cast<ReturnType>(object_size); | |
252 } | |
253 | |
254 V8_INLINE static ReturnType Visit(Map* map, HeapObject* object, | |
255 StaticVisitor* v) { | |
256 int object_size = BodyDescriptor::SizeOf(map, object); | |
257 return static_cast<ReturnType>(object_size); | |
258 } | |
259 | |
260 template <int object_size> | |
261 V8_INLINE static ReturnType VisitSpecialized(Map* map, HeapObject* object) { | |
262 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); | |
263 return static_cast<ReturnType>(object_size); | |
264 } | |
265 | |
266 template <int object_size> | |
267 V8_INLINE static ReturnType VisitSpecialized(Map* map, HeapObject* object, | |
268 StaticVisitor* v) { | |
269 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); | |
270 return static_cast<ReturnType>(object_size); | |
271 } | |
272 }; | |
273 | |
274 | |
224 // Base class for visitors used for a linear new space iteration. | 275 // Base class for visitors used for a linear new space iteration. |
225 // IterateBody returns size of visited object. | 276 // IterateBody returns size of visited object. |
226 // Certain types of objects (i.e. Code objects) are not handled | 277 // Certain types of objects (i.e. Code objects) are not handled |
227 // by dispatch table of this visitor because they cannot appear | 278 // by dispatch table of this visitor because they cannot appear |
228 // in the new space. | 279 // in the new space. |
229 // | 280 // |
230 // This class is intended to be used in the following way: | 281 // This class is intended to be used in the following way: |
231 // | 282 // |
232 // class SomeVisitor : public StaticNewSpaceVisitor<SomeVisitor> { | 283 // class SomeVisitor : public StaticNewSpaceVisitor<SomeVisitor> { |
233 // ... | 284 // ... |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 | 340 |
290 INLINE(static int VisitFreeSpace(Map* map, HeapObject* object)) { | 341 INLINE(static int VisitFreeSpace(Map* map, HeapObject* object)) { |
291 return FreeSpace::cast(object)->size(); | 342 return FreeSpace::cast(object)->size(); |
292 } | 343 } |
293 | 344 |
294 INLINE(static int VisitJSArrayBuffer(Map* map, HeapObject* object)); | 345 INLINE(static int VisitJSArrayBuffer(Map* map, HeapObject* object)); |
295 INLINE(static int VisitJSTypedArray(Map* map, HeapObject* object)); | 346 INLINE(static int VisitJSTypedArray(Map* map, HeapObject* object)); |
296 INLINE(static int VisitJSDataView(Map* map, HeapObject* object)); | 347 INLINE(static int VisitJSDataView(Map* map, HeapObject* object)); |
297 INLINE(static int VisitBytecodeArray(Map* map, HeapObject* object)); | 348 INLINE(static int VisitBytecodeArray(Map* map, HeapObject* object)); |
298 | 349 |
299 class DataObjectVisitor { | 350 typedef DataBodyVisitor<StaticVisitor, StructBodyDescriptor, int> |
300 public: | 351 DataObjectVisitor; |
301 template <int object_size> | |
302 static inline int VisitSpecialized(Map* map, HeapObject* object) { | |
303 return object_size; | |
304 } | |
305 | |
306 INLINE(static int Visit(Map* map, HeapObject* object)) { | |
307 return map->instance_size(); | |
308 } | |
309 }; | |
310 | 352 |
311 typedef FlexibleBodyVisitor<StaticVisitor, StructBodyDescriptor, int> | 353 typedef FlexibleBodyVisitor<StaticVisitor, StructBodyDescriptor, int> |
312 StructVisitor; | 354 StructVisitor; |
313 | 355 |
314 typedef FlexibleBodyVisitor<StaticVisitor, JSObject::BodyDescriptor, int> | 356 typedef FlexibleBodyVisitor<StaticVisitor, JSObject::BodyDescriptor, int> |
315 JSObjectVisitor; | 357 JSObjectVisitor; |
316 | 358 |
317 typedef int (*Callback)(Map* map, HeapObject* object); | 359 typedef int (*Callback)(Map* map, HeapObject* object); |
318 | 360 |
319 static VisitorDispatchTable<Callback> table_; | 361 static VisitorDispatchTable<Callback> table_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 INLINE(static bool IsFlushable(Heap* heap, JSFunction* function)); | 436 INLINE(static bool IsFlushable(Heap* heap, JSFunction* function)); |
395 INLINE(static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info)); | 437 INLINE(static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info)); |
396 | 438 |
397 // Helpers used by code flushing support that visit pointer fields and treat | 439 // Helpers used by code flushing support that visit pointer fields and treat |
398 // references to code objects either strongly or weakly. | 440 // references to code objects either strongly or weakly. |
399 static void VisitSharedFunctionInfoStrongCode(Heap* heap, HeapObject* object); | 441 static void VisitSharedFunctionInfoStrongCode(Heap* heap, HeapObject* object); |
400 static void VisitSharedFunctionInfoWeakCode(Heap* heap, HeapObject* object); | 442 static void VisitSharedFunctionInfoWeakCode(Heap* heap, HeapObject* object); |
401 static void VisitJSFunctionStrongCode(Map* map, HeapObject* object); | 443 static void VisitJSFunctionStrongCode(Map* map, HeapObject* object); |
402 static void VisitJSFunctionWeakCode(Map* map, HeapObject* object); | 444 static void VisitJSFunctionWeakCode(Map* map, HeapObject* object); |
403 | 445 |
404 class DataObjectVisitor { | 446 typedef DataBodyVisitor<StaticVisitor, StructBodyDescriptor, void> |
405 public: | 447 DataObjectVisitor; |
406 template <int size> | |
407 static inline void VisitSpecialized(Map* map, HeapObject* object) {} | |
408 | |
409 INLINE(static void Visit(Map* map, HeapObject* object)) {} | |
410 }; | |
411 | 448 |
412 typedef FlexibleBodyVisitor<StaticVisitor, FixedArray::BodyDescriptor, void> | 449 typedef FlexibleBodyVisitor<StaticVisitor, FixedArray::BodyDescriptor, void> |
413 FixedArrayVisitor; | 450 FixedArrayVisitor; |
414 | 451 |
415 typedef FlexibleBodyVisitor<StaticVisitor, JSObject::BodyDescriptor, void> | 452 typedef FlexibleBodyVisitor<StaticVisitor, JSObject::BodyDescriptor, void> |
416 JSObjectVisitor; | 453 JSObjectVisitor; |
417 | 454 |
418 typedef FlexibleBodyVisitor<StaticVisitor, StructBodyDescriptor, void> | 455 typedef FlexibleBodyVisitor<StaticVisitor, StructBodyDescriptor, void> |
419 StructObjectVisitor; | 456 StructObjectVisitor; |
420 | 457 |
(...skipping 15 matching lines...) Expand all Loading... | |
436 // the next element. Given the head of the list, this function removes dead | 473 // the next element. Given the head of the list, this function removes dead |
437 // elements from the list and if requested records slots for next-element | 474 // elements from the list and if requested records slots for next-element |
438 // pointers. The template parameter T is a WeakListVisitor that defines how to | 475 // pointers. The template parameter T is a WeakListVisitor that defines how to |
439 // access the next-element pointers. | 476 // access the next-element pointers. |
440 template <class T> | 477 template <class T> |
441 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); | 478 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); |
442 } // namespace internal | 479 } // namespace internal |
443 } // namespace v8 | 480 } // namespace v8 |
444 | 481 |
445 #endif // V8_OBJECTS_VISITING_H_ | 482 #endif // V8_OBJECTS_VISITING_H_ |
OLD | NEW |