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

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

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix-typo Created 4 years, 10 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_test.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) 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 30 matching lines...) Expand all
41 41
42 static void ExpectString(RawObject* obj, const char* s) { 42 static void ExpectString(RawObject* obj, const char* s) {
43 String& str = String::Handle(); 43 String& str = String::Handle();
44 str ^= obj; 44 str ^= obj;
45 EXPECT(str.Equals(s)); 45 EXPECT(str.Equals(s));
46 } 46 }
47 }; 47 };
48 48
49 49
50 // Test that serial number wrapping works. 50 // Test that serial number wrapping works.
51 TEST_CASE(ObjectIdRingSerialWrapTest) { 51 VM_TEST_CASE(ObjectIdRingSerialWrapTest) {
52 Isolate* isolate = Isolate::Current(); 52 Isolate* isolate = Isolate::Current();
53 ObjectIdRing* ring = isolate->object_id_ring(); 53 ObjectIdRing* ring = isolate->object_id_ring();
54 ObjectIdRingTestHelper::SetCapacityAndMaxSerial(ring, 2, 4); 54 ObjectIdRingTestHelper::SetCapacityAndMaxSerial(ring, 2, 4);
55 intptr_t id; 55 intptr_t id;
56 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; 56 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid;
57 id = ring->GetIdForObject(ObjectIdRingTestHelper::MakeString("0")); 57 id = ring->GetIdForObject(ObjectIdRingTestHelper::MakeString("0"));
58 EXPECT_EQ(0, id); 58 EXPECT_EQ(0, id);
59 ObjectIdRingTestHelper::ExpectIndexId(ring, 0, 0); 59 ObjectIdRingTestHelper::ExpectIndexId(ring, 0, 0);
60 ObjectIdRingTestHelper::ExpectInvalidIndex(ring, 1); 60 ObjectIdRingTestHelper::ExpectInvalidIndex(ring, 1);
61 id = ring->GetIdForObject(ObjectIdRingTestHelper::MakeString("1")); 61 id = ring->GetIdForObject(ObjectIdRingTestHelper::MakeString("1"));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 EXPECT_EQ(raw_obj_id1, 153 EXPECT_EQ(raw_obj_id1,
154 ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId)); 154 ring->GetIdForObject(raw_obj, ObjectIdRing::kReuseId));
155 RawObject* raw_obj1 = ring->GetObjectForId(raw_obj_id1, &kind); 155 RawObject* raw_obj1 = ring->GetObjectForId(raw_obj_id1, &kind);
156 EXPECT_EQ(ObjectIdRing::kValid, kind); 156 EXPECT_EQ(ObjectIdRing::kValid, kind);
157 RawObject* raw_obj2 = ring->GetObjectForId(raw_obj_id2, &kind); 157 RawObject* raw_obj2 = ring->GetObjectForId(raw_obj_id2, &kind);
158 EXPECT_EQ(ObjectIdRing::kValid, kind); 158 EXPECT_EQ(ObjectIdRing::kValid, kind);
159 EXPECT_NE(Object::null(), raw_obj1); 159 EXPECT_NE(Object::null(), raw_obj1);
160 EXPECT_NE(Object::null(), raw_obj2); 160 EXPECT_NE(Object::null(), raw_obj2);
161 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj1)); 161 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj1));
162 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj2)); 162 EXPECT_EQ(RawObject::ToAddr(raw_obj), RawObject::ToAddr(raw_obj2));
163 // Force a scavenge. 163 {
164 heap->CollectGarbage(Heap::kNew); 164 TransitionNativeToVM transition(thread);
165 // Force a scavenge.
166 heap->CollectGarbage(Heap::kNew);
167 }
165 RawObject* raw_object_moved1 = ring->GetObjectForId(raw_obj_id1, &kind); 168 RawObject* raw_object_moved1 = ring->GetObjectForId(raw_obj_id1, &kind);
166 EXPECT_EQ(ObjectIdRing::kValid, kind); 169 EXPECT_EQ(ObjectIdRing::kValid, kind);
167 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind); 170 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind);
168 EXPECT_EQ(ObjectIdRing::kValid, kind); 171 EXPECT_EQ(ObjectIdRing::kValid, kind);
169 EXPECT_NE(Object::null(), raw_object_moved1); 172 EXPECT_NE(Object::null(), raw_object_moved1);
170 EXPECT_NE(Object::null(), raw_object_moved2); 173 EXPECT_NE(Object::null(), raw_object_moved2);
171 EXPECT_EQ(RawObject::ToAddr(raw_object_moved1), 174 EXPECT_EQ(RawObject::ToAddr(raw_object_moved1),
172 RawObject::ToAddr(raw_object_moved2)); 175 RawObject::ToAddr(raw_object_moved2));
173 // Test that objects have moved. 176 // Test that objects have moved.
174 EXPECT_NE(RawObject::ToAddr(raw_obj1), RawObject::ToAddr(raw_object_moved1)); 177 EXPECT_NE(RawObject::ToAddr(raw_obj1), RawObject::ToAddr(raw_object_moved1));
175 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2)); 178 EXPECT_NE(RawObject::ToAddr(raw_obj2), RawObject::ToAddr(raw_object_moved2));
176 // Test that we still point at the same list. 179 // Test that we still point at the same list.
177 Dart_Handle moved_handle = Api::NewHandle(thread, raw_object_moved1); 180 Dart_Handle moved_handle = Api::NewHandle(thread, raw_object_moved1);
178 EXPECT_VALID(moved_handle); 181 EXPECT_VALID(moved_handle);
179 EXPECT(!Dart_IsNull(moved_handle)); 182 EXPECT(!Dart_IsNull(moved_handle));
180 EXPECT(Dart_IsList(moved_handle)); 183 EXPECT(Dart_IsList(moved_handle));
181 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length)); 184 EXPECT_VALID(Dart_ListLength(moved_handle, &list_length));
182 EXPECT_EQ(3, list_length); 185 EXPECT_EQ(3, list_length);
183 // Test id reuse. 186 // Test id reuse.
184 EXPECT_EQ(raw_obj_id1, 187 EXPECT_EQ(raw_obj_id1,
185 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId)); 188 ring->GetIdForObject(raw_object_moved1, ObjectIdRing::kReuseId));
186 } 189 }
187 190
188 191
189 // 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.
190 TEST_CASE(ObjectIdRingOldGCTest) { 193 VM_TEST_CASE(ObjectIdRingOldGCTest) {
191 Isolate* isolate = thread->isolate(); 194 Isolate* isolate = thread->isolate();
192 Heap* heap = isolate->heap(); 195 Heap* heap = isolate->heap();
193 ObjectIdRing* ring = isolate->object_id_ring(); 196 ObjectIdRing* ring = isolate->object_id_ring();
194 197
195 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; 198 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid;
196 intptr_t raw_obj_id1 = -1; 199 intptr_t raw_obj_id1 = -1;
197 intptr_t raw_obj_id2 = -1; 200 intptr_t raw_obj_id2 = -1;
198 { 201 {
199 Dart_EnterScope(); 202 Dart_EnterScope();
200 Dart_Handle result; 203 Dart_Handle result;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 EXPECT_EQ(ObjectIdRing::kCollected, kind); 237 EXPECT_EQ(ObjectIdRing::kCollected, kind);
235 EXPECT_EQ(Object::null(), raw_object_moved1); 238 EXPECT_EQ(Object::null(), raw_object_moved1);
236 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind); 239 RawObject* raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind);
237 EXPECT_EQ(ObjectIdRing::kCollected, kind); 240 EXPECT_EQ(ObjectIdRing::kCollected, kind);
238 EXPECT_EQ(Object::null(), raw_object_moved2); 241 EXPECT_EQ(Object::null(), raw_object_moved2);
239 } 242 }
240 243
241 244
242 // Test that the ring table correctly reports an entry as expired when it is 245 // Test that the ring table correctly reports an entry as expired when it is
243 // overridden by new entries. 246 // overridden by new entries.
244 TEST_CASE(ObjectIdRingExpiredEntryTest) { 247 VM_TEST_CASE(ObjectIdRingExpiredEntryTest) {
245 Isolate* isolate = Isolate::Current(); 248 Isolate* isolate = Isolate::Current();
246 ObjectIdRing* ring = isolate->object_id_ring(); 249 ObjectIdRing* ring = isolate->object_id_ring();
247 250
248 // Insert an object and check we can look it up. 251 // Insert an object and check we can look it up.
249 String& obj = String::Handle(String::New("I will expire")); 252 String& obj = String::Handle(String::New("I will expire"));
250 intptr_t obj_id = ring->GetIdForObject(obj.raw()); 253 intptr_t obj_id = ring->GetIdForObject(obj.raw());
251 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; 254 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid;
252 RawObject* obj_lookup = ring->GetObjectForId(obj_id, &kind); 255 RawObject* obj_lookup = ring->GetObjectForId(obj_id, &kind);
253 EXPECT_EQ(ObjectIdRing::kValid, kind); 256 EXPECT_EQ(ObjectIdRing::kValid, kind);
254 EXPECT_EQ(obj.raw(), obj_lookup); 257 EXPECT_EQ(obj.raw(), obj_lookup);
(...skipping 10 matching lines...) Expand all
265 } 268 }
266 269
267 // Check our first entry reports it has expired. 270 // Check our first entry reports it has expired.
268 obj_lookup = ring->GetObjectForId(obj_id, &kind); 271 obj_lookup = ring->GetObjectForId(obj_id, &kind);
269 EXPECT_EQ(ObjectIdRing::kExpired, kind); 272 EXPECT_EQ(ObjectIdRing::kExpired, kind);
270 EXPECT_NE(obj.raw(), obj_lookup); 273 EXPECT_NE(obj.raw(), obj_lookup);
271 EXPECT_EQ(Object::null(), obj_lookup); 274 EXPECT_EQ(Object::null(), obj_lookup);
272 } 275 }
273 276
274 } // namespace dart 277 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_graph_test.cc ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698