| 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 Counter : 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 Counter(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_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // No more allocation; raw pointers ahead. | 61 // No more allocation; raw pointers ahead. |
| 62 NoGCScope no_gc_scope; | 62 NoGCScope no_gc_scope; |
| 63 RawObject* b_raw = b.raw(); | 63 RawObject* b_raw = b.raw(); |
| 64 // Clear handles to cut unintended retained paths. | 64 // Clear handles to cut unintended retained paths. |
| 65 b = Array::null(); | 65 b = Array::null(); |
| 66 c = Array::null(); | 66 c = Array::null(); |
| 67 d = Array::null(); | 67 d = Array::null(); |
| 68 ObjectGraph graph(isolate); | 68 ObjectGraph graph(isolate); |
| 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 Counter with(Object::null(), Object::null()); | 71 CounterVisitor with(Object::null(), Object::null()); |
| 72 graph.IterateObjectsFrom(a, &with); | 72 graph.IterateObjectsFrom(a, &with); |
| 73 Counter 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, |
| 78 with.size() - without.size()); | 78 with.size() - without.size()); |
| 79 } | 79 } |
| 80 { | 80 { |
| 81 // Like above, but iterate over the entire isolate. The counts and sizes | 81 // 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'. | 82 // are thus larger, but the difference should still be just 'b' and 'c'. |
| 83 Counter with(Object::null(), Object::null()); | 83 CounterVisitor with(Object::null(), Object::null()); |
| 84 graph.IterateObjects(&with); | 84 graph.IterateObjects(&with); |
| 85 Counter without(b_raw, a.raw()); | 85 CounterVisitor without(b_raw, a.raw()); |
| 86 graph.IterateObjects(&without); | 86 graph.IterateObjects(&without); |
| 87 EXPECT_EQ(2, with.count() - without.count()); | 87 EXPECT_EQ(2, with.count() - without.count()); |
| 88 EXPECT_EQ(b_size + c_size, | 88 EXPECT_EQ(b_size + c_size, |
| 89 with.size() - without.size()); | 89 with.size() - without.size()); |
| 90 } | 90 } |
| 91 EXPECT_EQ(a_size + b_size + c_size + d_size, | 91 EXPECT_EQ(a_size + b_size + c_size + d_size, |
| 92 graph.SizeRetainedByInstance(a)); | 92 graph.SizeRetainedByInstance(a)); |
| 93 } | 93 } |
| 94 { | 94 { |
| 95 // Get hold of c again. | 95 // Get hold of c again. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 Array& expected_a = Array::Handle(); | 121 Array& expected_a = Array::Handle(); |
| 122 expected_a ^= path.At(2); | 122 expected_a ^= path.At(2); |
| 123 EXPECT(expected_c.raw() == c.raw()); | 123 EXPECT(expected_c.raw() == c.raw()); |
| 124 EXPECT(expected_b.raw() == a.At(0)); | 124 EXPECT(expected_b.raw() == a.At(0)); |
| 125 EXPECT(expected_a.raw() == a.raw()); | 125 EXPECT(expected_a.raw() == a.raw()); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace dart | 130 } // namespace dart |
| OLD | NEW |