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/heap.h" | |
9 | |
10 namespace dart { | |
11 | |
12 class Isolate; | |
13 class RawObject; | |
14 | |
15 // Utility to traverse the object graph in an ordered fashion. | |
16 // Example uses: | |
17 // - find a retaining path from the isolate roots to a particular object, or | |
18 // - determine how much memory is retained by some particular object(s). | |
19 class ObjectGraph { | |
20 public: | |
21 class Stack; | |
22 | |
23 // Allows climbing the search tree all the way to the root. | |
24 class StackIterator { | |
25 public: | |
26 // The object this iterator currently points to. | |
27 RawObject* Get() const; | |
28 // Returns false if there is no parent. | |
29 bool MoveToParent(); | |
30 private: | |
31 StackIterator(const Stack* stack, intptr_t index) | |
32 : stack_(stack), index_(index) { } | |
33 const Stack* stack_; | |
34 intptr_t index_; | |
35 friend class ObjectGraph::Stack; | |
36 DISALLOW_IMPLICIT_CONSTRUCTORS(StackIterator); | |
37 }; | |
38 | |
39 class Visitor { | |
40 public: | |
41 // Directs how the search should continue after visiting an object. | |
42 enum Direction { | |
43 kProceed, // Recurse on this object's pointers. | |
44 kBacktrack, // Ignore this object's pointers. | |
45 kAbort, // Terminate the entire search immediately. | |
46 }; | |
47 virtual ~Visitor() { } | |
48 // Visits the object pointed to by *it. The iterator is only valid | |
49 // during this call. | |
50 virtual Direction VisitObject(StackIterator* it) = 0; | |
51 }; | |
52 | |
53 // No GC is allowed during the lifetime of an ObjectGraph instance. | |
54 explicit ObjectGraph(Isolate* isolate); | |
55 ~ObjectGraph(); | |
56 | |
57 // Visits all strongly reachable objects in the isolate's heap, in a | |
58 // pre-order, depth first traversal. | |
59 void IterateObjects(Visitor* visitor); | |
60 | |
61 // Like 'IterateObjects', but restricted to objects reachable from 'root' | |
62 // (including 'root' itself). | |
63 void IterateObjectsFrom(RawObject* root, Visitor* visitor); | |
64 | |
65 private: | |
66 Isolate* isolate_; | |
67 NoGCScope no_gc_scope_; | |
Cutch
2014/05/02 18:23:42
Should this NoGCScope be here or inside the Iterat
koda
2014/05/02 18:51:34
Done. Also changed IterateObjectsFrom to take a ha
| |
68 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectGraph); | |
69 }; | |
70 | |
71 } // namespace dart | |
72 | |
73 #endif // VM_OBJECT_GRAPH_H_ | |
OLD | NEW |