OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/globals.h" | 6 #include "vm/globals.h" |
7 #include "vm/object_id_ring.h" | 7 #include "vm/object_id_ring.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 #ifndef PRODUCT | 14 #ifndef PRODUCT |
15 | 15 |
16 class ObjectIdRingTestHelper { | 16 class ObjectIdRingTestHelper { |
17 public: | 17 public: |
18 static void SetCapacityAndMaxSerial(ObjectIdRing* ring, int32_t capacity, | 18 static void SetCapacityAndMaxSerial(ObjectIdRing* ring, |
| 19 int32_t capacity, |
19 int32_t max_serial) { | 20 int32_t max_serial) { |
20 ring->SetCapacityAndMaxSerial(capacity, max_serial); | 21 ring->SetCapacityAndMaxSerial(capacity, max_serial); |
21 } | 22 } |
22 | 23 |
23 static void ExpectIdIsValid(ObjectIdRing* ring, intptr_t id) { | 24 static void ExpectIdIsValid(ObjectIdRing* ring, intptr_t id) { |
24 EXPECT(ring->IsValidId(id)); | 25 EXPECT(ring->IsValidId(id)); |
25 } | 26 } |
26 | 27 |
27 static void ExpectIdIsInvalid(ObjectIdRing* ring, intptr_t id) { | 28 static void ExpectIdIsInvalid(ObjectIdRing* ring, intptr_t id) { |
28 EXPECT(!ring->IsValidId(id)); | 29 EXPECT(!ring->IsValidId(id)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 ObjectIdRingTestHelper::ExpectIdIsValid(ring, 0); | 117 ObjectIdRingTestHelper::ExpectIdIsValid(ring, 0); |
117 ObjectIdRingTestHelper::ExpectIdIsValid(ring, 1); | 118 ObjectIdRingTestHelper::ExpectIdIsValid(ring, 1); |
118 ObjectIdRingTestHelper::ExpectIdIsInvalid(ring, 2); | 119 ObjectIdRingTestHelper::ExpectIdIsInvalid(ring, 2); |
119 ObjectIdRingTestHelper::ExpectIdIsInvalid(ring, 3); | 120 ObjectIdRingTestHelper::ExpectIdIsInvalid(ring, 3); |
120 } | 121 } |
121 | 122 |
122 | 123 |
123 // Test that the ring table is updated when the scavenger moves an object. | 124 // Test that the ring table is updated when the scavenger moves an object. |
124 TEST_CASE(ObjectIdRingScavengeMoveTest) { | 125 TEST_CASE(ObjectIdRingScavengeMoveTest) { |
125 const char* kScriptChars = | 126 const char* kScriptChars = |
126 "main() {\n" | 127 "main() {\n" |
127 " return [1, 2, 3];\n" | 128 " return [1, 2, 3];\n" |
128 "}\n"; | 129 "}\n"; |
129 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 130 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
130 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 131 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
131 intptr_t list_length = 0; | 132 intptr_t list_length = 0; |
132 EXPECT_VALID(result); | 133 EXPECT_VALID(result); |
133 EXPECT(!Dart_IsNull(result)); | 134 EXPECT(!Dart_IsNull(result)); |
134 EXPECT(Dart_IsList(result)); | 135 EXPECT(Dart_IsList(result)); |
135 EXPECT_VALID(Dart_ListLength(result, &list_length)); | 136 EXPECT_VALID(Dart_ListLength(result, &list_length)); |
136 EXPECT_EQ(3, list_length); | 137 EXPECT_EQ(3, list_length); |
137 Isolate* isolate = thread->isolate(); | 138 Isolate* isolate = thread->isolate(); |
138 Heap* heap = isolate->heap(); | 139 Heap* heap = isolate->heap(); |
139 ObjectIdRing* ring = isolate->object_id_ring(); | 140 ObjectIdRing* ring = isolate->object_id_ring(); |
140 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; | 141 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; |
141 RawObject* raw_obj = Api::UnwrapHandle(result); | 142 RawObject* raw_obj = Api::UnwrapHandle(result); |
142 // Located in new heap. | 143 // Located in new heap. |
143 EXPECT(raw_obj->IsNewObject()); | 144 EXPECT(raw_obj->IsNewObject()); |
144 EXPECT_NE(Object::null(), raw_obj); | 145 EXPECT_NE(Object::null(), raw_obj); |
145 intptr_t raw_obj_id1 = ring->GetIdForObject(raw_obj); | 146 intptr_t raw_obj_id1 = ring->GetIdForObject(raw_obj); |
146 EXPECT_EQ(0, raw_obj_id1); | 147 EXPECT_EQ(0, raw_obj_id1); |
147 // Get id 0 again. | 148 // Get id 0 again. |
148 EXPECT_EQ(raw_obj_id1, | 149 EXPECT_EQ(raw_obj_id1, ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId)); |
149 ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId)); | |
150 // Add to ring a second time. | 150 // Add to ring a second time. |
151 intptr_t raw_obj_id2 = ring->GetIdForObject(raw_obj); | 151 intptr_t raw_obj_id2 = ring->GetIdForObject(raw_obj); |
152 EXPECT_EQ(1, raw_obj_id2); | 152 EXPECT_EQ(1, raw_obj_id2); |
153 // Get id 0 again. | 153 // Get id 0 again. |
154 EXPECT_EQ(raw_obj_id1, | 154 EXPECT_EQ(raw_obj_id1, ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId)); |
155 ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId)); | |
156 RawObject* raw_obj1 = ring->GetObjectForId(raw_obj_id1, &kind); | 155 RawObject* raw_obj1 = ring->GetObjectForId(raw_obj_id1, &kind); |
157 EXPECT_EQ(ObjectIdRing::kValid, kind); | 156 EXPECT_EQ(ObjectIdRing::kValid, kind); |
158 RawObject* raw_obj2 = ring->GetObjectForId(raw_obj_id2, &kind); | 157 RawObject* raw_obj2 = ring->GetObjectForId(raw_obj_id2, &kind); |
159 EXPECT_EQ(ObjectIdRing::kValid, kind); | 158 EXPECT_EQ(ObjectIdRing::kValid, kind); |
160 EXPECT_NE(Object::null(), raw_obj1); | 159 EXPECT_NE(Object::null(), raw_obj1); |
161 EXPECT_NE(Object::null(), raw_obj2); | 160 EXPECT_NE(Object::null(), raw_obj2); |
162 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj1)); | 161 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj1)); |
163 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj2)); | 162 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj2)); |
164 { | 163 { |
165 TransitionNativeToVM transition(thread); | 164 TransitionNativeToVM transition(thread); |
(...skipping 13 matching lines...) Expand all Loading... |
179 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2)); | 178 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2)); |
180 // Test that we still point at the same list. | 179 // Test that we still point at the same list. |
181 Dart_Handle moved_handle = Api::NewHandle(thread, raw_object_moved1); | 180 Dart_Handle moved_handle = Api::NewHandle(thread, raw_object_moved1); |
182 EXPECT_VALID(moved_handle); | 181 EXPECT_VALID(moved_handle); |
183 EXPECT(!Dart_IsNull(moved_handle)); | 182 EXPECT(!Dart_IsNull(moved_handle)); |
184 EXPECT(Dart_IsList(moved_handle)); | 183 EXPECT(Dart_IsList(moved_handle)); |
185 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length)); | 184 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length)); |
186 EXPECT_EQ(3, list_length); | 185 EXPECT_EQ(3, list_length); |
187 // Test id reuse. | 186 // Test id reuse. |
188 EXPECT_EQ(raw_obj_id1, | 187 EXPECT_EQ(raw_obj_id1, |
189 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId)); | 188 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId)); |
190 } | 189 } |
191 | 190 |
192 | 191 |
193 // Test that the ring table is updated with nulls when the old GC collects. | 192 // Test that the ring table is updated with nulls when the old GC collects. |
194 VM_TEST_CASE(ObjectIdRingOldGCTest) { | 193 VM_TEST_CASE(ObjectIdRingOldGCTest) { |
195 Isolate* isolate = thread->isolate(); | 194 Isolate* isolate = thread->isolate(); |
196 Heap* heap = isolate->heap(); | 195 Heap* heap = isolate->heap(); |
197 ObjectIdRing* ring = isolate->object_id_ring(); | 196 ObjectIdRing* ring = isolate->object_id_ring(); |
198 | 197 |
199 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; | 198 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // Check our first entry reports it has expired. | 270 // Check our first entry reports it has expired. |
272 obj_lookup = ring->GetObjectForId(obj_id, &kind); | 271 obj_lookup = ring->GetObjectForId(obj_id, &kind); |
273 EXPECT_EQ(ObjectIdRing::kExpired, kind); | 272 EXPECT_EQ(ObjectIdRing::kExpired, kind); |
274 EXPECT_NE(obj.raw(), obj_lookup); | 273 EXPECT_NE(obj.raw(), obj_lookup); |
275 EXPECT_EQ(Object::null(), obj_lookup); | 274 EXPECT_EQ(Object::null(), obj_lookup); |
276 } | 275 } |
277 | 276 |
278 #endif // !PRODUCT | 277 #endif // !PRODUCT |
279 | 278 |
280 } // namespace dart | 279 } // namespace dart |
OLD | NEW |