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

Unified Diff: runtime/vm/object_graph.h

Issue 266643002: Object graph visitor: general depth-first search. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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
Index: runtime/vm/object_graph.h
===================================================================
--- runtime/vm/object_graph.h (revision 0)
+++ runtime/vm/object_graph.h (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef VM_OBJECT_GRAPH_H_
+#define VM_OBJECT_GRAPH_H_
+
+#include "vm/object.h"
+
+namespace dart {
+
+class Isolate;
+
+// Utility to traverse the object graph in an ordered fashion.
+// Example uses:
+// - find a retaining path from the isolate roots to a particular object, or
+// - determine how much memory is retained by some particular object(s).
+class ObjectGraph {
+ public:
+ class Stack;
+
+ // Allows climbing the search tree all the way to the root.
+ class StackIterator {
+ public:
+ // The object this iterator currently points to.
+ RawObject* Get() const;
+ // Returns false if there is no parent.
+ bool MoveToParent();
+ private:
+ StackIterator(const Stack* stack, intptr_t index)
+ : stack_(stack), index_(index) { }
+ const Stack* stack_;
+ intptr_t index_;
+ friend class ObjectGraph::Stack;
+ DISALLOW_IMPLICIT_CONSTRUCTORS(StackIterator);
+ };
+
+ class Visitor {
+ public:
+ // Directs how the search should continue after visiting an object.
+ enum Direction {
+ kProceed, // Recurse on this object's pointers.
+ kBacktrack, // Ignore this object's pointers.
+ kAbort, // Terminate the entire search immediately.
+ };
+ virtual ~Visitor() { }
+ // Visits the object pointed to by *it. The iterator is only valid
+ // during this call. This method must not allocate from the heap.
+ virtual Direction VisitObject(StackIterator* it) = 0;
+ };
+
+ // No GC is allowed during the lifetime of an ObjectGraph instance.
+ explicit ObjectGraph(Isolate* isolate);
+ ~ObjectGraph();
+
+ // Visits all strongly reachable objects in the isolate's heap, in a
+ // pre-order, depth first traversal.
+ void IterateObjects(Visitor* visitor);
+
+ // Like 'IterateObjects', but restricted to objects reachable from 'root'
+ // (including 'root' itself).
+ void IterateObjectsFrom(const Object& root, Visitor* visitor);
+
+ private:
+ Isolate* isolate_;
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGraph);
+};
+
+} // namespace dart
+
+#endif // VM_OBJECT_GRAPH_H_
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/object_graph.cc » ('j') | runtime/vm/object_graph.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698