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 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 | 1353 |
1354 Observable& m_target; | 1354 Observable& m_target; |
1355 static Persistent<ObserverMap>* s_observerMap; | 1355 static Persistent<ObserverMap>* s_observerMap; |
1356 }; | 1356 }; |
1357 | 1357 |
1358 bool FinalizationObserverWithHashMap::s_didCallWillFinalize = false; | 1358 bool FinalizationObserverWithHashMap::s_didCallWillFinalize = false; |
1359 Persistent<FinalizationObserverWithHashMap::ObserverMap>* FinalizationObserverWi
thHashMap::s_observerMap; | 1359 Persistent<FinalizationObserverWithHashMap::ObserverMap>* FinalizationObserverWi
thHashMap::s_observerMap; |
1360 | 1360 |
1361 class SuperClass; | 1361 class SuperClass; |
1362 | 1362 |
1363 class PointsBack : public RefCountedWillBeGarbageCollectedFinalized<PointsBack>
{ | 1363 class PointsBack : public GarbageCollectedFinalized<PointsBack> { |
1364 public: | 1364 public: |
1365 static PassRefPtrWillBeRawPtr<PointsBack> create() | 1365 static PointsBack* create() |
1366 { | 1366 { |
1367 return adoptRefWillBeNoop(new PointsBack()); | 1367 return new PointsBack; |
1368 } | 1368 } |
1369 | 1369 |
1370 ~PointsBack() | 1370 ~PointsBack() |
1371 { | 1371 { |
1372 --s_aliveCount; | 1372 --s_aliveCount; |
1373 } | 1373 } |
1374 | 1374 |
1375 void setBackPointer(SuperClass* backPointer) | 1375 void setBackPointer(SuperClass* backPointer) |
1376 { | 1376 { |
1377 m_backPointer = backPointer; | 1377 m_backPointer = backPointer; |
1378 } | 1378 } |
1379 | 1379 |
1380 SuperClass* backPointer() const { return m_backPointer; } | 1380 SuperClass* backPointer() const { return m_backPointer; } |
1381 | 1381 |
1382 DEFINE_INLINE_TRACE() | 1382 DEFINE_INLINE_TRACE() |
1383 { | 1383 { |
1384 visitor->trace(m_backPointer); | 1384 visitor->trace(m_backPointer); |
1385 } | 1385 } |
1386 | 1386 |
1387 static int s_aliveCount; | 1387 static int s_aliveCount; |
1388 private: | 1388 private: |
1389 PointsBack() : m_backPointer(nullptr) | 1389 PointsBack() : m_backPointer(nullptr) |
1390 { | 1390 { |
1391 ++s_aliveCount; | 1391 ++s_aliveCount; |
1392 } | 1392 } |
1393 | 1393 |
1394 RawPtrWillBeWeakMember<SuperClass> m_backPointer; | 1394 WeakMember<SuperClass> m_backPointer; |
1395 }; | 1395 }; |
1396 | 1396 |
1397 int PointsBack::s_aliveCount = 0; | 1397 int PointsBack::s_aliveCount = 0; |
1398 | 1398 |
1399 class SuperClass : public RefCountedWillBeGarbageCollectedFinalized<SuperClass>
{ | 1399 class SuperClass : public GarbageCollectedFinalized<SuperClass> { |
1400 public: | 1400 public: |
1401 static PassRefPtrWillBeRawPtr<SuperClass> create(PassRefPtrWillBeRawPtr<Poin
tsBack> pointsBack) | 1401 static SuperClass* create(PointsBack* pointsBack) |
1402 { | 1402 { |
1403 return adoptRefWillBeNoop(new SuperClass(pointsBack)); | 1403 return new SuperClass(pointsBack); |
1404 } | 1404 } |
1405 | 1405 |
1406 virtual ~SuperClass() | 1406 virtual ~SuperClass() |
1407 { | 1407 { |
1408 #if !ENABLE(OILPAN) | 1408 #if !ENABLE(OILPAN) |
1409 m_pointsBack->setBackPointer(0); | 1409 m_pointsBack->setBackPointer(0); |
1410 #endif | 1410 #endif |
1411 --s_aliveCount; | 1411 --s_aliveCount; |
1412 } | 1412 } |
1413 | 1413 |
1414 void doStuff(PassRefPtrWillBeRawPtr<SuperClass> targetPass, PointsBack* poin
tsBack, int superClassCount) | 1414 void doStuff(SuperClass* target, PointsBack* pointsBack, int superClassCount
) |
1415 { | 1415 { |
1416 RefPtrWillBeRawPtr<SuperClass> target = targetPass; | |
1417 conservativelyCollectGarbage(); | 1416 conservativelyCollectGarbage(); |
1418 EXPECT_EQ(pointsBack, target->getPointsBack()); | 1417 EXPECT_EQ(pointsBack, target->getPointsBack()); |
1419 EXPECT_EQ(superClassCount, SuperClass::s_aliveCount); | 1418 EXPECT_EQ(superClassCount, SuperClass::s_aliveCount); |
1420 } | 1419 } |
1421 | 1420 |
1422 DEFINE_INLINE_VIRTUAL_TRACE() | 1421 DEFINE_INLINE_VIRTUAL_TRACE() |
1423 { | 1422 { |
1424 visitor->trace(m_pointsBack); | 1423 visitor->trace(m_pointsBack); |
1425 } | 1424 } |
1426 | 1425 |
1427 PointsBack* getPointsBack() const { return m_pointsBack.get(); } | 1426 PointsBack* getPointsBack() const { return m_pointsBack.get(); } |
1428 | 1427 |
1429 static int s_aliveCount; | 1428 static int s_aliveCount; |
1430 protected: | 1429 protected: |
1431 explicit SuperClass(PassRefPtrWillBeRawPtr<PointsBack> pointsBack) | 1430 explicit SuperClass(PointsBack* pointsBack) |
1432 : m_pointsBack(pointsBack) | 1431 : m_pointsBack(pointsBack) |
1433 { | 1432 { |
1434 m_pointsBack->setBackPointer(this); | 1433 m_pointsBack->setBackPointer(this); |
1435 ++s_aliveCount; | 1434 ++s_aliveCount; |
1436 } | 1435 } |
1437 | 1436 |
1438 private: | 1437 private: |
1439 RefPtrWillBeMember<PointsBack> m_pointsBack; | 1438 Member<PointsBack> m_pointsBack; |
1440 }; | 1439 }; |
1441 | 1440 |
1442 int SuperClass::s_aliveCount = 0; | 1441 int SuperClass::s_aliveCount = 0; |
1443 class SubData : public NoBaseWillBeGarbageCollectedFinalized<SubData> { | 1442 class SubData : public GarbageCollectedFinalized<SubData> { |
1444 public: | 1443 public: |
1445 SubData() { ++s_aliveCount; } | 1444 SubData() { ++s_aliveCount; } |
1446 ~SubData() { --s_aliveCount; } | 1445 ~SubData() { --s_aliveCount; } |
1447 | 1446 |
1448 DEFINE_INLINE_TRACE() { } | 1447 DEFINE_INLINE_TRACE() { } |
1449 | 1448 |
1450 static int s_aliveCount; | 1449 static int s_aliveCount; |
1451 }; | 1450 }; |
1452 | 1451 |
1453 int SubData::s_aliveCount = 0; | 1452 int SubData::s_aliveCount = 0; |
1454 | 1453 |
1455 class SubClass : public SuperClass { | 1454 class SubClass : public SuperClass { |
1456 public: | 1455 public: |
1457 static PassRefPtrWillBeRawPtr<SubClass> create(PassRefPtrWillBeRawPtr<Points
Back> pointsBack) | 1456 static SubClass* create(PointsBack* pointsBack) |
1458 { | 1457 { |
1459 return adoptRefWillBeNoop(new SubClass(pointsBack)); | 1458 return new SubClass(pointsBack); |
1460 } | 1459 } |
1461 | 1460 |
1462 ~SubClass() override | 1461 ~SubClass() override |
1463 { | 1462 { |
1464 --s_aliveCount; | 1463 --s_aliveCount; |
1465 } | 1464 } |
1466 | 1465 |
1467 DEFINE_INLINE_VIRTUAL_TRACE() | 1466 DEFINE_INLINE_VIRTUAL_TRACE() |
1468 { | 1467 { |
1469 visitor->trace(m_data); | 1468 visitor->trace(m_data); |
1470 SuperClass::trace(visitor); | 1469 SuperClass::trace(visitor); |
1471 } | 1470 } |
1472 | 1471 |
1473 static int s_aliveCount; | 1472 static int s_aliveCount; |
1474 private: | 1473 private: |
1475 explicit SubClass(PassRefPtrWillBeRawPtr<PointsBack> pointsBack) | 1474 explicit SubClass(PointsBack* pointsBack) |
1476 : SuperClass(pointsBack) | 1475 : SuperClass(pointsBack) |
1477 , m_data(adoptPtrWillBeNoop(new SubData())) | 1476 , m_data(new SubData) |
1478 { | 1477 { |
1479 ++s_aliveCount; | 1478 ++s_aliveCount; |
1480 } | 1479 } |
1481 | 1480 |
1482 private: | 1481 private: |
1483 OwnPtrWillBeMember<SubData> m_data; | 1482 Member<SubData> m_data; |
1484 }; | 1483 }; |
1485 | 1484 |
1486 int SubClass::s_aliveCount = 0; | 1485 int SubClass::s_aliveCount = 0; |
1487 | 1486 |
1488 class TransitionRefCounted : public RefCountedWillBeRefCountedGarbageCollected<T
ransitionRefCounted> { | 1487 class TransitionRefCounted : public RefCountedGarbageCollected<TransitionRefCoun
ted> { |
1489 public: | 1488 public: |
1490 static PassRefPtrWillBeRawPtr<TransitionRefCounted> create() | 1489 static TransitionRefCounted* create() |
1491 { | 1490 { |
1492 return adoptRefWillBeNoop(new TransitionRefCounted()); | 1491 return new TransitionRefCounted; |
1493 } | 1492 } |
1494 | 1493 |
1495 ~TransitionRefCounted() | 1494 ~TransitionRefCounted() |
1496 { | 1495 { |
1497 --s_aliveCount; | 1496 --s_aliveCount; |
1498 } | 1497 } |
1499 | 1498 |
1500 DEFINE_INLINE_TRACE() { } | 1499 DEFINE_INLINE_TRACE() { } |
1501 | 1500 |
1502 static int s_aliveCount; | 1501 static int s_aliveCount; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 | 1682 |
1684 DEFINE_INLINE_TRACE() { } | 1683 DEFINE_INLINE_TRACE() { } |
1685 | 1684 |
1686 private: | 1685 private: |
1687 Persistent<IntWrapper>* m_wrapper; | 1686 Persistent<IntWrapper>* m_wrapper; |
1688 }; | 1687 }; |
1689 | 1688 |
1690 TEST(HeapTest, Transition) | 1689 TEST(HeapTest, Transition) |
1691 { | 1690 { |
1692 { | 1691 { |
1693 RefPtrWillBePersistent<TransitionRefCounted> refCounted = TransitionRefC
ounted::create(); | 1692 Persistent<TransitionRefCounted> refCounted = TransitionRefCounted::crea
te(); |
1694 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1693 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); |
1695 preciselyCollectGarbage(); | 1694 preciselyCollectGarbage(); |
1696 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1695 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); |
1697 } | 1696 } |
1698 preciselyCollectGarbage(); | 1697 preciselyCollectGarbage(); |
1699 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); | 1698 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); |
1700 | 1699 |
1701 RefPtrWillBePersistent<PointsBack> pointsBack1 = PointsBack::create(); | 1700 Persistent<PointsBack> pointsBack1 = PointsBack::create(); |
1702 RefPtrWillBePersistent<PointsBack> pointsBack2 = PointsBack::create(); | 1701 Persistent<PointsBack> pointsBack2 = PointsBack::create(); |
1703 RefPtrWillBePersistent<SuperClass> superClass = SuperClass::create(pointsBac
k1); | 1702 Persistent<SuperClass> superClass = SuperClass::create(pointsBack1); |
1704 RefPtrWillBePersistent<SubClass> subClass = SubClass::create(pointsBack2); | 1703 Persistent<SubClass> subClass = SubClass::create(pointsBack2); |
1705 EXPECT_EQ(2, PointsBack::s_aliveCount); | 1704 EXPECT_EQ(2, PointsBack::s_aliveCount); |
1706 EXPECT_EQ(2, SuperClass::s_aliveCount); | 1705 EXPECT_EQ(2, SuperClass::s_aliveCount); |
1707 EXPECT_EQ(1, SubClass::s_aliveCount); | 1706 EXPECT_EQ(1, SubClass::s_aliveCount); |
1708 EXPECT_EQ(1, SubData::s_aliveCount); | 1707 EXPECT_EQ(1, SubData::s_aliveCount); |
1709 | 1708 |
1710 preciselyCollectGarbage(); | 1709 preciselyCollectGarbage(); |
1711 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); | 1710 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); |
1712 EXPECT_EQ(2, PointsBack::s_aliveCount); | 1711 EXPECT_EQ(2, PointsBack::s_aliveCount); |
1713 EXPECT_EQ(2, SuperClass::s_aliveCount); | 1712 EXPECT_EQ(2, SuperClass::s_aliveCount); |
1714 EXPECT_EQ(1, SubClass::s_aliveCount); | 1713 EXPECT_EQ(1, SubClass::s_aliveCount); |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 | 2426 |
2428 struct NeedsTracingTrait { | 2427 struct NeedsTracingTrait { |
2429 explicit NeedsTracingTrait(IntWrapper* wrapper) : m_wrapper(wrapper) { } | 2428 explicit NeedsTracingTrait(IntWrapper* wrapper) : m_wrapper(wrapper) { } |
2430 DEFINE_INLINE_TRACE() { visitor->trace(m_wrapper); } | 2429 DEFINE_INLINE_TRACE() { visitor->trace(m_wrapper); } |
2431 Member<IntWrapper> m_wrapper; | 2430 Member<IntWrapper> m_wrapper; |
2432 }; | 2431 }; |
2433 | 2432 |
2434 // These class definitions test compile-time asserts with transition | 2433 // These class definitions test compile-time asserts with transition |
2435 // types. They are therefore unused in test code and just need to | 2434 // types. They are therefore unused in test code and just need to |
2436 // compile. This is intentional; do not delete the A and B classes below. | 2435 // compile. This is intentional; do not delete the A and B classes below. |
2437 class A : public WillBeGarbageCollectedMixin { | 2436 class A : public GarbageCollectedMixin { |
2438 }; | 2437 }; |
2439 | 2438 |
2440 class B : public NoBaseWillBeGarbageCollected<B>, public A { | 2439 class B : public GarbageCollected<B>, public A { |
2441 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(B); | 2440 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(B); |
2442 public: | 2441 public: |
2443 DEFINE_INLINE_TRACE() { } | 2442 DEFINE_INLINE_TRACE() { } |
2444 }; | 2443 }; |
2445 | 2444 |
2446 TEST(HeapTest, HeapVectorFilledWithValue) | 2445 TEST(HeapTest, HeapVectorFilledWithValue) |
2447 { | 2446 { |
2448 IntWrapper* val = IntWrapper::create(1); | 2447 IntWrapper* val = IntWrapper::create(1); |
2449 HeapVector<Member<IntWrapper>> vector(10, val); | 2448 HeapVector<Member<IntWrapper>> vector(10, val); |
2450 EXPECT_EQ(10u, vector.size()); | 2449 EXPECT_EQ(10u, vector.size()); |
(...skipping 4051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6502 EXPECT_EQ(1u, vector2.size()); | 6501 EXPECT_EQ(1u, vector2.size()); |
6503 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables | 6502 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables |
6504 // Vector<>s with inline capacity, remove. | 6503 // Vector<>s with inline capacity, remove. |
6505 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) | 6504 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
6506 EXPECT_EQ(16u, vector1.capacity()); | 6505 EXPECT_EQ(16u, vector1.capacity()); |
6507 EXPECT_EQ(16u, vector2.capacity()); | 6506 EXPECT_EQ(16u, vector2.capacity()); |
6508 #endif | 6507 #endif |
6509 } | 6508 } |
6510 | 6509 |
6511 } // namespace blink | 6510 } // namespace blink |
OLD | NEW |