OLD | NEW |
---|---|
(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. | |
Ivan Posva
2014/05/02 22:20:41
No allocation and no GC is allowed...
koda
2014/05/02 22:45:19
Actually, the comment is obsolete, since I moved t
| |
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_ | |
OLD | NEW |