| 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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/object_graph.h" | 6 #include "vm/object_graph.h" |
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| 11 class CounterVisitor : public ObjectGraph::Visitor { | 11 class CounterVisitor : public ObjectGraph::Visitor { |
| 12 public: | 12 public: |
| 13 // Records the number of objects and total size visited, excluding 'skip' | 13 // Records the number of objects and total size visited, excluding 'skip' |
| 14 // and any objects only reachable through 'skip'. | 14 // and any objects only reachable through 'skip'. |
| 15 CounterVisitor(RawObject* skip, RawObject* expected_parent) | 15 CounterVisitor(RawObject* skip, RawObject* expected_parent) |
| 16 : count_(0), size_(0), skip_(skip), expected_parent_(expected_parent) { } | 16 : count_(0), size_(0), skip_(skip), expected_parent_(expected_parent) {} |
| 17 | 17 |
| 18 virtual Direction VisitObject(ObjectGraph::StackIterator* it) { | 18 virtual Direction VisitObject(ObjectGraph::StackIterator* it) { |
| 19 RawObject* obj = it->Get(); | 19 RawObject* obj = it->Get(); |
| 20 if (obj == skip_) { | 20 if (obj == skip_) { |
| 21 EXPECT(it->MoveToParent()); | 21 EXPECT(it->MoveToParent()); |
| 22 EXPECT_EQ(expected_parent_, it->Get()); | 22 EXPECT_EQ(expected_parent_, it->Get()); |
| 23 return kBacktrack; | 23 return kBacktrack; |
| 24 } | 24 } |
| 25 ++count_; | 25 ++count_; |
| 26 size_ += obj->Size(); | 26 size_ += obj->Size(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 d = Array::null(); | 67 d = Array::null(); |
| 68 ObjectGraph graph(thread); | 68 ObjectGraph graph(thread); |
| 69 { | 69 { |
| 70 // Compare count and size when 'b' is/isn't skipped. | 70 // Compare count and size when 'b' is/isn't skipped. |
| 71 CounterVisitor with(Object::null(), Object::null()); | 71 CounterVisitor with(Object::null(), Object::null()); |
| 72 graph.IterateObjectsFrom(a, &with); | 72 graph.IterateObjectsFrom(a, &with); |
| 73 CounterVisitor without(b_raw, a.raw()); | 73 CounterVisitor without(b_raw, a.raw()); |
| 74 graph.IterateObjectsFrom(a, &without); | 74 graph.IterateObjectsFrom(a, &without); |
| 75 // Only 'b' and 'c' were cut off. | 75 // Only 'b' and 'c' were cut off. |
| 76 EXPECT_EQ(2, with.count() - without.count()); | 76 EXPECT_EQ(2, with.count() - without.count()); |
| 77 EXPECT_EQ(b_size + c_size, | 77 EXPECT_EQ(b_size + c_size, with.size() - without.size()); |
| 78 with.size() - without.size()); | |
| 79 } | 78 } |
| 80 { | 79 { |
| 81 // Like above, but iterate over the entire isolate. The counts and sizes | 80 // Like above, but iterate over the entire isolate. The counts and sizes |
| 82 // are thus larger, but the difference should still be just 'b' and 'c'. | 81 // are thus larger, but the difference should still be just 'b' and 'c'. |
| 83 CounterVisitor with(Object::null(), Object::null()); | 82 CounterVisitor with(Object::null(), Object::null()); |
| 84 graph.IterateObjects(&with); | 83 graph.IterateObjects(&with); |
| 85 CounterVisitor without(b_raw, a.raw()); | 84 CounterVisitor without(b_raw, a.raw()); |
| 86 graph.IterateObjects(&without); | 85 graph.IterateObjects(&without); |
| 87 EXPECT_EQ(2, with.count() - without.count()); | 86 EXPECT_EQ(2, with.count() - without.count()); |
| 88 EXPECT_EQ(b_size + c_size, | 87 EXPECT_EQ(b_size + c_size, with.size() - without.size()); |
| 89 with.size() - without.size()); | |
| 90 } | 88 } |
| 91 EXPECT_EQ(a_size + b_size + c_size + d_size, | 89 EXPECT_EQ(a_size + b_size + c_size + d_size, |
| 92 graph.SizeRetainedByInstance(a)); | 90 graph.SizeRetainedByInstance(a)); |
| 93 } | 91 } |
| 94 { | 92 { |
| 95 // Get hold of c again. | 93 // Get hold of c again. |
| 96 b ^= a.At(10); | 94 b ^= a.At(10); |
| 97 c ^= b.At(0); | 95 c ^= b.At(0); |
| 98 b = Array::null(); | 96 b = Array::null(); |
| 99 ObjectGraph graph(thread); | 97 ObjectGraph graph(thread); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 Array& expected_a = Array::Handle(); | 130 Array& expected_a = Array::Handle(); |
| 133 expected_a ^= path.At(4); | 131 expected_a ^= path.At(4); |
| 134 EXPECT(expected_c.raw() == c.raw()); | 132 EXPECT(expected_c.raw() == c.raw()); |
| 135 EXPECT(expected_b.raw() == a.At(10)); | 133 EXPECT(expected_b.raw() == a.At(10)); |
| 136 EXPECT(expected_a.raw() == a.raw()); | 134 EXPECT(expected_a.raw() == a.raw()); |
| 137 } | 135 } |
| 138 } | 136 } |
| 139 } | 137 } |
| 140 | 138 |
| 141 } // namespace dart | 139 } // namespace dart |
| OLD | NEW |