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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef VM_OBJECT_GRAPH_H_
6 #define VM_OBJECT_GRAPH_H_
7
8 #include "vm/object.h"
9
10 namespace dart {
11
12 class Isolate;
13
14 // Utility to traverse the object graph in an ordered fashion.
15 // Example uses:
16 // - find a retaining path from the isolate roots to a particular object, or
17 // - determine how much memory is retained by some particular object(s).
18 class ObjectGraph {
19 public:
20 class Stack;
21
22 // Allows climbing the search tree all the way to the root.
23 class StackIterator {
24 public:
25 // The object this iterator currently points to.
26 RawObject* Get() const;
27 // Returns false if there is no parent.
28 bool MoveToParent();
29 private:
30 StackIterator(const Stack* stack, intptr_t index)
31 : stack_(stack), index_(index) { }
32 const Stack* stack_;
33 intptr_t index_;
34 friend class ObjectGraph::Stack;
35 DISALLOW_IMPLICIT_CONSTRUCTORS(StackIterator);
36 };
37
38 class Visitor {
39 public:
40 // Directs how the search should continue after visiting an object.
41 enum Direction {
42 kProceed, // Recurse on this object's pointers.
43 kBacktrack, // Ignore this object's pointers.
44 kAbort, // Terminate the entire search immediately.
45 };
46 virtual ~Visitor() { }
47 // Visits the object pointed to by *it. The iterator is only valid
48 // during this call. This method must not allocate from the heap.
49 virtual Direction VisitObject(StackIterator* it) = 0;
50 };
51
52 // No GC is allowed during the lifetime of an ObjectGraph instance.
53 explicit ObjectGraph(Isolate* isolate);
54 ~ObjectGraph();
55
56 // Visits all strongly reachable objects in the isolate's heap, in a
57 // pre-order, depth first traversal.
58 void IterateObjects(Visitor* visitor);
59
60 // Like 'IterateObjects', but restricted to objects reachable from 'root'
61 // (including 'root' itself).
62 void IterateObjectsFrom(const Object& root, Visitor* visitor);
63
64 private:
65 Isolate* isolate_;
66 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGraph);
67 };
68
69 } // namespace dart
70
71 #endif // VM_OBJECT_GRAPH_H_
OLDNEW
« 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