| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 intptr_t c_size = c.raw()->Size(); | 58 intptr_t c_size = c.raw()->Size(); |
| 59 intptr_t d_size = d.raw()->Size(); | 59 intptr_t d_size = d.raw()->Size(); |
| 60 { | 60 { |
| 61 // No more allocation; raw pointers ahead. | 61 // No more allocation; raw pointers ahead. |
| 62 NoSafepointScope no_safepoint_scope; | 62 NoSafepointScope no_safepoint_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(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, |
| 78 with.size() - without.size()); | 78 with.size() - without.size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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. |
| 96 b ^= a.At(10); | 96 b ^= a.At(10); |
| 97 c ^= b.At(0); | 97 c ^= b.At(0); |
| 98 b = Array::null(); | 98 b = Array::null(); |
| 99 ObjectGraph graph(isolate); | 99 ObjectGraph graph(thread); |
| 100 // A retaining path should end like this: c <- b <- a <- ... | 100 // A retaining path should end like this: c <- b <- a <- ... |
| 101 { | 101 { |
| 102 HANDLESCOPE(thread); | 102 HANDLESCOPE(thread); |
| 103 // Test null, empty, and length 1 array. | 103 // Test null, empty, and length 1 array. |
| 104 intptr_t null_length = graph.RetainingPath(&c, Object::null_array()); | 104 intptr_t null_length = graph.RetainingPath(&c, Object::null_array()); |
| 105 intptr_t empty_length = graph.RetainingPath(&c, Object::empty_array()); | 105 intptr_t empty_length = graph.RetainingPath(&c, Object::empty_array()); |
| 106 Array& path = Array::Handle(Array::New(1, Heap::kNew)); | 106 Array& path = Array::Handle(Array::New(1, Heap::kNew)); |
| 107 intptr_t one_length = graph.RetainingPath(&c, path); | 107 intptr_t one_length = graph.RetainingPath(&c, path); |
| 108 EXPECT_EQ(null_length, empty_length); | 108 EXPECT_EQ(null_length, empty_length); |
| 109 EXPECT_EQ(null_length, one_length); | 109 EXPECT_EQ(null_length, one_length); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 132 Array& expected_a = Array::Handle(); | 132 Array& expected_a = Array::Handle(); |
| 133 expected_a ^= path.At(4); | 133 expected_a ^= path.At(4); |
| 134 EXPECT(expected_c.raw() == c.raw()); | 134 EXPECT(expected_c.raw() == c.raw()); |
| 135 EXPECT(expected_b.raw() == a.At(10)); | 135 EXPECT(expected_b.raw() == a.At(10)); |
| 136 EXPECT(expected_a.raw() == a.raw()); | 136 EXPECT(expected_a.raw() == a.raw()); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace dart | 141 } // namespace dart |
| OLD | NEW |