Chromium Code Reviews| Index: runtime/vm/object_graph.cc |
| =================================================================== |
| --- runtime/vm/object_graph.cc (revision 36049) |
| +++ runtime/vm/object_graph.cc (working copy) |
| @@ -207,4 +207,42 @@ |
| return size_total - size_excluding_class; |
| } |
| + |
| +class RetainingPathVisitor : public ObjectGraph::Visitor { |
| + public: |
| + RetainingPathVisitor(RawObject* obj, const Array& path) |
| + : obj_(obj), path_(path), length_(0) { |
| + ASSERT(Isolate::Current()->no_gc_scope_depth() != 0); |
|
turnidge
2014/05/20 18:00:38
We could consider clearing path_ here.
Are we una
koda
2014/05/20 20:37:49
Yes, we need to avoid GC during the search.
|
| + } |
| + intptr_t length() const { return length_; } |
|
turnidge
2014/05/20 18:00:38
blank line here would help me.
koda
2014/05/20 20:37:49
Done.
|
| + virtual Direction VisitObject(ObjectGraph::StackIterator* it) { |
| + if (it->Get() != obj_) { |
| + return kProceed; |
| + } |
| + Object& parent = Object::Handle(); |
| + for (length_ = 0; it->MoveToParent(); ++length_) { |
| + if (length_ < path_.Length()) { |
|
Cutch
2014/05/20 17:39:12
Could we allow path to be Array::null() and call l
koda
2014/05/20 20:37:49
Done. Although I expect the common use will be to
|
| + parent = it->Get(); |
| + path_.SetAt(length_, parent); |
| + } |
| + } |
| + return kAbort; |
| + } |
| + private: |
| + RawObject* obj_; |
| + const Array& path_; |
| + intptr_t length_; |
| +}; |
| + |
| + |
| +intptr_t ObjectGraph::RetainingPath(Object* obj, const Array& path) { |
| + NoGCScope no_gc_scope_; |
|
turnidge
2014/05/20 18:00:38
Maybe comment on what you are doing here with obj
koda
2014/05/20 20:37:49
Done.
|
| + RawObject* raw = obj->raw(); |
| + *obj = Object::null(); |
| + RetainingPathVisitor visitor(raw, path); |
| + IterateObjects(&visitor); |
| + *obj = raw; |
| + return visitor.length(); |
| +} |
| + |
| } // namespace dart |