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

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

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments Created 5 years, 3 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
« no previous file with comments | « runtime/vm/object_graph.cc ('k') | runtime/vm/object_test.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 21 matching lines...) Expand all
32 32
33 private: 33 private:
34 int count_; 34 int count_;
35 intptr_t size_; 35 intptr_t size_;
36 RawObject* skip_; 36 RawObject* skip_;
37 RawObject* expected_parent_; 37 RawObject* expected_parent_;
38 }; 38 };
39 39
40 40
41 TEST_CASE(ObjectGraph) { 41 TEST_CASE(ObjectGraph) {
42 Isolate* isolate = Isolate::Current(); 42 Isolate* isolate = thread->isolate();
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(12, 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(10, b); 52 a.SetAt(10, b);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(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(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);
110 EXPECT_LE(3, null_length); 110 EXPECT_LE(3, null_length);
111 } 111 }
112 { 112 {
113 HANDLESCOPE(isolate); 113 HANDLESCOPE(thread);
114 Array& path = Array::Handle(Array::New(6, Heap::kNew)); 114 Array& path = Array::Handle(Array::New(6, Heap::kNew));
115 // Trigger a full GC to increase probability of concurrent tasks. 115 // Trigger a full GC to increase probability of concurrent tasks.
116 isolate->heap()->CollectAllGarbage(); 116 isolate->heap()->CollectAllGarbage();
117 intptr_t length = graph.RetainingPath(&c, path); 117 intptr_t length = graph.RetainingPath(&c, path);
118 EXPECT_LE(3, length); 118 EXPECT_LE(3, length);
119 Array& expected_c = Array::Handle(); 119 Array& expected_c = Array::Handle();
120 expected_c ^= path.At(0); 120 expected_c ^= path.At(0);
121 // c is the first element in b. 121 // c is the first element in b.
122 Smi& offset_from_parent = Smi::Handle(); 122 Smi& offset_from_parent = Smi::Handle();
123 offset_from_parent ^= path.At(1); 123 offset_from_parent ^= path.At(1);
124 EXPECT_EQ(Array::element_offset(0), 124 EXPECT_EQ(Array::element_offset(0),
125 offset_from_parent.Value() * kWordSize); 125 offset_from_parent.Value() * kWordSize);
126 Array& expected_b = Array::Handle(); 126 Array& expected_b = Array::Handle();
127 expected_b ^= path.At(2); 127 expected_b ^= path.At(2);
128 // b is the element with index 10 in a. 128 // b is the element with index 10 in a.
129 offset_from_parent ^= path.At(3); 129 offset_from_parent ^= path.At(3);
130 EXPECT_EQ(Array::element_offset(10), 130 EXPECT_EQ(Array::element_offset(10),
131 offset_from_parent.Value() * kWordSize); 131 offset_from_parent.Value() * kWordSize);
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
OLDNEW
« no previous file with comments | « runtime/vm/object_graph.cc ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698