Chromium Code Reviews| Index: src/heap.h |
| =================================================================== |
| --- src/heap.h (revision 6858) |
| +++ src/heap.h (working copy) |
| @@ -30,6 +30,7 @@ |
| #include <math.h> |
| +#include "list.h" |
| #include "spaces.h" |
| #include "splay-tree-inl.h" |
| #include "v8-counters.h" |
| @@ -2152,6 +2153,102 @@ |
| }; |
| +#if defined(DEBUG) || defined(LIVE_OBJECT_LIST) |
| +// Helper class for tracing paths to a search target Object from all roots. |
| +// The TracePathFrom() method can be used to trace paths from a specific |
| +// object to the search target object. |
| +// |
| +// The "what_to_find" can be kFindFirst or kFindAll. If kFindFirst is |
| +// specified, tracing will stop after the first match. If kFindAll is |
| +// specified, then tracing will be done for all matches. |
| +class PathTracer: public ObjectVisitor { |
|
marklam
2011/02/20 00:41:15
PathTracer used to be called MarkRootVisitor in he
|
| + public: |
| + PathTracer(Object* search_target, |
| + bool search_for_any_global, |
| + int what_to_find, |
| + bool skip_weak_refs) |
| + : search_target_(search_target), |
| + search_for_any_global_(search_for_any_global), |
| + found_target_(false), |
| + what_to_find_(what_to_find), |
| + skip_weak_refs_(skip_weak_refs), |
| + object_stack_(20), |
| + mark_visitor(this), |
| + unmark_visitor(this) {} |
| + |
| + void VisitPointers(Object** start, Object** end) { |
| + bool done = false; |
| + // Visit all HeapObject pointers in [start, end) |
| + for (Object** p = start; !done && (p < end); p++) { |
| + if ((*p)->IsHeapObject()) { |
| + TracePathFrom(p); |
| + done = ((what_to_find_ == kFindFirst) && found_target_); |
|
marklam
2011/02/20 00:41:15
I added an optimization to bail here if we've alre
|
| + } |
| + } |
| + } |
| + |
| + void TracePathFrom(Object** root); |
|
marklam
2011/02/20 00:41:15
TracePathFrom() used to be called MarkRootObjectRe
|
| + |
| + bool found() const { return found_target_; } |
| + |
| + // Values for the "what_to_find" argument of the constructor. |
| + static const int kFindFirst = 1; // Will stop the search after first match. |
| + static const int kFindAll = 0; // Will find all matches. |
| + |
| + protected: |
| + class MarkVisitor: public ObjectVisitor { |
|
marklam
2011/02/20 00:41:15
MarkVisitor used to be called MarkObjectVisitor in
|
| + public: |
| + explicit MarkVisitor(PathTracer* tracer) : tracer_(tracer) {} |
| + void VisitPointers(Object** start, Object** end) { |
| + // Scan all HeapObject pointers in [start, end) |
| + for (Object** p = start; !tracer_->found() && (p < end); p++) { |
|
marklam
2011/02/20 00:41:15
The check for !tracer->found() is an optimization
|
| + if ((*p)->IsHeapObject()) |
| + tracer_->MarkRecursively(p); |
| + } |
| + } |
| + |
| + private: |
| + PathTracer* tracer_; |
| + }; |
| + |
| + |
| + class UnmarkVisitor: public ObjectVisitor { |
|
marklam
2011/02/20 00:41:15
UnmarkVisitor used to be called UnmarkObjectVisito
|
| + public: |
| + explicit UnmarkVisitor(PathTracer* tracer) : tracer_(tracer) {} |
| + void VisitPointers(Object** start, Object** end) { |
| + // Scan all HeapObject pointers in [start, end) |
| + for (Object** p = start; p < end; p++) { |
| + if ((*p)->IsHeapObject()) |
| + tracer_->UnmarkRecursively(p); |
| + } |
| + } |
| + |
| + private: |
| + PathTracer* tracer_; |
| + }; |
| + |
| + PathTracer(); |
| + |
| + void MarkRecursively(Object** p); |
|
marklam
2011/02/20 00:41:15
MarkRecursively() used to be called MarkObjectRecu
|
| + void UnmarkRecursively(Object** p); |
|
marklam
2011/02/20 00:41:15
UnmarkRecursively() used to be called UnmarkObject
|
| + virtual void ProcessResults(); |
| + |
| + // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. |
| + static const int kMarkTag = 2; |
| + |
| + Object* search_target_; |
| + bool search_for_any_global_; |
| + bool found_target_; |
| + bool what_to_find_; |
| + bool skip_weak_refs_; |
| + List<Object*> object_stack_; |
|
marklam
2011/02/20 00:41:15
search_target_, search_for_any_global_, found_targ
|
| + |
| + MarkVisitor mark_visitor; |
| + UnmarkVisitor unmark_visitor; |
|
marklam
2011/02/20 00:41:15
There used to be global static instances of these
|
| +}; |
| +#endif // DEBUG || LIVE_OBJECT_LIST |
| + |
| + |
| } } // namespace v8::internal |
| #endif // V8_HEAP_H_ |