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

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') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.h
===================================================================
--- src/heap.h (revision 6872)
+++ src/heap.h (working copy)
@@ -30,6 +30,8 @@
#include <math.h>
+#include "globals.h"
+#include "list.h"
#include "spaces.h"
#include "splay-tree-inl.h"
#include "v8-counters.h"
@@ -2152,6 +2154,78 @@
};
+#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.
+class PathTracer: public ObjectVisitor {
mnaganov (inactive) 2011/02/21 18:08:28 nit: space needed after PathTracer
marklam 2011/02/22 03:11:15 Done. I've seen this done both ways throughout th
+ public:
+ enum WhatToFind {
+ FIND_ALL, // Will find all matches.
+ FIND_FIRST // Will stop the search after first match.
+ };
+
+ // For the WhatToFind arg, if FIND_FIRST is specified, tracing will stop
+ // after the first match. If FIND_ALL is specified, then tracing will be
+ // done for all matches.
+ PathTracer(Object* search_target,
mnaganov (inactive) 2011/02/21 18:08:28 I have an idea about constructor args. Create a co
marklam 2011/02/22 03:11:15 Done.
+ bool search_for_any_global,
+ WhatToFind what_to_find,
+ bool skip_weak_refs)
mnaganov (inactive) 2011/02/21 18:08:28 Excuse me for being annoying but I would prefer us
marklam 2011/02/22 03:11:15 Done. Sorry for missing this one the first time a
+ : search_target_(search_target),
+ search_for_any_global_(search_for_any_global),
+ found_target_(false),
+ found_target_in_trace_(false),
+ what_to_find_(what_to_find),
+ skip_weak_refs_(skip_weak_refs),
+ object_stack_(20),
+ no_alloc() {}
+
+ void VisitPointers(Object** start, Object** end) {
mnaganov (inactive) 2011/02/21 18:08:28 Does this method need to be inline?
marklam 2011/02/22 03:11:15 Done. This is a virtual method override (and I th
mnaganov (inactive) 2011/02/22 10:12:01 I'm just against having too much code in .h file.
+ bool done = ((what_to_find_ == FIND_FIRST) && 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_ == FIND_FIRST) && found_target_);
+ }
+ }
+ }
+
+ void Reset() {
mnaganov (inactive) 2011/02/21 18:08:28 Does this method need to be inline?
marklam 2011/02/22 03:11:15 Done. It doesn't have to be, but I figured it was
+ found_target_ = false;
+ object_stack_.Clear();
+ }
+ void TracePathFrom(Object** root);
+
+ bool found() const { return found_target_; }
+
+ protected:
mnaganov (inactive) 2011/02/21 18:08:28 I'd prefer to use 'private:' in all cases, except
marklam 2011/02/22 03:11:15 I do intend for this class to be subclassed. That
mnaganov (inactive) 2011/02/22 10:12:01 OK, I just wanted to be sure. Sorry, I forgot the
+ class MarkVisitor;
+ class UnmarkVisitor;
+
+ void MarkRecursively(Object** p, MarkVisitor* mark_visitor);
+ void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor);
+ 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_;
+ WhatToFind what_to_find_;
+ bool skip_weak_refs_;
+ List<Object*> object_stack_;
+
+ AssertNoAllocation no_alloc; // i.e. no gc allowed.
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer);
+};
+#endif // DEBUG || LIVE_OBJECT_LIST
+
+
} } // namespace v8::internal
#endif // V8_HEAP_H_
« no previous file with comments | « no previous file | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698