OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 TEST(Promotion) { | 75 TEST(Promotion) { |
76 // This test requires compaction. If compaction is turned off, we | 76 // This test requires compaction. If compaction is turned off, we |
77 // skip the entire test. | 77 // skip the entire test. |
78 if (FLAG_never_compact) return; | 78 if (FLAG_never_compact) return; |
79 | 79 |
80 // Ensure that we get a compacting collection so that objects are promoted | 80 // Ensure that we get a compacting collection so that objects are promoted |
81 // from new space. | 81 // from new space. |
82 FLAG_gc_global = true; | 82 FLAG_gc_global = true; |
83 FLAG_always_compact = true; | 83 FLAG_always_compact = true; |
84 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 84 Heap* heap = CcTest::heap(); |
| 85 heap->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
85 | 86 |
86 CcTest::InitializeVM(); | 87 CcTest::InitializeVM(); |
87 | 88 |
88 v8::HandleScope sc(CcTest::isolate()); | 89 v8::HandleScope sc(CcTest::isolate()); |
89 | 90 |
90 // Allocate a fixed array in the new space. | 91 // Allocate a fixed array in the new space. |
91 int array_size = | 92 int array_size = |
92 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / | 93 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
93 (kPointerSize * 4); | 94 (kPointerSize * 4); |
94 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); | 95 Object* obj = heap->AllocateFixedArray(array_size)->ToObjectChecked(); |
95 | 96 |
96 Handle<FixedArray> array(FixedArray::cast(obj)); | 97 Handle<FixedArray> array(FixedArray::cast(obj)); |
97 | 98 |
98 // Array should be in the new space. | 99 // Array should be in the new space. |
99 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 100 CHECK(heap->InSpace(*array, NEW_SPACE)); |
100 | 101 |
101 // Call the m-c collector, so array becomes an old object. | 102 // Call the m-c collector, so array becomes an old object. |
102 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 103 heap->CollectGarbage(OLD_POINTER_SPACE); |
103 | 104 |
104 // Array now sits in the old space | 105 // Array now sits in the old space |
105 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); | 106 CHECK(heap->InSpace(*array, OLD_POINTER_SPACE)); |
106 } | 107 } |
107 | 108 |
108 | 109 |
109 TEST(NoPromotion) { | 110 TEST(NoPromotion) { |
110 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); | 111 CcTest::heap()->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
111 | 112 |
112 // Test the situation that some objects in new space are promoted to | 113 // Test the situation that some objects in new space are promoted to |
113 // the old space | 114 // the old space |
114 CcTest::InitializeVM(); | 115 CcTest::InitializeVM(); |
115 | 116 |
116 v8::HandleScope sc(CcTest::isolate()); | 117 v8::HandleScope sc(CcTest::isolate()); |
117 | 118 |
118 // Do a mark compact GC to shrink the heap. | 119 // Do a mark compact GC to shrink the heap. |
119 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 120 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
120 | 121 |
121 // Allocate a big Fixed array in the new space. | 122 // Allocate a big Fixed array in the new space. |
122 int length = (Page::kMaxNonCodeHeapObjectSize - | 123 int length = (Page::kMaxNonCodeHeapObjectSize - |
123 FixedArray::kHeaderSize) / (2 * kPointerSize); | 124 FixedArray::kHeaderSize) / (2 * kPointerSize); |
124 Object* obj = CcTest::i_isolate()->heap()->AllocateFixedArray(length)-> | 125 Object* obj = CcTest::heap()->AllocateFixedArray(length)-> |
125 ToObjectChecked(); | 126 ToObjectChecked(); |
126 | 127 |
127 Handle<FixedArray> array(FixedArray::cast(obj)); | 128 Handle<FixedArray> array(FixedArray::cast(obj)); |
128 | 129 |
129 // Array still stays in the new space. | 130 // Array still stays in the new space. |
130 CHECK(HEAP->InSpace(*array, NEW_SPACE)); | 131 CHECK(CcTest::heap()->InSpace(*array, NEW_SPACE)); |
131 | 132 |
132 // Allocate objects in the old space until out of memory. | 133 // Allocate objects in the old space until out of memory. |
133 FixedArray* host = *array; | 134 FixedArray* host = *array; |
134 while (true) { | 135 while (true) { |
135 Object* obj; | 136 Object* obj; |
136 { MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED); | 137 { MaybeObject* maybe_obj = CcTest::heap()->AllocateFixedArray(100, TENURED); |
137 if (!maybe_obj->ToObject(&obj)) break; | 138 if (!maybe_obj->ToObject(&obj)) break; |
138 } | 139 } |
139 | 140 |
140 host->set(0, obj); | 141 host->set(0, obj); |
141 host = FixedArray::cast(obj); | 142 host = FixedArray::cast(obj); |
142 } | 143 } |
143 | 144 |
144 // Call mark compact GC, and it should pass. | 145 // Call mark compact GC, and it should pass. |
145 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 146 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
146 } | 147 } |
147 | 148 |
148 | 149 |
149 TEST(MarkCompactCollector) { | 150 TEST(MarkCompactCollector) { |
150 FLAG_incremental_marking = false; | 151 FLAG_incremental_marking = false; |
151 CcTest::InitializeVM(); | 152 CcTest::InitializeVM(); |
152 Isolate* isolate = CcTest::i_isolate(); | 153 Isolate* isolate = CcTest::i_isolate(); |
153 Heap* heap = isolate->heap(); | 154 Heap* heap = isolate->heap(); |
154 | 155 |
155 v8::HandleScope sc(CcTest::isolate()); | 156 v8::HandleScope sc(CcTest::isolate()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 249 |
249 { | 250 { |
250 v8::HandleScope sc; | 251 v8::HandleScope sc; |
251 // keep allocating maps while pointers are still encodable and thus | 252 // keep allocating maps while pointers are still encodable and thus |
252 // mark compact is permitted. | 253 // mark compact is permitted. |
253 Handle<JSObject> root = factory->NewJSObjectFromMap(CreateMap()); | 254 Handle<JSObject> root = factory->NewJSObjectFromMap(CreateMap()); |
254 do { | 255 do { |
255 Handle<Map> map = CreateMap(); | 256 Handle<Map> map = CreateMap(); |
256 map->set_prototype(*root); | 257 map->set_prototype(*root); |
257 root = factory->NewJSObjectFromMap(map); | 258 root = factory->NewJSObjectFromMap(map); |
258 } while (HEAP->map_space()->MapPointersEncodable()); | 259 } while (CcTest::heap()->map_space()->MapPointersEncodable()); |
259 } | 260 } |
260 // Now, as we don't have any handles to just allocated maps, we should | 261 // Now, as we don't have any handles to just allocated maps, we should |
261 // be able to trigger map compaction. | 262 // be able to trigger map compaction. |
262 // To give an additional chance to fail, try to force compaction which | 263 // To give an additional chance to fail, try to force compaction which |
263 // should be impossible right now. | 264 // should be impossible right now. |
264 HEAP->CollectAllGarbage(Heap::kForceCompactionMask); | 265 CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask); |
265 // And now map pointers should be encodable again. | 266 // And now map pointers should be encodable again. |
266 CHECK(HEAP->map_space()->MapPointersEncodable()); | 267 CHECK(CcTest::heap()->map_space()->MapPointersEncodable()); |
267 } | 268 } |
268 #endif | 269 #endif |
269 | 270 |
270 | 271 |
271 static int NumberOfWeakCalls = 0; | 272 static int NumberOfWeakCalls = 0; |
272 static void WeakPointerCallback(v8::Isolate* isolate, | 273 static void WeakPointerCallback(v8::Isolate* isolate, |
273 v8::Persistent<v8::Value>* handle, | 274 v8::Persistent<v8::Value>* handle, |
274 void* id) { | 275 void* id) { |
275 ASSERT(id == reinterpret_cast<void*>(1234)); | 276 ASSERT(id == reinterpret_cast<void*>(1234)); |
276 NumberOfWeakCalls++; | 277 NumberOfWeakCalls++; |
277 handle->Dispose(); | 278 handle->Dispose(); |
278 } | 279 } |
279 | 280 |
280 | 281 |
281 TEST(ObjectGroups) { | 282 TEST(ObjectGroups) { |
282 FLAG_incremental_marking = false; | 283 FLAG_incremental_marking = false; |
283 CcTest::InitializeVM(); | 284 CcTest::InitializeVM(); |
284 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); | 285 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
285 | 286 Heap* heap = CcTest::heap(); |
286 NumberOfWeakCalls = 0; | 287 NumberOfWeakCalls = 0; |
287 v8::HandleScope handle_scope(CcTest::isolate()); | 288 v8::HandleScope handle_scope(CcTest::isolate()); |
288 | 289 |
289 Handle<Object> g1s1 = | 290 Handle<Object> g1s1 = |
290 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 291 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
291 Handle<Object> g1s2 = | 292 Handle<Object> g1s2 = |
292 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 293 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
293 Handle<Object> g1c1 = | 294 Handle<Object> g1c1 = |
294 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 295 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
295 global_handles->MakeWeak(g1s1.location(), | 296 global_handles->MakeWeak(g1s1.location(), |
296 reinterpret_cast<void*>(1234), | 297 reinterpret_cast<void*>(1234), |
297 &WeakPointerCallback); | 298 &WeakPointerCallback); |
298 global_handles->MakeWeak(g1s2.location(), | 299 global_handles->MakeWeak(g1s2.location(), |
299 reinterpret_cast<void*>(1234), | 300 reinterpret_cast<void*>(1234), |
300 &WeakPointerCallback); | 301 &WeakPointerCallback); |
301 global_handles->MakeWeak(g1c1.location(), | 302 global_handles->MakeWeak(g1c1.location(), |
302 reinterpret_cast<void*>(1234), | 303 reinterpret_cast<void*>(1234), |
303 &WeakPointerCallback); | 304 &WeakPointerCallback); |
304 | 305 |
305 Handle<Object> g2s1 = | 306 Handle<Object> g2s1 = |
306 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 307 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
307 Handle<Object> g2s2 = | 308 Handle<Object> g2s2 = |
308 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 309 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
309 Handle<Object> g2c1 = | 310 Handle<Object> g2c1 = |
310 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 311 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); |
311 global_handles->MakeWeak(g2s1.location(), | 312 global_handles->MakeWeak(g2s1.location(), |
312 reinterpret_cast<void*>(1234), | 313 reinterpret_cast<void*>(1234), |
313 &WeakPointerCallback); | 314 &WeakPointerCallback); |
314 global_handles->MakeWeak(g2s2.location(), | 315 global_handles->MakeWeak(g2s2.location(), |
315 reinterpret_cast<void*>(1234), | 316 reinterpret_cast<void*>(1234), |
316 &WeakPointerCallback); | 317 &WeakPointerCallback); |
317 global_handles->MakeWeak(g2c1.location(), | 318 global_handles->MakeWeak(g2c1.location(), |
318 reinterpret_cast<void*>(1234), | 319 reinterpret_cast<void*>(1234), |
319 &WeakPointerCallback); | 320 &WeakPointerCallback); |
320 | 321 |
321 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | 322 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
322 | 323 |
323 // Connect group 1 and 2, make a cycle. | 324 // Connect group 1 and 2, make a cycle. |
324 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 325 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
325 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 326 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
326 | 327 |
327 { | 328 { |
328 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 329 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
329 Object** g1_children[] = { g1c1.location() }; | 330 Object** g1_children[] = { g1c1.location() }; |
330 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 331 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
331 Object** g2_children[] = { g2c1.location() }; | 332 Object** g2_children[] = { g2c1.location() }; |
332 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 333 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
333 global_handles->AddImplicitReferences( | 334 global_handles->AddImplicitReferences( |
334 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 335 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
335 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 336 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
336 global_handles->AddImplicitReferences( | 337 global_handles->AddImplicitReferences( |
337 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 338 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
338 } | 339 } |
339 // Do a full GC | 340 // Do a full GC |
340 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 341 heap->CollectGarbage(OLD_POINTER_SPACE); |
341 | 342 |
342 // All object should be alive. | 343 // All object should be alive. |
343 CHECK_EQ(0, NumberOfWeakCalls); | 344 CHECK_EQ(0, NumberOfWeakCalls); |
344 | 345 |
345 // Weaken the root. | 346 // Weaken the root. |
346 global_handles->MakeWeak(root.location(), | 347 global_handles->MakeWeak(root.location(), |
347 reinterpret_cast<void*>(1234), | 348 reinterpret_cast<void*>(1234), |
348 &WeakPointerCallback); | 349 &WeakPointerCallback); |
349 // But make children strong roots---all the objects (except for children) | 350 // But make children strong roots---all the objects (except for children) |
350 // should be collectable now. | 351 // should be collectable now. |
351 global_handles->ClearWeakness(g1c1.location()); | 352 global_handles->ClearWeakness(g1c1.location()); |
352 global_handles->ClearWeakness(g2c1.location()); | 353 global_handles->ClearWeakness(g2c1.location()); |
353 | 354 |
354 // Groups are deleted, rebuild groups. | 355 // Groups are deleted, rebuild groups. |
355 { | 356 { |
356 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 357 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
357 Object** g1_children[] = { g1c1.location() }; | 358 Object** g1_children[] = { g1c1.location() }; |
358 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 359 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
359 Object** g2_children[] = { g2c1.location() }; | 360 Object** g2_children[] = { g2c1.location() }; |
360 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 361 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
361 global_handles->AddImplicitReferences( | 362 global_handles->AddImplicitReferences( |
362 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 363 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
363 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 364 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
364 global_handles->AddImplicitReferences( | 365 global_handles->AddImplicitReferences( |
365 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 366 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
366 } | 367 } |
367 | 368 |
368 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 369 heap->CollectGarbage(OLD_POINTER_SPACE); |
369 | 370 |
370 // All objects should be gone. 5 global handles in total. | 371 // All objects should be gone. 5 global handles in total. |
371 CHECK_EQ(5, NumberOfWeakCalls); | 372 CHECK_EQ(5, NumberOfWeakCalls); |
372 | 373 |
373 // And now make children weak again and collect them. | 374 // And now make children weak again and collect them. |
374 global_handles->MakeWeak(g1c1.location(), | 375 global_handles->MakeWeak(g1c1.location(), |
375 reinterpret_cast<void*>(1234), | 376 reinterpret_cast<void*>(1234), |
376 &WeakPointerCallback); | 377 &WeakPointerCallback); |
377 global_handles->MakeWeak(g2c1.location(), | 378 global_handles->MakeWeak(g2c1.location(), |
378 reinterpret_cast<void*>(1234), | 379 reinterpret_cast<void*>(1234), |
379 &WeakPointerCallback); | 380 &WeakPointerCallback); |
380 | 381 |
381 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 382 heap->CollectGarbage(OLD_POINTER_SPACE); |
382 CHECK_EQ(7, NumberOfWeakCalls); | 383 CHECK_EQ(7, NumberOfWeakCalls); |
383 } | 384 } |
384 | 385 |
385 | 386 |
386 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 387 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
387 public: | 388 public: |
388 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 389 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
389 | 390 |
390 bool has_been_disposed() { return has_been_disposed_; } | 391 bool has_been_disposed() { return has_been_disposed_; } |
391 | 392 |
(...skipping 14 matching lines...) Expand all Loading... |
406 bool has_been_disposed_; | 407 bool has_been_disposed_; |
407 }; | 408 }; |
408 | 409 |
409 | 410 |
410 TEST(EmptyObjectGroups) { | 411 TEST(EmptyObjectGroups) { |
411 CcTest::InitializeVM(); | 412 CcTest::InitializeVM(); |
412 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); | 413 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); |
413 | 414 |
414 v8::HandleScope handle_scope(CcTest::isolate()); | 415 v8::HandleScope handle_scope(CcTest::isolate()); |
415 | 416 |
416 Handle<Object> object = | 417 Handle<Object> object = global_handles->Create( |
417 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 418 CcTest::heap()->AllocateFixedArray(1)->ToObjectChecked()); |
418 | 419 |
419 TestRetainedObjectInfo info; | 420 TestRetainedObjectInfo info; |
420 global_handles->AddObjectGroup(NULL, 0, &info); | 421 global_handles->AddObjectGroup(NULL, 0, &info); |
421 ASSERT(info.has_been_disposed()); | 422 ASSERT(info.has_been_disposed()); |
422 | 423 |
423 global_handles->AddImplicitReferences( | 424 global_handles->AddImplicitReferences( |
424 Handle<HeapObject>::cast(object).location(), NULL, 0); | 425 Handle<HeapObject>::cast(object).location(), NULL, 0); |
425 } | 426 } |
426 | 427 |
427 | 428 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 550 |
550 | 551 |
551 TEST(RegressJoinThreadsOnIsolateDeinit) { | 552 TEST(RegressJoinThreadsOnIsolateDeinit) { |
552 intptr_t size_limit = ShortLivingIsolate() * 2; | 553 intptr_t size_limit = ShortLivingIsolate() * 2; |
553 for (int i = 0; i < 10; i++) { | 554 for (int i = 0; i < 10; i++) { |
554 CHECK_GT(size_limit, ShortLivingIsolate()); | 555 CHECK_GT(size_limit, ShortLivingIsolate()); |
555 } | 556 } |
556 } | 557 } |
557 | 558 |
558 #endif // __linux__ and !USE_SIMULATOR | 559 #endif // __linux__ and !USE_SIMULATOR |
OLD | NEW |