Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: runtime/vm/object_graph_test.cc

Issue 350403005: Include parent field/list index in retaining path. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_graph.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 }; 38 };
39 39
40 40
41 TEST_CASE(ObjectGraph) { 41 TEST_CASE(ObjectGraph) {
42 Isolate* isolate = Isolate::Current(); 42 Isolate* isolate = Isolate::Current();
43 // Create a simple object graph with objects a, b, c, d: 43 // Create a simple object graph with objects a, b, c, d:
44 // a+->b+->c 44 // a+->b+->c
45 // +   + 45 // +   +
46 // |   v 46 // |   v
47 // +-->d 47 // +-->d
48 Array& a = Array::Handle(Array::New(2, Heap::kNew)); 48 Array& a = Array::Handle(Array::New(12, Heap::kNew));
49 Array& b = Array::Handle(Array::New(2, Heap::kOld)); 49 Array& b = Array::Handle(Array::New(2, Heap::kOld));
50 Array& c = Array::Handle(Array::New(0, Heap::kOld)); 50 Array& c = Array::Handle(Array::New(0, Heap::kOld));
51 Array& d = Array::Handle(Array::New(0, Heap::kOld)); 51 Array& d = Array::Handle(Array::New(0, Heap::kOld));
52 a.SetAt(0, b); 52 a.SetAt(10, b);
53 b.SetAt(0, c); 53 b.SetAt(0, c);
54 b.SetAt(1, d); 54 b.SetAt(1, d);
55 a.SetAt(1, d); 55 a.SetAt(11, d);
56 intptr_t a_size = a.raw()->Size(); 56 intptr_t a_size = a.raw()->Size();
57 intptr_t b_size = b.raw()->Size(); 57 intptr_t b_size = b.raw()->Size();
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 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();
(...skipping 20 matching lines...) Expand all
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.
96 b ^= a.At(0); 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(isolate);
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(isolate); 102 HANDLESCOPE(isolate);
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);
110 EXPECT_LE(3, null_length); 110 EXPECT_LE(3, null_length);
111 } 111 }
112 { 112 {
113 HANDLESCOPE(isolate); 113 HANDLESCOPE(isolate);
114 Array& path = Array::Handle(Array::New(3, Heap::kNew)); 114 Array& path = Array::Handle(Array::New(6, Heap::kNew));
115 intptr_t length = graph.RetainingPath(&c, path); 115 intptr_t length = graph.RetainingPath(&c, path);
116 EXPECT_LE(3, length); 116 EXPECT_LE(3, length);
117 Array& expected_c = Array::Handle(); 117 Array& expected_c = Array::Handle();
118 expected_c ^= path.At(0); 118 expected_c ^= path.At(0);
119 // c is the first element in b.
120 Smi& offset_from_parent = Smi::Handle();
121 offset_from_parent ^= path.At(1);
122 EXPECT_EQ(Array::element_offset(0),
123 offset_from_parent.Value() * kWordSize);
119 Array& expected_b = Array::Handle(); 124 Array& expected_b = Array::Handle();
120 expected_b ^= path.At(1); 125 expected_b ^= path.At(2);
126 // b is the element with index 10 in a.
127 offset_from_parent ^= path.At(3);
128 EXPECT_EQ(Array::element_offset(10),
129 offset_from_parent.Value() * kWordSize);
121 Array& expected_a = Array::Handle(); 130 Array& expected_a = Array::Handle();
122 expected_a ^= path.At(2); 131 expected_a ^= path.At(4);
123 EXPECT(expected_c.raw() == c.raw()); 132 EXPECT(expected_c.raw() == c.raw());
124 EXPECT(expected_b.raw() == a.At(0)); 133 EXPECT(expected_b.raw() == a.At(10));
125 EXPECT(expected_a.raw() == a.raw()); 134 EXPECT(expected_a.raw() == a.raw());
126 } 135 }
127 } 136 }
128 } 137 }
129 138
130 } // namespace dart 139 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_graph.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698