| 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/embedder-tracing.h" | 9 #include "src/heap/embedder-tracing.h" |
| 10 #include "src/heap/heap.h" | 10 #include "src/heap/heap.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // | 388 // |
| 389 // class SomeVisitor : public HeapVisitor<ResultType, SomeVisitor> { | 389 // class SomeVisitor : public HeapVisitor<ResultType, SomeVisitor> { |
| 390 // ... | 390 // ... |
| 391 // } | 391 // } |
| 392 // | 392 // |
| 393 // This is an example of Curiously recurring template pattern. | 393 // This is an example of Curiously recurring template pattern. |
| 394 // TODO(ulan): replace static visitors with the HeapVisitor. | 394 // TODO(ulan): replace static visitors with the HeapVisitor. |
| 395 template <typename ResultType, typename ConcreteVisitor> | 395 template <typename ResultType, typename ConcreteVisitor> |
| 396 class HeapVisitor : public ObjectVisitor { | 396 class HeapVisitor : public ObjectVisitor { |
| 397 public: | 397 public: |
| 398 ResultType IterateBody(HeapObject* object); | 398 ResultType Visit(HeapObject* object); |
| 399 | 399 |
| 400 protected: | 400 protected: |
| 401 // A guard predicate for visiting the object. |
| 402 // If it returns false then the default implementations of the Visit* |
| 403 // functions bailout from iterating the object pointers. |
| 404 virtual bool ShouldVisit(HeapObject* object); |
| 405 // A callback for visiting the map pointer in the object header. |
| 406 virtual void VisitMapPointer(HeapObject* host, HeapObject** map); |
| 407 |
| 401 #define VISIT(type) virtual ResultType Visit##type(Map* map, type* object); | 408 #define VISIT(type) virtual ResultType Visit##type(Map* map, type* object); |
| 402 TYPED_VISITOR_ID_LIST(VISIT) | 409 TYPED_VISITOR_ID_LIST(VISIT) |
| 403 #undef VISIT | 410 #undef VISIT |
| 404 virtual ResultType VisitShortcutCandidate(Map* map, ConsString* object); | 411 virtual ResultType VisitShortcutCandidate(Map* map, ConsString* object); |
| 405 virtual ResultType VisitNativeContext(Map* map, Context* object); | 412 virtual ResultType VisitNativeContext(Map* map, Context* object); |
| 406 virtual ResultType VisitDataObject(Map* map, HeapObject* object); | 413 virtual ResultType VisitDataObject(Map* map, HeapObject* object); |
| 407 virtual ResultType VisitJSObjectFast(Map* map, JSObject* object); | 414 virtual ResultType VisitJSObjectFast(Map* map, JSObject* object); |
| 408 virtual ResultType VisitJSApiObject(Map* map, JSObject* object); | 415 virtual ResultType VisitJSApiObject(Map* map, JSObject* object); |
| 409 virtual ResultType VisitStruct(Map* map, HeapObject* object); | 416 virtual ResultType VisitStruct(Map* map, HeapObject* object); |
| 410 virtual ResultType VisitFreeSpace(Map* map, FreeSpace* object); | 417 virtual ResultType VisitFreeSpace(Map* map, FreeSpace* object); |
| 411 }; | 418 }; |
| 412 | 419 |
| 413 class WeakObjectRetainer; | 420 class WeakObjectRetainer; |
| 414 | 421 |
| 415 // A weak list is single linked list where each element has a weak pointer to | 422 // A weak list is single linked list where each element has a weak pointer to |
| 416 // the next element. Given the head of the list, this function removes dead | 423 // the next element. Given the head of the list, this function removes dead |
| 417 // elements from the list and if requested records slots for next-element | 424 // elements from the list and if requested records slots for next-element |
| 418 // pointers. The template parameter T is a WeakListVisitor that defines how to | 425 // pointers. The template parameter T is a WeakListVisitor that defines how to |
| 419 // access the next-element pointers. | 426 // access the next-element pointers. |
| 420 template <class T> | 427 template <class T> |
| 421 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); | 428 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); |
| 422 } // namespace internal | 429 } // namespace internal |
| 423 } // namespace v8 | 430 } // namespace v8 |
| 424 | 431 |
| 425 #endif // V8_OBJECTS_VISITING_H_ | 432 #endif // V8_OBJECTS_VISITING_H_ |
| OLD | NEW |