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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 LargeHeapObject() | 971 LargeHeapObject() |
972 { | 972 { |
973 m_intWrapper = IntWrapper::create(23); | 973 m_intWrapper = IntWrapper::create(23); |
974 } | 974 } |
975 Member<IntWrapper> m_intWrapper; | 975 Member<IntWrapper> m_intWrapper; |
976 char m_data[s_length]; | 976 char m_data[s_length]; |
977 }; | 977 }; |
978 | 978 |
979 int LargeHeapObject::s_destructorCalls = 0; | 979 int LargeHeapObject::s_destructorCalls = 0; |
980 | 980 |
981 class RefCountedAndGarbageCollected : public RefCountedGarbageCollected<RefCount
edAndGarbageCollected> { | 981 // This test class served a more important role while Blink |
| 982 // was transitioned over to using Oilpan. That required classes |
| 983 // that were hybrid, both ref-counted and on the Oilpan heap |
| 984 // (the RefCountedGarbageCollected<> class providing just that.) |
| 985 // |
| 986 // There's no current need for having a ref-counted veneer on |
| 987 // top of a GCed class, but we preserve it here to exercise the |
| 988 // implementation technique that it used -- keeping an internal |
| 989 // "keep alive" persistent reference that is set & cleared across |
| 990 // ref-counting operations. |
| 991 // |
| 992 class RefCountedAndGarbageCollected : public GarbageCollectedFinalized<RefCounte
dAndGarbageCollected> { |
982 public: | 993 public: |
983 static RefCountedAndGarbageCollected* create() | 994 static RefCountedAndGarbageCollected* create() |
984 { | 995 { |
985 return new RefCountedAndGarbageCollected(); | 996 return new RefCountedAndGarbageCollected; |
986 } | 997 } |
987 | 998 |
988 ~RefCountedAndGarbageCollected() | 999 ~RefCountedAndGarbageCollected() |
989 { | 1000 { |
990 ++s_destructorCalls; | 1001 ++s_destructorCalls; |
991 } | 1002 } |
992 | 1003 |
993 // These are here with their default implementations so you can break in | 1004 void ref() |
994 // them in the debugger. | 1005 { |
995 void ref() { RefCountedGarbageCollected<RefCountedAndGarbageCollected>::ref(
); } | 1006 if (UNLIKELY(!m_refCount)) { |
996 void deref() { RefCountedGarbageCollected<RefCountedAndGarbageCollected>::de
ref(); } | 1007 ASSERT(ThreadState::current()->findPageFromAddress(reinterpret_cast<
Address>(this))); |
| 1008 m_keepAlive = this; |
| 1009 } |
| 1010 ++m_refCount; |
| 1011 } |
| 1012 |
| 1013 void deref() |
| 1014 { |
| 1015 ASSERT(m_refCount > 0); |
| 1016 if (!--m_refCount) |
| 1017 m_keepAlive.clear(); |
| 1018 } |
997 | 1019 |
998 DEFINE_INLINE_TRACE() { } | 1020 DEFINE_INLINE_TRACE() { } |
999 | 1021 |
1000 static int s_destructorCalls; | 1022 static int s_destructorCalls; |
1001 | 1023 |
1002 private: | 1024 private: |
1003 RefCountedAndGarbageCollected() | 1025 RefCountedAndGarbageCollected() |
| 1026 : m_refCount(0) |
1004 { | 1027 { |
1005 } | 1028 } |
| 1029 |
| 1030 int m_refCount; |
| 1031 SelfKeepAlive<RefCountedAndGarbageCollected> m_keepAlive; |
1006 }; | 1032 }; |
1007 | 1033 |
1008 int RefCountedAndGarbageCollected::s_destructorCalls = 0; | 1034 int RefCountedAndGarbageCollected::s_destructorCalls = 0; |
1009 | 1035 |
1010 class RefCountedAndGarbageCollected2 : public HeapTestOtherSuperClass, public Re
fCountedGarbageCollected<RefCountedAndGarbageCollected2> { | 1036 class RefCountedAndGarbageCollected2 : public HeapTestOtherSuperClass, public Ga
rbageCollectedFinalized<RefCountedAndGarbageCollected2> { |
1011 public: | 1037 public: |
1012 static RefCountedAndGarbageCollected2* create() | 1038 static RefCountedAndGarbageCollected2* create() |
1013 { | 1039 { |
1014 return new RefCountedAndGarbageCollected2(); | 1040 return new RefCountedAndGarbageCollected2; |
1015 } | 1041 } |
1016 | 1042 |
1017 ~RefCountedAndGarbageCollected2() | 1043 ~RefCountedAndGarbageCollected2() |
1018 { | 1044 { |
1019 ++s_destructorCalls; | 1045 ++s_destructorCalls; |
1020 } | 1046 } |
1021 | 1047 |
| 1048 void ref() |
| 1049 { |
| 1050 if (UNLIKELY(!m_refCount)) { |
| 1051 ASSERT(ThreadState::current()->findPageFromAddress(reinterpret_cast<
Address>(this))); |
| 1052 m_keepAlive = this; |
| 1053 } |
| 1054 ++m_refCount; |
| 1055 } |
| 1056 |
| 1057 void deref() |
| 1058 { |
| 1059 ASSERT(m_refCount > 0); |
| 1060 if (!--m_refCount) |
| 1061 m_keepAlive.clear(); |
| 1062 } |
| 1063 |
1022 DEFINE_INLINE_TRACE() { } | 1064 DEFINE_INLINE_TRACE() { } |
1023 | 1065 |
1024 static int s_destructorCalls; | 1066 static int s_destructorCalls; |
1025 | 1067 |
1026 private: | 1068 private: |
1027 RefCountedAndGarbageCollected2() | 1069 RefCountedAndGarbageCollected2() |
| 1070 : m_refCount(0) |
1028 { | 1071 { |
1029 } | 1072 } |
| 1073 |
| 1074 int m_refCount; |
| 1075 SelfKeepAlive<RefCountedAndGarbageCollected2> m_keepAlive; |
1030 }; | 1076 }; |
1031 | 1077 |
1032 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; | 1078 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; |
1033 | 1079 |
1034 #define DEFINE_VISITOR_METHODS(Type) \ | 1080 #define DEFINE_VISITOR_METHODS(Type) \ |
1035 void mark(const Type* object, TraceCallback callback) override \ | 1081 void mark(const Type* object, TraceCallback callback) override \ |
1036 { \ | 1082 { \ |
1037 mark(object); \ | 1083 mark(object); \ |
1038 } \ | 1084 } \ |
1039 | 1085 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 { | 1525 { |
1480 ++s_aliveCount; | 1526 ++s_aliveCount; |
1481 } | 1527 } |
1482 | 1528 |
1483 private: | 1529 private: |
1484 Member<SubData> m_data; | 1530 Member<SubData> m_data; |
1485 }; | 1531 }; |
1486 | 1532 |
1487 int SubClass::s_aliveCount = 0; | 1533 int SubClass::s_aliveCount = 0; |
1488 | 1534 |
1489 class TransitionRefCounted : public RefCountedGarbageCollected<TransitionRefCoun
ted> { | |
1490 public: | |
1491 static TransitionRefCounted* create() | |
1492 { | |
1493 return new TransitionRefCounted; | |
1494 } | |
1495 | |
1496 ~TransitionRefCounted() | |
1497 { | |
1498 --s_aliveCount; | |
1499 } | |
1500 | |
1501 DEFINE_INLINE_TRACE() { } | |
1502 | |
1503 static int s_aliveCount; | |
1504 | |
1505 private: | |
1506 TransitionRefCounted() | |
1507 { | |
1508 ++s_aliveCount; | |
1509 } | |
1510 }; | |
1511 | |
1512 int TransitionRefCounted::s_aliveCount = 0; | |
1513 | |
1514 class Mixin : public GarbageCollectedMixin { | 1535 class Mixin : public GarbageCollectedMixin { |
1515 public: | 1536 public: |
1516 DEFINE_INLINE_VIRTUAL_TRACE() { } | 1537 DEFINE_INLINE_VIRTUAL_TRACE() { } |
1517 | 1538 |
1518 virtual char getPayload(int i) { return m_padding[i]; } | 1539 virtual char getPayload(int i) { return m_padding[i]; } |
1519 | 1540 |
1520 protected: | 1541 protected: |
1521 int m_padding[8]; | 1542 int m_padding[8]; |
1522 }; | 1543 }; |
1523 | 1544 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 | 1707 |
1687 DEFINE_INLINE_TRACE() { } | 1708 DEFINE_INLINE_TRACE() { } |
1688 | 1709 |
1689 private: | 1710 private: |
1690 Persistent<IntWrapper>* m_wrapper; | 1711 Persistent<IntWrapper>* m_wrapper; |
1691 }; | 1712 }; |
1692 | 1713 |
1693 TEST(HeapTest, Transition) | 1714 TEST(HeapTest, Transition) |
1694 { | 1715 { |
1695 { | 1716 { |
1696 Persistent<TransitionRefCounted> refCounted = TransitionRefCounted::crea
te(); | 1717 RefCountedAndGarbageCollected::s_destructorCalls = 0; |
1697 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1718 Persistent<RefCountedAndGarbageCollected> refCounted = RefCountedAndGarb
ageCollected::create(); |
1698 preciselyCollectGarbage(); | 1719 preciselyCollectGarbage(); |
1699 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1720 EXPECT_EQ(0, RefCountedAndGarbageCollected::s_destructorCalls); |
1700 } | 1721 } |
1701 preciselyCollectGarbage(); | 1722 preciselyCollectGarbage(); |
1702 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); | 1723 EXPECT_EQ(1, RefCountedAndGarbageCollected::s_destructorCalls); |
| 1724 RefCountedAndGarbageCollected::s_destructorCalls = 0; |
1703 | 1725 |
1704 Persistent<PointsBack> pointsBack1 = PointsBack::create(); | 1726 Persistent<PointsBack> pointsBack1 = PointsBack::create(); |
1705 Persistent<PointsBack> pointsBack2 = PointsBack::create(); | 1727 Persistent<PointsBack> pointsBack2 = PointsBack::create(); |
1706 Persistent<SuperClass> superClass = SuperClass::create(pointsBack1); | 1728 Persistent<SuperClass> superClass = SuperClass::create(pointsBack1); |
1707 Persistent<SubClass> subClass = SubClass::create(pointsBack2); | 1729 Persistent<SubClass> subClass = SubClass::create(pointsBack2); |
1708 EXPECT_EQ(2, PointsBack::s_aliveCount); | 1730 EXPECT_EQ(2, PointsBack::s_aliveCount); |
1709 EXPECT_EQ(2, SuperClass::s_aliveCount); | 1731 EXPECT_EQ(2, SuperClass::s_aliveCount); |
1710 EXPECT_EQ(1, SubClass::s_aliveCount); | 1732 EXPECT_EQ(1, SubClass::s_aliveCount); |
1711 EXPECT_EQ(1, SubData::s_aliveCount); | 1733 EXPECT_EQ(1, SubData::s_aliveCount); |
1712 | 1734 |
1713 preciselyCollectGarbage(); | 1735 preciselyCollectGarbage(); |
1714 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); | 1736 EXPECT_EQ(0, RefCountedAndGarbageCollected::s_destructorCalls); |
1715 EXPECT_EQ(2, PointsBack::s_aliveCount); | 1737 EXPECT_EQ(2, PointsBack::s_aliveCount); |
1716 EXPECT_EQ(2, SuperClass::s_aliveCount); | 1738 EXPECT_EQ(2, SuperClass::s_aliveCount); |
1717 EXPECT_EQ(1, SubClass::s_aliveCount); | 1739 EXPECT_EQ(1, SubClass::s_aliveCount); |
1718 EXPECT_EQ(1, SubData::s_aliveCount); | 1740 EXPECT_EQ(1, SubData::s_aliveCount); |
1719 | 1741 |
1720 superClass->doStuff(superClass.release(), pointsBack1.get(), 2); | 1742 superClass->doStuff(superClass.release(), pointsBack1.get(), 2); |
1721 preciselyCollectGarbage(); | 1743 preciselyCollectGarbage(); |
1722 EXPECT_EQ(2, PointsBack::s_aliveCount); | 1744 EXPECT_EQ(2, PointsBack::s_aliveCount); |
1723 EXPECT_EQ(1, SuperClass::s_aliveCount); | 1745 EXPECT_EQ(1, SuperClass::s_aliveCount); |
1724 EXPECT_EQ(1, SubClass::s_aliveCount); | 1746 EXPECT_EQ(1, SubClass::s_aliveCount); |
(...skipping 4804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6529 }; | 6551 }; |
6530 | 6552 |
6531 } // namespace | 6553 } // namespace |
6532 | 6554 |
6533 TEST(HeapTest, TestClearOnShutdown) | 6555 TEST(HeapTest, TestClearOnShutdown) |
6534 { | 6556 { |
6535 ThreadedClearOnShutdownTester::test(); | 6557 ThreadedClearOnShutdownTester::test(); |
6536 } | 6558 } |
6537 | 6559 |
6538 } // namespace blink | 6560 } // namespace blink |
OLD | NEW |