| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); | 341 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); |
| 342 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); | 342 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); |
| 343 // Destructors not called again when sweeping again. | 343 // Destructors not called again when sweeping again. |
| 344 Heap::sweep(); | 344 Heap::sweep(); |
| 345 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); | 345 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); |
| 346 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); | 346 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); |
| 347 } | 347 } |
| 348 | 348 |
| 349 static void refCountedHeapAllocatedTest() | 349 static void refCountedHeapAllocatedTest() |
| 350 { | 350 { |
| 351 RefCountedAndHeapAllocated::s_destructorCalls = 0; |
| 352 RefCountedAndHeapAllocated2::s_destructorCalls = 0; |
| 351 { | 353 { |
| 352 RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated::
create(); | 354 RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated::
create(); |
| 353 RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated::
create(); | 355 RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated::
create(); |
| 354 RefPtr<RefCountedAndHeapAllocated2> o3 = RefCountedAndHeapAllocated2
::create(); | 356 RefPtr<RefCountedAndHeapAllocated2> o3 = RefCountedAndHeapAllocated2
::create(); |
| 355 RefPtr<RefCountedAndHeapAllocated2> o4 = RefCountedAndHeapAllocated2
::create(); | 357 RefPtr<RefCountedAndHeapAllocated2> o4 = RefCountedAndHeapAllocated2
::create(); |
| 356 void* objects[4] = { o1.get(), o2.get(), o3.get(), o4.get() }; | 358 void* objects[4] = { o1.get(), o2.get(), o3.get(), o4.get() }; |
| 357 RefCountedHeapAllocatedHandleVisitor visitor(4, objects); | 359 RefCountedHeapAllocatedHandleVisitor visitor(4, objects); |
| 358 PersistentBase::visitRoots(&visitor); | 360 PersistentBase::visitRoots(&visitor); |
| 359 ASSERT_TRUE(visitor.validate()); | 361 ASSERT_TRUE(visitor.validate()); |
| 360 | 362 |
| 361 Heap::collectGarbage(); | 363 Heap::collectGarbage(); |
| 362 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); | 364 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| 363 ASSERT_EQ(0, RefCountedAndHeapAllocated2::s_destructorCalls); | 365 ASSERT_EQ(0, RefCountedAndHeapAllocated2::s_destructorCalls); |
| 364 } | 366 } |
| 365 Heap::collectGarbage(); | 367 Heap::collectGarbage(); |
| 366 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); | 368 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); |
| 367 ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls); | 369 ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls); |
| 368 } | 370 } |
| 369 | 371 |
| 372 static void refCountedHeapAllocatedWithHandlesTest() |
| 373 { |
| 374 RefCountedAndHeapAllocated::s_destructorCalls = 0; |
| 375 RefCountedAndHeapAllocated2::s_destructorCalls = 0; |
| 376 { |
| 377 HandleScope scope; |
| 378 Handle<RefCountedAndHeapAllocated> handle1; |
| 379 Handle<RefCountedAndHeapAllocated> handle2; |
| 380 { |
| 381 RefPtr<RefCountedAndHeapAllocated> object1 = RefCountedAndHeapAl
located::create(); |
| 382 RefPtr<RefCountedAndHeapAllocated> object2 = RefCountedAndHeapAl
located::create(); |
| 383 handle1 = Handle<RefCountedAndHeapAllocated>(object1.get()); |
| 384 handle2 = Handle<RefCountedAndHeapAllocated>(object2.get()); |
| 385 void* objects[2] = { object1.get(), object2.get() }; |
| 386 RefCountedHeapAllocatedHandleVisitor visitor(2, objects); |
| 387 PersistentBase::visitRoots(&visitor); |
| 388 ASSERT_TRUE(visitor.validate()); |
| 389 |
| 390 Heap::collectGarbage(); |
| 391 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| 392 } |
| 393 Heap::collectGarbage(); |
| 394 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| 395 |
| 396 // At this point, the reference counts of object1 and object2 are 0. |
| 397 // Only handle1 and handle2 keep references to object1 and object2. |
| 398 void* objects[] = { }; |
| 399 RefCountedHeapAllocatedHandleVisitor visitor(0, objects); |
| 400 PersistentBase::visitRoots(&visitor); |
| 401 ASSERT_TRUE(visitor.validate()); |
| 402 |
| 403 { |
| 404 RefPtr<RefCountedAndHeapAllocated> object1(handle1.raw()); |
| 405 RefPtr<RefCountedAndHeapAllocated> object2(handle2.raw()); |
| 406 void* objects[2] = { object1.get(), object2.get() }; |
| 407 RefCountedHeapAllocatedHandleVisitor visitor(2, objects); |
| 408 PersistentBase::visitRoots(&visitor); |
| 409 ASSERT_TRUE(visitor.validate()); |
| 410 |
| 411 Heap::collectGarbage(); |
| 412 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| 413 } |
| 414 |
| 415 Heap::collectGarbage(); |
| 416 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); |
| 417 } |
| 418 Heap::collectGarbage(); |
| 419 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); |
| 420 } |
| 421 |
| 370 static void markTest(); | 422 static void markTest(); |
| 371 static void deepTest(); | 423 static void deepTest(); |
| 372 static void wideTest(); | 424 static void wideTest(); |
| 373 static void memberTest(); | 425 static void memberTest(); |
| 374 }; | 426 }; |
| 375 | 427 |
| 376 class Bar { | 428 class Bar { |
| 377 DECLARE_GC_TYPE_MARKER | 429 DECLARE_GC_TYPE_MARKER |
| 378 public: | 430 public: |
| 379 Bar() | 431 Bar() |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 TEST(heap, Finalization) | 629 TEST(heap, Finalization) |
| 578 { | 630 { |
| 579 HeapTester::finalizationTest(); | 631 HeapTester::finalizationTest(); |
| 580 } | 632 } |
| 581 | 633 |
| 582 TEST(heap, RefCountedHeapAllocated) | 634 TEST(heap, RefCountedHeapAllocated) |
| 583 { | 635 { |
| 584 HeapTester::refCountedHeapAllocatedTest(); | 636 HeapTester::refCountedHeapAllocatedTest(); |
| 585 } | 637 } |
| 586 | 638 |
| 639 TEST(heap, RefCountedHeapAllocatedWithHandles) |
| 640 { |
| 641 HeapTester::refCountedHeapAllocatedWithHandlesTest(); |
| 642 } |
| 643 |
| 587 TEST(heap, Mark) | 644 TEST(heap, Mark) |
| 588 { | 645 { |
| 589 HeapTester::markTest(); | 646 HeapTester::markTest(); |
| 590 } | 647 } |
| 591 | 648 |
| 592 TEST(heap, Deep) | 649 TEST(heap, Deep) |
| 593 { | 650 { |
| 594 HeapTester::deepTest(); | 651 HeapTester::deepTest(); |
| 595 } | 652 } |
| 596 | 653 |
| 597 TEST(heap, Wide) | 654 TEST(heap, Wide) |
| 598 { | 655 { |
| 599 HeapTester::wideTest(); | 656 HeapTester::wideTest(); |
| 600 } | 657 } |
| 601 | 658 |
| 602 TEST(heap, Member) | 659 TEST(heap, Member) |
| 603 { | 660 { |
| 604 HeapTester::memberTest(); | 661 HeapTester::memberTest(); |
| 605 } | 662 } |
| 606 | 663 |
| 607 } // namespace WebCore | 664 } // namespace WebCore |
| OLD | NEW |