Chromium Code Reviews| Index: runtime/vm/object_graph.cc |
| diff --git a/runtime/vm/object_graph.cc b/runtime/vm/object_graph.cc |
| index bbecac73b11bfdaf1717a3bf6a33c81fb8769b9e..8e235b32bfc1de06f5f57ecc76ee1edf0f9efd03 100644 |
| --- a/runtime/vm/object_graph.cc |
| +++ b/runtime/vm/object_graph.cc |
| @@ -319,6 +319,30 @@ class RetainingPathVisitor : public ObjectGraph::Visitor { |
| } |
| } |
| + bool ShouldStop(RawObject* obj) { |
| + // A static field is considered a root from a language point of view. |
| + if (obj->IsField()) { |
| + const Field& field = Field::Handle(static_cast<RawField*>(obj)); |
| + return field.is_static(); |
| + } |
| + return false; |
| + } |
| + |
| + void StartList() { |
| + wasLastArray_ = false; |
|
Cutch
2016/08/12 14:23:39
C++ style guide says variables are lower_case_like
cbernaschina
2016/08/12 17:28:24
Done.
|
| + } |
| + |
| + bool ShouldOverwrite(RawObject* obj) { |
|
Cutch
2016/08/12 14:23:40
ShouldReplace?
cbernaschina
2016/08/12 17:28:24
Changed approach, and name
|
| + // A GrowableObjectArray overwrites its internal storage. |
| + // Keeping both of them in the list is redundant. |
| + if (wasLastArray_ && obj->IsGrowableObjectArray()) { |
| + wasLastArray_ = false; |
| + return true; |
| + } |
| + wasLastArray_ = obj->IsArray(); |
| + return false; |
| + } |
| + |
| virtual Direction VisitObject(ObjectGraph::StackIterator* it) { |
| if (it->Get() != obj_) { |
| if (ShouldSkip(it->Get())) { |
| @@ -330,7 +354,11 @@ class RetainingPathVisitor : public ObjectGraph::Visitor { |
| HANDLESCOPE(thread_); |
| Object& current = Object::Handle(); |
| Smi& offset_from_parent = Smi::Handle(); |
| + StartList(); |
| do { |
| + if (ShouldOverwrite(it->Get())) { |
| + --length_; |
| + } |
| intptr_t obj_index = length_ * 2; |
| intptr_t offset_index = obj_index + 1; |
| if (!path_.IsNull() && offset_index < path_.Length()) { |
| @@ -340,7 +368,7 @@ class RetainingPathVisitor : public ObjectGraph::Visitor { |
| path_.SetAt(offset_index, offset_from_parent); |
| } |
| ++length_; |
| - } while (it->MoveToParent()); |
| + } while (!ShouldStop(it->Get()) && it->MoveToParent()); |
| return kAbort; |
| } |
| } |
| @@ -350,6 +378,7 @@ class RetainingPathVisitor : public ObjectGraph::Visitor { |
| RawObject* obj_; |
| const Array& path_; |
| intptr_t length_; |
| + bool wasLastArray_; |
| }; |