| 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 752         : Bar() | 752         : Bar() | 
| 753         , m_strongBar(strongBar) | 753         , m_strongBar(strongBar) | 
| 754         , m_weakBar(weakBar) | 754         , m_weakBar(weakBar) | 
| 755     { | 755     { | 
| 756     } | 756     } | 
| 757 | 757 | 
| 758     Member<Bar> m_strongBar; | 758     Member<Bar> m_strongBar; | 
| 759     WeakMember<Bar> m_weakBar; | 759     WeakMember<Bar> m_weakBar; | 
| 760 }; | 760 }; | 
| 761 | 761 | 
|  | 762 | 
|  | 763 class SuperClass; | 
|  | 764 | 
|  | 765 class PointsBack : public RefCountedWillBeGarbageCollectedFinalized<PointsBack> 
      { | 
|  | 766     DECLARE_GC_INFO; | 
|  | 767 public: | 
|  | 768     static PassRefPtrWillBePtr<PointsBack> create() | 
|  | 769     { | 
|  | 770         return adoptRefWillBeNoop(new PointsBack()); | 
|  | 771     } | 
|  | 772 | 
|  | 773     ~PointsBack() | 
|  | 774     { | 
|  | 775         --s_aliveCount; | 
|  | 776     } | 
|  | 777 | 
|  | 778     void setBackPointer(SuperClass* backPointer) | 
|  | 779     { | 
|  | 780         m_backPointer = backPointer; | 
|  | 781     } | 
|  | 782 | 
|  | 783     SuperClass* backPointer() const { return m_backPointer; } | 
|  | 784 | 
|  | 785     void trace(Visitor* visitor) | 
|  | 786     { | 
|  | 787 #if ENABLE_OILPAN | 
|  | 788         visitor->trace(m_backPointer); | 
|  | 789 #endif | 
|  | 790     } | 
|  | 791 | 
|  | 792     static int s_aliveCount; | 
|  | 793 private: | 
|  | 794     PointsBack() : m_backPointer(nullptr) | 
|  | 795     { | 
|  | 796         ++s_aliveCount; | 
|  | 797     } | 
|  | 798 | 
|  | 799     PtrWillBeWeakMember<SuperClass> m_backPointer; | 
|  | 800 }; | 
|  | 801 | 
|  | 802 int PointsBack::s_aliveCount = 0; | 
|  | 803 | 
|  | 804 class SuperClass : public RefCountedWillBeGarbageCollectedFinalized<SuperClass> 
      { | 
|  | 805     DECLARE_GC_INFO; | 
|  | 806 public: | 
|  | 807     static PassRefPtrWillBePtr<SuperClass> create(PassRefPtrWillBePtr<PointsBack
      > pointsBack) | 
|  | 808     { | 
|  | 809         return adoptRefWillBeNoop(new SuperClass(pointsBack)); | 
|  | 810     } | 
|  | 811 | 
|  | 812     virtual ~SuperClass() | 
|  | 813     { | 
|  | 814 #if !ENABLE_OILPAN | 
|  | 815         m_pointsBack->setBackPointer(0); | 
|  | 816 #endif | 
|  | 817         --s_aliveCount; | 
|  | 818     } | 
|  | 819 | 
|  | 820     void doStuff(PassRefPtrWillBePtr<SuperClass> targetPass, PointsBack* pointsB
      ack, int superClassCount) | 
|  | 821     { | 
|  | 822         RefPtrWillBePtr<SuperClass> target = targetPass; | 
|  | 823         Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 
|  | 824         EXPECT_EQ(pointsBack, target->pointsBack()); | 
|  | 825         EXPECT_EQ(superClassCount, SuperClass::s_aliveCount); | 
|  | 826     } | 
|  | 827 | 
|  | 828     virtual void trace(Visitor* visitor) | 
|  | 829     { | 
|  | 830 #if ENABLE_OILPAN | 
|  | 831         visitor->trace(m_pointsBack); | 
|  | 832 #endif | 
|  | 833     } | 
|  | 834 | 
|  | 835     PointsBack* pointsBack() const { return m_pointsBack.get(); } | 
|  | 836 | 
|  | 837     static int s_aliveCount; | 
|  | 838 protected: | 
|  | 839     explicit SuperClass(PassRefPtrWillBePtr<PointsBack> pointsBack) | 
|  | 840         : m_pointsBack(pointsBack) | 
|  | 841     { | 
|  | 842         m_pointsBack->setBackPointer(this); | 
|  | 843         ++s_aliveCount; | 
|  | 844     } | 
|  | 845 | 
|  | 846 private: | 
|  | 847     RefPtrWillBeMember<PointsBack> m_pointsBack; | 
|  | 848 }; | 
|  | 849 | 
|  | 850 int SuperClass::s_aliveCount = 0; | 
|  | 851 class SubData : public NoBaseWillBeGarbageCollectedFinalized<SubData> { | 
|  | 852     DECLARE_GC_INFO | 
|  | 853 public: | 
|  | 854     SubData() { ++s_aliveCount; } | 
|  | 855     ~SubData() { --s_aliveCount; } | 
|  | 856 | 
|  | 857     void trace(Visitor*) { } | 
|  | 858 | 
|  | 859     static int s_aliveCount; | 
|  | 860 }; | 
|  | 861 | 
|  | 862 int SubData::s_aliveCount = 0; | 
|  | 863 | 
|  | 864 class SubClass : public SuperClass { | 
|  | 865 public: | 
|  | 866     static PassRefPtrWillBePtr<SubClass> create(PassRefPtrWillBePtr<PointsBack> 
      pointsBack) | 
|  | 867     { | 
|  | 868         return adoptRefWillBeNoop(new SubClass(pointsBack)); | 
|  | 869     } | 
|  | 870 | 
|  | 871     virtual ~SubClass() | 
|  | 872     { | 
|  | 873         --s_aliveCount; | 
|  | 874     } | 
|  | 875 | 
|  | 876     virtual void trace(Visitor* visitor) | 
|  | 877     { | 
|  | 878 #if ENABLE_OILPAN | 
|  | 879         SuperClass::trace(visitor); | 
|  | 880         visitor->trace(m_data); | 
|  | 881 #endif | 
|  | 882     } | 
|  | 883 | 
|  | 884     static int s_aliveCount; | 
|  | 885 private: | 
|  | 886     explicit SubClass(PassRefPtrWillBePtr<PointsBack> pointsBack) | 
|  | 887         : SuperClass(pointsBack) | 
|  | 888         , m_data(adoptPtrWillBeNoop(new SubData())) | 
|  | 889     { | 
|  | 890         ++s_aliveCount; | 
|  | 891     } | 
|  | 892 | 
|  | 893 private: | 
|  | 894     OwnPtrWillBeMember<SubData> m_data; | 
|  | 895 }; | 
|  | 896 | 
|  | 897 int SubClass::s_aliveCount = 0; | 
|  | 898 | 
|  | 899 TEST(HeapTest, Transition) | 
|  | 900 { | 
|  | 901     RefPtrWillBePersistent<PointsBack> pointsBack1 = PointsBack::create(); | 
|  | 902     RefPtrWillBePersistent<PointsBack> pointsBack2 = PointsBack::create(); | 
|  | 903     RefPtrWillBePersistent<SuperClass> superClass = SuperClass::create(pointsBac
      k1); | 
|  | 904     RefPtrWillBePersistent<SubClass> subClass = SubClass::create(pointsBack2); | 
|  | 905     EXPECT_EQ(2, PointsBack::s_aliveCount); | 
|  | 906     EXPECT_EQ(2, SuperClass::s_aliveCount); | 
|  | 907     EXPECT_EQ(1, SubClass::s_aliveCount); | 
|  | 908     EXPECT_EQ(1, SubData::s_aliveCount); | 
|  | 909 | 
|  | 910     Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 
|  | 911     EXPECT_EQ(2, PointsBack::s_aliveCount); | 
|  | 912     EXPECT_EQ(2, SuperClass::s_aliveCount); | 
|  | 913     EXPECT_EQ(1, SubClass::s_aliveCount); | 
|  | 914     EXPECT_EQ(1, SubData::s_aliveCount); | 
|  | 915 | 
|  | 916     superClass->doStuff(superClass.release(), pointsBack1.get(), 2); | 
|  | 917     Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 
|  | 918     EXPECT_EQ(2, PointsBack::s_aliveCount); | 
|  | 919     EXPECT_EQ(1, SuperClass::s_aliveCount); | 
|  | 920     EXPECT_EQ(1, SubClass::s_aliveCount); | 
|  | 921     EXPECT_EQ(1, SubData::s_aliveCount); | 
|  | 922     EXPECT_EQ(0, pointsBack1->backPointer()); | 
|  | 923 | 
|  | 924     pointsBack1.release(); | 
|  | 925     Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 
|  | 926     EXPECT_EQ(1, PointsBack::s_aliveCount); | 
|  | 927     EXPECT_EQ(1, SuperClass::s_aliveCount); | 
|  | 928     EXPECT_EQ(1, SubClass::s_aliveCount); | 
|  | 929     EXPECT_EQ(1, SubData::s_aliveCount); | 
|  | 930 | 
|  | 931     subClass->doStuff(subClass.release(), pointsBack2.get(), 1); | 
|  | 932     Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 
|  | 933     EXPECT_EQ(1, PointsBack::s_aliveCount); | 
|  | 934     EXPECT_EQ(0, SuperClass::s_aliveCount); | 
|  | 935     EXPECT_EQ(0, SubClass::s_aliveCount); | 
|  | 936     EXPECT_EQ(0, SubData::s_aliveCount); | 
|  | 937     EXPECT_EQ(0, pointsBack2->backPointer()); | 
|  | 938 | 
|  | 939     pointsBack2.release(); | 
|  | 940     Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 
|  | 941     EXPECT_EQ(0, PointsBack::s_aliveCount); | 
|  | 942     EXPECT_EQ(0, SuperClass::s_aliveCount); | 
|  | 943     EXPECT_EQ(0, SubClass::s_aliveCount); | 
|  | 944     EXPECT_EQ(0, SubData::s_aliveCount); | 
|  | 945 | 
|  | 946     EXPECT_TRUE(superClass == subClass); | 
|  | 947 } | 
|  | 948 | 
| 762 TEST(HeapTest, Threading) | 949 TEST(HeapTest, Threading) | 
| 763 { | 950 { | 
| 764     ThreadedHeapTester::test(); | 951     ThreadedHeapTester::test(); | 
| 765 } | 952 } | 
| 766 | 953 | 
| 767 TEST(HeapTest, BasicFunctionality) | 954 TEST(HeapTest, BasicFunctionality) | 
| 768 { | 955 { | 
| 769     HeapStats heapStats; | 956     HeapStats heapStats; | 
| 770     clearOutOldGarbage(&heapStats); | 957     clearOutOldGarbage(&heapStats); | 
| 771     { | 958     { | 
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1420 } | 1607 } | 
| 1421 | 1608 | 
| 1422 DEFINE_GC_INFO(Bar); | 1609 DEFINE_GC_INFO(Bar); | 
| 1423 DEFINE_GC_INFO(Baz); | 1610 DEFINE_GC_INFO(Baz); | 
| 1424 DEFINE_GC_INFO(ClassWithMember); | 1611 DEFINE_GC_INFO(ClassWithMember); | 
| 1425 DEFINE_GC_INFO(ConstructorAllocation); | 1612 DEFINE_GC_INFO(ConstructorAllocation); | 
| 1426 DEFINE_GC_INFO(HeapAllocatedArray); | 1613 DEFINE_GC_INFO(HeapAllocatedArray); | 
| 1427 DEFINE_GC_INFO(HeapTestSuperClass); | 1614 DEFINE_GC_INFO(HeapTestSuperClass); | 
| 1428 DEFINE_GC_INFO(IntWrapper); | 1615 DEFINE_GC_INFO(IntWrapper); | 
| 1429 DEFINE_GC_INFO(LargeObject); | 1616 DEFINE_GC_INFO(LargeObject); | 
|  | 1617 DEFINE_GC_INFO(PointsBack); | 
| 1430 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 1618 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 
| 1431 DEFINE_GC_INFO(RefCountedAndGarbageCollected2); | 1619 DEFINE_GC_INFO(RefCountedAndGarbageCollected2); | 
| 1432 DEFINE_GC_INFO(SimpleFinalizedObject); | 1620 DEFINE_GC_INFO(SimpleFinalizedObject); | 
| 1433 DEFINE_GC_INFO(SimpleObject); | 1621 DEFINE_GC_INFO(SimpleObject); | 
|  | 1622 DEFINE_GC_INFO(SuperClass); | 
|  | 1623 DEFINE_GC_INFO(SubData); | 
| 1434 DEFINE_GC_INFO(TestTypedHeapClass); | 1624 DEFINE_GC_INFO(TestTypedHeapClass); | 
| 1435 DEFINE_GC_INFO(TraceCounter); | 1625 DEFINE_GC_INFO(TraceCounter); | 
| 1436 | 1626 | 
| 1437 } // namespace | 1627 } // namespace | 
| OLD | NEW | 
|---|