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 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 graph.IterateObjects(&with); | 84 graph.IterateObjects(&with); |
85 Counter without(b_raw, a.raw()); | 85 Counter 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 { |
| 95 // Get hold of c again. |
| 96 b ^= a.At(0); |
| 97 c ^= b.At(0); |
| 98 b = Array::null(); |
| 99 ObjectGraph graph(isolate); |
| 100 // A retaining path should end like this: c <- b <- a <- ... |
| 101 // c itself is not included in the returned path and length. |
| 102 { |
| 103 HANDLESCOPE(isolate); |
| 104 // Test null, empty, and length 1 array. |
| 105 intptr_t null_length = graph.RetainingPath(&c, Object::null_array()); |
| 106 intptr_t empty_length = graph.RetainingPath(&c, Object::empty_array()); |
| 107 Array& path = Array::Handle(Array::New(1, Heap::kNew)); |
| 108 intptr_t one_length = graph.RetainingPath(&c, path); |
| 109 EXPECT_EQ(null_length, empty_length); |
| 110 EXPECT_EQ(null_length, one_length); |
| 111 EXPECT_LE(2, null_length); |
| 112 } |
| 113 { |
| 114 HANDLESCOPE(isolate); |
| 115 Array& path = Array::Handle(Array::New(2, Heap::kNew)); |
| 116 intptr_t length = graph.RetainingPath(&c, path); |
| 117 EXPECT_LE(2, length); |
| 118 Array& expected_b = Array::Handle(); |
| 119 expected_b ^= path.At(0); |
| 120 Array& expected_a = Array::Handle(); |
| 121 expected_a ^= path.At(1); |
| 122 EXPECT(expected_b.raw() == a.At(0)); |
| 123 EXPECT(expected_a.raw() == a.raw()); |
| 124 } |
| 125 } |
94 } | 126 } |
95 | 127 |
96 } // namespace dart | 128 } // namespace dart |
OLD | NEW |