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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 306 |
307 static int NumberOfWeakCalls = 0; | 307 static int NumberOfWeakCalls = 0; |
308 static void WeakPointerCallback(v8::Isolate* isolate, | 308 static void WeakPointerCallback(v8::Isolate* isolate, |
309 v8::Persistent<v8::Value> handle, | 309 v8::Persistent<v8::Value> handle, |
310 void* id) { | 310 void* id) { |
311 ASSERT(id == reinterpret_cast<void*>(1234)); | 311 ASSERT(id == reinterpret_cast<void*>(1234)); |
312 NumberOfWeakCalls++; | 312 NumberOfWeakCalls++; |
313 handle.Dispose(isolate); | 313 handle.Dispose(isolate); |
314 } | 314 } |
315 | 315 |
316 TEST(ObjectGroups) { | 316 TEST(ObjectGroupsOldApi) { |
317 FLAG_incremental_marking = false; | 317 FLAG_incremental_marking = false; |
318 InitializeVM(); | 318 InitializeVM(); |
319 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 319 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
320 | 320 |
321 NumberOfWeakCalls = 0; | 321 NumberOfWeakCalls = 0; |
322 v8::HandleScope handle_scope(env->GetIsolate()); | 322 v8::HandleScope handle_scope(env->GetIsolate()); |
323 | 323 |
324 Handle<Object> g1s1 = | 324 Handle<Object> g1s1 = |
325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
326 Handle<Object> g1s2 = | 326 Handle<Object> g1s2 = |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 &WeakPointerCallback); | 419 &WeakPointerCallback); |
420 global_handles->MakeWeak(g2c1.location(), | 420 global_handles->MakeWeak(g2c1.location(), |
421 reinterpret_cast<void*>(1234), | 421 reinterpret_cast<void*>(1234), |
422 NULL, | 422 NULL, |
423 &WeakPointerCallback); | 423 &WeakPointerCallback); |
424 | 424 |
425 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 425 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
426 CHECK_EQ(7, NumberOfWeakCalls); | 426 CHECK_EQ(7, NumberOfWeakCalls); |
427 } | 427 } |
428 | 428 |
429 TEST(ObjectGroups) { | |
430 FLAG_incremental_marking = false; | |
431 InitializeVM(); | |
432 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | |
Sven Panne
2013/04/10 10:58:52
Use CcTest::isolate().
marja
2013/04/10 13:14:51
Done.
| |
433 | |
434 NumberOfWeakCalls = 0; | |
435 v8::HandleScope handle_scope(env->GetIsolate()); | |
Sven Panne
2013/04/10 10:58:52
Same here.
marja
2013/04/10 13:14:51
Done.
| |
436 | |
437 Handle<Object> g1s1 = | |
438 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
Sven Panne
2013/04/10 10:58:52
Use CcTest::isolate()->heap(), perhaps store this
marja
2013/04/10 13:14:51
Done.
| |
439 Handle<Object> g1s2 = | |
440 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
441 Handle<Object> g1c1 = | |
442 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
443 global_handles->MakeWeak(g1s1.location(), | |
444 reinterpret_cast<void*>(1234), | |
445 NULL, | |
446 &WeakPointerCallback); | |
447 global_handles->MakeWeak(g1s2.location(), | |
448 reinterpret_cast<void*>(1234), | |
449 NULL, | |
450 &WeakPointerCallback); | |
451 global_handles->MakeWeak(g1c1.location(), | |
452 reinterpret_cast<void*>(1234), | |
453 NULL, | |
454 &WeakPointerCallback); | |
455 | |
456 Handle<Object> g2s1 = | |
457 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
458 Handle<Object> g2s2 = | |
459 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
460 Handle<Object> g2c1 = | |
461 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | |
462 global_handles->MakeWeak(g2s1.location(), | |
463 reinterpret_cast<void*>(1234), | |
464 NULL, | |
465 &WeakPointerCallback); | |
466 global_handles->MakeWeak(g2s2.location(), | |
467 reinterpret_cast<void*>(1234), | |
468 NULL, | |
469 &WeakPointerCallback); | |
470 global_handles->MakeWeak(g2c1.location(), | |
471 reinterpret_cast<void*>(1234), | |
472 NULL, | |
473 &WeakPointerCallback); | |
474 | |
475 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | |
476 | |
477 // Connect group 1 and 2, make a cycle. | |
478 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | |
479 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | |
480 | |
481 { | |
482 Object** g1_children[] = { g1c1.location() }; | |
483 Object** g2_children[] = { g2c1.location() }; | |
484 global_handles->SetObjectGroupId(g1s1.location(), v8::UniqueId(1)); | |
485 global_handles->SetObjectGroupId(g1s2.location(), v8::UniqueId(1)); | |
486 global_handles->AddImplicitReferences( | |
487 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | |
488 global_handles->SetObjectGroupId(g2s1.location(), v8::UniqueId(2)); | |
489 global_handles->SetObjectGroupId(g2s2.location(), v8::UniqueId(2)); | |
490 global_handles->AddImplicitReferences( | |
491 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); | |
492 } | |
493 // Do a full GC | |
494 HEAP->CollectGarbage(OLD_POINTER_SPACE); | |
495 | |
496 // All object should be alive. | |
497 CHECK_EQ(0, NumberOfWeakCalls); | |
498 | |
499 // Weaken the root. | |
500 global_handles->MakeWeak(root.location(), | |
501 reinterpret_cast<void*>(1234), | |
502 NULL, | |
503 &WeakPointerCallback); | |
504 // But make children strong roots---all the objects (except for children) | |
505 // should be collectable now. | |
506 global_handles->ClearWeakness(g1c1.location()); | |
507 global_handles->ClearWeakness(g2c1.location()); | |
508 | |
509 // Groups are deleted, rebuild groups. | |
510 { | |
511 Object** g1_children[] = { g1c1.location() }; | |
512 Object** g2_children[] = { g2c1.location() }; | |
513 global_handles->SetObjectGroupId(g1s1.location(), v8::UniqueId(1)); | |
514 global_handles->SetObjectGroupId(g1s2.location(), v8::UniqueId(1)); | |
515 global_handles->AddImplicitReferences( | |
516 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | |
517 global_handles->SetObjectGroupId(g2s1.location(), v8::UniqueId(2)); | |
518 global_handles->SetObjectGroupId(g2s2.location(), v8::UniqueId(2)); | |
519 global_handles->AddImplicitReferences( | |
520 Handle<HeapObject>::cast(g2s2).location(), g2_children, 1); | |
521 } | |
522 | |
523 HEAP->CollectGarbage(OLD_POINTER_SPACE); | |
524 | |
525 // All objects should be gone. 5 global handles in total. | |
526 CHECK_EQ(5, NumberOfWeakCalls); | |
527 | |
528 // And now make children weak again and collect them. | |
529 global_handles->MakeWeak(g1c1.location(), | |
530 reinterpret_cast<void*>(1234), | |
531 NULL, | |
532 &WeakPointerCallback); | |
533 global_handles->MakeWeak(g2c1.location(), | |
534 reinterpret_cast<void*>(1234), | |
535 NULL, | |
536 &WeakPointerCallback); | |
537 | |
538 HEAP->CollectGarbage(OLD_POINTER_SPACE); | |
539 CHECK_EQ(7, NumberOfWeakCalls); | |
540 } | |
541 | |
429 | 542 |
430 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 543 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
431 public: | 544 public: |
432 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 545 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
433 | 546 |
434 bool has_been_disposed() { return has_been_disposed_; } | 547 bool has_been_disposed() { return has_been_disposed_; } |
435 | 548 |
436 virtual void Dispose() { | 549 virtual void Dispose() { |
437 ASSERT(!has_been_disposed_); | 550 ASSERT(!has_been_disposed_); |
438 has_been_disposed_ = true; | 551 has_been_disposed_ = true; |
439 } | 552 } |
440 | 553 |
441 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { | 554 virtual bool IsEquivalent(v8::RetainedObjectInfo* other) { |
442 return other == this; | 555 return other == this; |
443 } | 556 } |
444 | 557 |
445 virtual intptr_t GetHash() { return 0; } | 558 virtual intptr_t GetHash() { return 0; } |
446 | 559 |
447 virtual const char* GetLabel() { return "whatever"; } | 560 virtual const char* GetLabel() { return "whatever"; } |
448 | 561 |
449 private: | 562 private: |
450 bool has_been_disposed_; | 563 bool has_been_disposed_; |
451 }; | 564 }; |
452 | 565 |
453 | 566 |
454 TEST(EmptyObjectGroups) { | 567 TEST(EmptyObjectGroupsOldApi) { |
455 InitializeVM(); | 568 InitializeVM(); |
456 GlobalHandles* global_handles = Isolate::Current()->global_handles(); | 569 GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
457 | 570 |
458 v8::HandleScope handle_scope(env->GetIsolate()); | 571 v8::HandleScope handle_scope(env->GetIsolate()); |
459 | 572 |
460 Handle<Object> object = | 573 Handle<Object> object = |
461 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 574 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
462 | 575 |
463 TestRetainedObjectInfo info; | 576 TestRetainedObjectInfo info; |
464 global_handles->AddObjectGroup(NULL, 0, &info); | 577 global_handles->AddObjectGroup(NULL, 0, &info); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 if (v8::internal::Snapshot::IsEnabled()) { | 678 if (v8::internal::Snapshot::IsEnabled()) { |
566 CHECK_LE(delta, 2900 * 1024); | 679 CHECK_LE(delta, 2900 * 1024); |
567 } else { | 680 } else { |
568 CHECK_LE(delta, 3400 * 1024); | 681 CHECK_LE(delta, 3400 * 1024); |
569 } | 682 } |
570 } | 683 } |
571 } | 684 } |
572 } | 685 } |
573 | 686 |
574 #endif // __linux__ and !USE_SIMULATOR | 687 #endif // __linux__ and !USE_SIMULATOR |
OLD | NEW |