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

Unified Diff: runtime/vm/object_graph.cc

Issue 286203015: ObjectGraph::RetainingPath (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object_graph.h ('k') | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object_graph.cc
===================================================================
--- runtime/vm/object_graph.cc (revision 36049)
+++ runtime/vm/object_graph.cc (working copy)
@@ -207,4 +207,50 @@
return size_total - size_excluding_class;
}
+
+class RetainingPathVisitor : public ObjectGraph::Visitor {
+ public:
+ // We cannot use a GrowableObjectArray, since we must not trigger GC.
+ RetainingPathVisitor(RawObject* obj, const Array& path)
+ : obj_(obj), path_(path), length_(0) {
+ ASSERT(Isolate::Current()->no_gc_scope_depth() != 0);
+ }
+
+ intptr_t length() const { return length_; }
+
+ virtual Direction VisitObject(ObjectGraph::StackIterator* it) {
+ if (it->Get() != obj_) {
+ return kProceed;
+ } else {
+ HANDLESCOPE(Isolate::Current());
+ Object& parent = Object::Handle();
+ for (length_ = 0; it->MoveToParent(); ++length_) {
+ if (!path_.IsNull() && length_ < path_.Length()) {
+ 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_;
+ // To break the trivial path, the handle 'obj' is temporarily cleared during
+ // the search, but restored before returning.
+ RawObject* raw = obj->raw();
+ *obj = Object::null();
+ RetainingPathVisitor visitor(raw, path);
+ IterateObjects(&visitor);
+ *obj = raw;
+ return visitor.length();
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/object_graph.h ('k') | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698