| 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 : Bar() | 551 : Bar() |
| 552 , m_strongBar(strongBar) | 552 , m_strongBar(strongBar) |
| 553 , m_weakBar(weakBar) | 553 , m_weakBar(weakBar) |
| 554 { | 554 { |
| 555 } | 555 } |
| 556 | 556 |
| 557 Member<Bar> m_strongBar; | 557 Member<Bar> m_strongBar; |
| 558 WeakMember<Bar> m_weakBar; | 558 WeakMember<Bar> m_weakBar; |
| 559 }; | 559 }; |
| 560 | 560 |
| 561 |
| 562 class SuperClass; |
| 563 |
| 564 class PointsBack : public RefCountedWillBeGarbageCollectedFinalized<PointsBack>
{ |
| 565 DECLARE_GC_INFO; |
| 566 public: |
| 567 static PassRefPtrWillBePtr<PointsBack> create() |
| 568 { |
| 569 return adoptRefWillBeNoop(new PointsBack()); |
| 570 } |
| 571 |
| 572 ~PointsBack() |
| 573 { |
| 574 --s_aliveCount; |
| 575 } |
| 576 |
| 577 void setBackPointer(SuperClass* backPointer) |
| 578 { |
| 579 m_backPointer = backPointer; |
| 580 } |
| 581 |
| 582 SuperClass* backPointer() const { return m_backPointer; } |
| 583 |
| 584 void trace(Visitor* visitor) |
| 585 { |
| 586 #if ENABLE_OILPAN |
| 587 visitor->trace(m_backPointer); |
| 588 #endif |
| 589 } |
| 590 |
| 591 static int s_aliveCount; |
| 592 private: |
| 593 PointsBack() : m_backPointer(nullptr) |
| 594 { |
| 595 ++s_aliveCount; |
| 596 } |
| 597 |
| 598 PtrWillBeWeakMember<SuperClass> m_backPointer; |
| 599 }; |
| 600 |
| 601 int PointsBack::s_aliveCount = 0; |
| 602 |
| 603 class SuperClass : public RefCountedWillBeGarbageCollectedFinalized<SuperClass>
{ |
| 604 DECLARE_GC_INFO; |
| 605 public: |
| 606 static PassRefPtrWillBePtr<SuperClass> create(PassRefPtrWillBePtr<PointsBack
> pointsBack) |
| 607 { |
| 608 return adoptRefWillBeNoop(new SuperClass(pointsBack)); |
| 609 } |
| 610 |
| 611 virtual ~SuperClass() |
| 612 { |
| 613 #if !ENABLE_OILPAN |
| 614 m_pointsBack->setBackPointer(0); |
| 615 #endif |
| 616 --s_aliveCount; |
| 617 } |
| 618 |
| 619 void doStuff(PassRefPtrWillBePtr<SuperClass> targetPass, PointsBack* pointsB
ack, int superClassCount) |
| 620 { |
| 621 RefPtrWillBePtr<SuperClass> target = targetPass; |
| 622 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
| 623 EXPECT_EQ(pointsBack, target->pointsBack()); |
| 624 EXPECT_EQ(superClassCount, SuperClass::s_aliveCount); |
| 625 } |
| 626 |
| 627 virtual void trace(Visitor* visitor) |
| 628 { |
| 629 #if ENABLE_OILPAN |
| 630 visitor->trace(m_pointsBack); |
| 631 #endif |
| 632 } |
| 633 |
| 634 PointsBack* pointsBack() const { return m_pointsBack.get(); } |
| 635 |
| 636 static int s_aliveCount; |
| 637 protected: |
| 638 explicit SuperClass(PassRefPtrWillBePtr<PointsBack> pointsBack) |
| 639 : m_pointsBack(pointsBack) |
| 640 { |
| 641 m_pointsBack->setBackPointer(this); |
| 642 ++s_aliveCount; |
| 643 } |
| 644 |
| 645 private: |
| 646 RefPtrWillBeMember<PointsBack> m_pointsBack; |
| 647 }; |
| 648 |
| 649 int SuperClass::s_aliveCount = 0; |
| 650 class SubData : public NoBaseWillBeGarbageCollectedFinalized<SubData> { |
| 651 DECLARE_GC_INFO |
| 652 public: |
| 653 SubData() { ++s_aliveCount; } |
| 654 ~SubData() { --s_aliveCount; } |
| 655 |
| 656 void trace(Visitor*) { } |
| 657 |
| 658 static int s_aliveCount; |
| 659 }; |
| 660 |
| 661 int SubData::s_aliveCount = 0; |
| 662 |
| 663 class SubClass : public SuperClass { |
| 664 public: |
| 665 static PassRefPtrWillBePtr<SubClass> create(PassRefPtrWillBePtr<PointsBack>
pointsBack) |
| 666 { |
| 667 return adoptRefWillBeNoop(new SubClass(pointsBack)); |
| 668 } |
| 669 |
| 670 virtual ~SubClass() |
| 671 { |
| 672 --s_aliveCount; |
| 673 } |
| 674 |
| 675 virtual void trace(Visitor* visitor) |
| 676 { |
| 677 #if ENABLE_OILPAN |
| 678 SuperClass::trace(visitor); |
| 679 visitor->trace(m_data); |
| 680 #endif |
| 681 } |
| 682 |
| 683 static int s_aliveCount; |
| 684 private: |
| 685 explicit SubClass(PassRefPtrWillBePtr<PointsBack> pointsBack) |
| 686 : SuperClass(pointsBack) |
| 687 , m_data(adoptPtrWillBeNoop(new SubData())) |
| 688 { |
| 689 ++s_aliveCount; |
| 690 } |
| 691 |
| 692 private: |
| 693 OwnPtrWillBeMember<SubData> m_data; |
| 694 }; |
| 695 |
| 696 int SubClass::s_aliveCount = 0; |
| 697 |
| 698 TEST(HeapTest, Transition) |
| 699 { |
| 700 Heap::init(); |
| 701 |
| 702 { |
| 703 RefPtrWillBePersistent<PointsBack> pointsBack1 = PointsBack::create(); |
| 704 RefPtrWillBePersistent<PointsBack> pointsBack2 = PointsBack::create(); |
| 705 RefPtrWillBePersistent<SuperClass> superClass = SuperClass::create(point
sBack1); |
| 706 RefPtrWillBePersistent<SubClass> subClass = SubClass::create(pointsBack2
); |
| 707 EXPECT_EQ(2, PointsBack::s_aliveCount); |
| 708 EXPECT_EQ(2, SuperClass::s_aliveCount); |
| 709 EXPECT_EQ(1, SubClass::s_aliveCount); |
| 710 EXPECT_EQ(1, SubData::s_aliveCount); |
| 711 |
| 712 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 713 EXPECT_EQ(2, PointsBack::s_aliveCount); |
| 714 EXPECT_EQ(2, SuperClass::s_aliveCount); |
| 715 EXPECT_EQ(1, SubClass::s_aliveCount); |
| 716 EXPECT_EQ(1, SubData::s_aliveCount); |
| 717 |
| 718 superClass->doStuff(superClass.release(), pointsBack1.get(), 2); |
| 719 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 720 EXPECT_EQ(2, PointsBack::s_aliveCount); |
| 721 EXPECT_EQ(1, SuperClass::s_aliveCount); |
| 722 EXPECT_EQ(1, SubClass::s_aliveCount); |
| 723 EXPECT_EQ(1, SubData::s_aliveCount); |
| 724 EXPECT_EQ(0, pointsBack1->backPointer()); |
| 725 |
| 726 pointsBack1.release(); |
| 727 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 728 EXPECT_EQ(1, PointsBack::s_aliveCount); |
| 729 EXPECT_EQ(1, SuperClass::s_aliveCount); |
| 730 EXPECT_EQ(1, SubClass::s_aliveCount); |
| 731 EXPECT_EQ(1, SubData::s_aliveCount); |
| 732 |
| 733 subClass->doStuff(subClass.release(), pointsBack2.get(), 1); |
| 734 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 735 EXPECT_EQ(1, PointsBack::s_aliveCount); |
| 736 EXPECT_EQ(0, SuperClass::s_aliveCount); |
| 737 EXPECT_EQ(0, SubClass::s_aliveCount); |
| 738 EXPECT_EQ(0, SubData::s_aliveCount); |
| 739 EXPECT_EQ(0, pointsBack2->backPointer()); |
| 740 |
| 741 pointsBack2.release(); |
| 742 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 743 EXPECT_EQ(0, PointsBack::s_aliveCount); |
| 744 EXPECT_EQ(0, SuperClass::s_aliveCount); |
| 745 EXPECT_EQ(0, SubClass::s_aliveCount); |
| 746 EXPECT_EQ(0, SubData::s_aliveCount); |
| 747 |
| 748 EXPECT_TRUE(superClass == subClass); |
| 749 } |
| 750 |
| 751 Heap::shutdown(); |
| 752 } |
| 753 |
| 561 TEST(HeapTest, Threading) | 754 TEST(HeapTest, Threading) |
| 562 { | 755 { |
| 563 Heap::init(); | 756 Heap::init(); |
| 564 ThreadedHeapTester::test(); | 757 ThreadedHeapTester::test(); |
| 565 Heap::shutdown(); | 758 Heap::shutdown(); |
| 566 } | 759 } |
| 567 | 760 |
| 568 TEST(HeapTest, Init) | 761 TEST(HeapTest, Init) |
| 569 { | 762 { |
| 570 // FIXME: init and shutdown should be called via Blink | 763 // FIXME: init and shutdown should be called via Blink |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 Heap::shutdown(); | 1215 Heap::shutdown(); |
| 1023 } | 1216 } |
| 1024 | 1217 |
| 1025 DEFINE_GC_INFO(Bar); | 1218 DEFINE_GC_INFO(Bar); |
| 1026 DEFINE_GC_INFO(Baz); | 1219 DEFINE_GC_INFO(Baz); |
| 1027 DEFINE_GC_INFO(ClassWithMember); | 1220 DEFINE_GC_INFO(ClassWithMember); |
| 1028 DEFINE_GC_INFO(ConstructorAllocation); | 1221 DEFINE_GC_INFO(ConstructorAllocation); |
| 1029 DEFINE_GC_INFO(HeapAllocatedArray); | 1222 DEFINE_GC_INFO(HeapAllocatedArray); |
| 1030 DEFINE_GC_INFO(IntWrapper); | 1223 DEFINE_GC_INFO(IntWrapper); |
| 1031 DEFINE_GC_INFO(LargeObject); | 1224 DEFINE_GC_INFO(LargeObject); |
| 1225 DEFINE_GC_INFO(PointsBack); |
| 1032 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 1226 DEFINE_GC_INFO(RefCountedAndGarbageCollected); |
| 1033 DEFINE_GC_INFO(SimpleFinalizedObject); | 1227 DEFINE_GC_INFO(SimpleFinalizedObject); |
| 1228 DEFINE_GC_INFO(SuperClass); |
| 1229 DEFINE_GC_INFO(SubData); |
| 1034 DEFINE_GC_INFO(TestTypedHeapClass); | 1230 DEFINE_GC_INFO(TestTypedHeapClass); |
| 1035 DEFINE_GC_INFO(TraceCounter); | 1231 DEFINE_GC_INFO(TraceCounter); |
| 1036 | 1232 |
| 1037 } // namespace | 1233 } // namespace |
| OLD | NEW |