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