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" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 " return [1, 2, 3];\n" | 126 " return [1, 2, 3];\n" |
127 "}\n"; | 127 "}\n"; |
128 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 128 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
129 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 129 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
130 intptr_t list_length = 0; | 130 intptr_t list_length = 0; |
131 EXPECT_VALID(result); | 131 EXPECT_VALID(result); |
132 EXPECT(!Dart_IsNull(result)); | 132 EXPECT(!Dart_IsNull(result)); |
133 EXPECT(Dart_IsList(result)); | 133 EXPECT(Dart_IsList(result)); |
134 EXPECT_VALID(Dart_ListLength(result, &list_length)); | 134 EXPECT_VALID(Dart_ListLength(result, &list_length)); |
135 EXPECT_EQ(3, list_length); | 135 EXPECT_EQ(3, list_length); |
136 Isolate* isolate = Isolate::Current(); | 136 Isolate* isolate = thread->isolate(); |
137 Heap* heap = isolate->heap(); | 137 Heap* heap = isolate->heap(); |
138 ObjectIdRing* ring = isolate->object_id_ring(); | 138 ObjectIdRing* ring = isolate->object_id_ring(); |
139 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; | 139 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; |
140 RawObject* raw_obj = Api::UnwrapHandle(result); | 140 RawObject* raw_obj = Api::UnwrapHandle(result); |
141 // Located in new heap. | 141 // Located in new heap. |
142 EXPECT(raw_obj->IsNewObject()); | 142 EXPECT(raw_obj->IsNewObject()); |
143 EXPECT_NE(Object::null(), raw_obj); | 143 EXPECT_NE(Object::null(), raw_obj); |
144 intptr_t raw_obj_id1 = ring->GetIdForObject(raw_obj); | 144 intptr_t raw_obj_id1 = ring->GetIdForObject(raw_obj); |
145 EXPECT_EQ(0, raw_obj_id1); | 145 EXPECT_EQ(0, raw_obj_id1); |
146 // Get id 0 again. | 146 // Get id 0 again. |
(...skipping 20 matching lines...) Expand all Loading... |
167 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind); | 167 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind); |
168 EXPECT_EQ(ObjectIdRing::kValid, kind); | 168 EXPECT_EQ(ObjectIdRing::kValid, kind); |
169 EXPECT_NE(Object::null(), raw_object_moved1); | 169 EXPECT_NE(Object::null(), raw_object_moved1); |
170 EXPECT_NE(Object::null(), raw_object_moved2); | 170 EXPECT_NE(Object::null(), raw_object_moved2); |
171 EXPECT_EQ(RawObject::ToAddr(raw_object_moved1), | 171 EXPECT_EQ(RawObject::ToAddr(raw_object_moved1), |
172 RawObject::ToAddr(raw_object_moved2)); | 172 RawObject::ToAddr(raw_object_moved2)); |
173 // Test that objects have moved. | 173 // Test that objects have moved. |
174 EXPECT_NE(RawObject::ToAddr(raw_obj1), RawObject::ToAddr(raw_object_moved1)); | 174 EXPECT_NE(RawObject::ToAddr(raw_obj1), RawObject::ToAddr(raw_object_moved1)); |
175 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2)); | 175 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2)); |
176 // Test that we still point at the same list. | 176 // Test that we still point at the same list. |
177 Dart_Handle moved_handle = Api::NewHandle(isolate, raw_object_moved1); | 177 Dart_Handle moved_handle = Api::NewHandle(thread, raw_object_moved1); |
178 EXPECT_VALID(moved_handle); | 178 EXPECT_VALID(moved_handle); |
179 EXPECT(!Dart_IsNull(moved_handle)); | 179 EXPECT(!Dart_IsNull(moved_handle)); |
180 EXPECT(Dart_IsList(moved_handle)); | 180 EXPECT(Dart_IsList(moved_handle)); |
181 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length)); | 181 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length)); |
182 EXPECT_EQ(3, list_length); | 182 EXPECT_EQ(3, list_length); |
183 // Test id reuse. | 183 // Test id reuse. |
184 EXPECT_EQ(raw_obj_id1, | 184 EXPECT_EQ(raw_obj_id1, |
185 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId)); | 185 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId)); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 // Test that the ring table is updated with nulls when the old GC collects. | 189 // Test that the ring table is updated with nulls when the old GC collects. |
190 TEST_CASE(ObjectIdRingOldGCTest) { | 190 TEST_CASE(ObjectIdRingOldGCTest) { |
191 Isolate* isolate = Isolate::Current(); | 191 Isolate* isolate = thread->isolate(); |
192 Heap* heap = isolate->heap(); | 192 Heap* heap = isolate->heap(); |
193 ObjectIdRing* ring = isolate->object_id_ring(); | 193 ObjectIdRing* ring = isolate->object_id_ring(); |
194 | 194 |
195 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; | 195 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; |
196 intptr_t raw_obj_id1 = -1; | 196 intptr_t raw_obj_id1 = -1; |
197 intptr_t raw_obj_id2 = -1; | 197 intptr_t raw_obj_id2 = -1; |
198 { | 198 { |
199 Dart_EnterScope(); | 199 Dart_EnterScope(); |
200 Dart_Handle result; | 200 Dart_Handle result; |
201 // Create a string in the old heap. | 201 // Create a string in the old heap. |
202 result = Api::NewHandle(isolate, String::New("old", Heap::kOld)); | 202 result = Api::NewHandle(thread, String::New("old", Heap::kOld)); |
203 EXPECT_VALID(result); | 203 EXPECT_VALID(result); |
204 intptr_t string_length = 0; | 204 intptr_t string_length = 0; |
205 // Inspect string. | 205 // Inspect string. |
206 EXPECT(!Dart_IsNull(result)); | 206 EXPECT(!Dart_IsNull(result)); |
207 EXPECT(Dart_IsString(result)); | 207 EXPECT(Dart_IsString(result)); |
208 EXPECT_VALID(Dart_StringLength(result, &string_length)); | 208 EXPECT_VALID(Dart_StringLength(result, &string_length)); |
209 EXPECT_EQ(3, string_length); | 209 EXPECT_EQ(3, string_length); |
210 RawObject* raw_obj = Api::UnwrapHandle(result); | 210 RawObject* raw_obj = Api::UnwrapHandle(result); |
211 // Verify that it is located in old heap. | 211 // Verify that it is located in old heap. |
212 EXPECT(raw_obj->IsOldObject()); | 212 EXPECT(raw_obj->IsOldObject()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 | 266 |
267 // Check our first entry reports it has expired. | 267 // Check our first entry reports it has expired. |
268 obj_lookup = ring->GetObjectForId(obj_id, &kind); | 268 obj_lookup = ring->GetObjectForId(obj_id, &kind); |
269 EXPECT_EQ(ObjectIdRing::kExpired, kind); | 269 EXPECT_EQ(ObjectIdRing::kExpired, kind); |
270 EXPECT_NE(obj.raw(), obj_lookup); | 270 EXPECT_NE(obj.raw(), obj_lookup); |
271 EXPECT_EQ(Object::null(), obj_lookup); | 271 EXPECT_EQ(Object::null(), obj_lookup); |
272 } | 272 } |
273 | 273 |
274 } // namespace dart | 274 } // namespace dart |
OLD | NEW |