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

Unified Diff: src/heap.h

Issue 6541044: Refactored PathTracer in heap.cc.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/heap.cc » ('j') | src/heap.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,108 @@
};
+#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 {
+ public:
+ PathTracer(Object* search_target,
mnaganov (inactive) 2011/02/21 10:59:46 When using raw pointers, you should instantiate As
marklam 2011/02/21 17:45:15 Done. Thanks for pointing this out. Since PathTr
+ bool search_for_any_global,
mnaganov (inactive) 2011/02/21 10:59:46 I have a concern about argument types. I'd suggest
marklam 2011/02/21 17:45:15 Done. I had mistakenly believed that enums are no
+ int what_to_find,
+ bool skip_weak_refs)
+ : search_target_(search_target),
+ search_for_any_global_(search_for_any_global),
+ found_target_(false),
+ found_target_in_trace_(false),
marklam 2011/02/20 08:23:07 There's a need to distinguish found_target_in_trac
+ 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 = ((what_to_find_ == kFindFirst) && found_target_);
+ // 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_);
+ }
+ }
+ }
+
+ void Reset() {
+ found_target_ = false;
+ object_stack_.Clear();
+ }
+ void TracePathFrom(Object** root);
+
+ bool found() const { return found_target_; }
+
+ // Values for the "what_to_find" argument of the constructor.
mnaganov (inactive) 2011/02/21 10:59:46 As a bonus of using enums, you will not need comme
marklam 2011/02/21 17:45:15 Done.
+ 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 {
mnaganov (inactive) 2011/02/21 10:59:46 Does this really need to be put in the header file
marklam 2011/02/21 17:45:15 Done. I moved this into heap.cc, and instantiate
+ 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++) {
+ if ((*p)->IsHeapObject())
+ tracer_->MarkRecursively(p);
+ }
+ }
+
+ private:
+ PathTracer* tracer_;
+ };
+
+
+ class UnmarkVisitor: public ObjectVisitor {
+ 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();
mnaganov (inactive) 2011/02/21 10:59:46 I think what you need here is DISALLOW_IMPLICIT_CO
marklam 2011/02/21 17:45:15 Done.
+
+ void MarkRecursively(Object** p);
+ void UnmarkRecursively(Object** p);
+ 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 found_target_in_trace_;
+ bool what_to_find_;
+ bool skip_weak_refs_;
+ List<Object*> object_stack_;
+
+ MarkVisitor mark_visitor;
+ UnmarkVisitor unmark_visitor;
+};
+#endif // DEBUG || LIVE_OBJECT_LIST
+
+
} } // namespace v8::internal
#endif // V8_HEAP_H_
« no previous file with comments | « no previous file | src/heap.cc » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698