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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ThreadState::resumeThreads(); | 215 ThreadState::resumeThreads(); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 private: | 219 private: |
220 ThreadState* m_state; | 220 ThreadState* m_state; |
221 ThreadState::SafePointScope m_safePointScope; | 221 ThreadState::SafePointScope m_safePointScope; |
222 bool m_parkedAllThreads; // False if we fail to park all threads | 222 bool m_parkedAllThreads; // False if we fail to park all threads |
223 }; | 223 }; |
224 | 224 |
225 static void getHeapStats(HeapStats* stats) | 225 static size_t objectPayloadSize() |
226 { | 226 { |
227 TestGCScope scope(ThreadState::NoHeapPointersOnStack); | 227 TestGCScope scope(ThreadState::NoHeapPointersOnStack); |
228 EXPECT_TRUE(scope.allThreadsParked()); | 228 EXPECT_TRUE(scope.allThreadsParked()); |
229 Heap::getStatsForTesting(stats); | 229 return Heap::objectPayloadSizeForTesting(); |
230 } | 230 } |
231 | 231 |
232 #define DEFINE_VISITOR_METHODS(Type) \ | 232 #define DEFINE_VISITOR_METHODS(Type) \ |
233 virtual void mark(const Type* object, TraceCallback callback) override \ | 233 virtual void mark(const Type* object, TraceCallback callback) override \ |
234 { \ | 234 { \ |
235 if (object) \ | 235 if (object) \ |
236 m_count++; \ | 236 m_count++; \ |
237 } \ | 237 } \ |
238 virtual bool isMarked(const Type*) override { return false; } | 238 virtual bool isMarked(const Type*) override { return false; } |
239 | 239 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 362 |
363 int8_t at(size_t i) { return m_array[i]; } | 363 int8_t at(size_t i) { return m_array[i]; } |
364 void trace(Visitor*) { } | 364 void trace(Visitor*) { } |
365 private: | 365 private: |
366 static const int s_arraySize = 1000; | 366 static const int s_arraySize = 1000; |
367 int8_t m_array[s_arraySize]; | 367 int8_t m_array[s_arraySize]; |
368 }; | 368 }; |
369 | 369 |
370 // Do several GCs to make sure that later GCs don't free up old memory from | 370 // Do several GCs to make sure that later GCs don't free up old memory from |
371 // previously run tests in this process. | 371 // previously run tests in this process. |
372 static void clearOutOldGarbage(HeapStats* heapStats) | 372 static void clearOutOldGarbage() |
373 { | 373 { |
374 while (true) { | 374 while (true) { |
375 getHeapStats(heapStats); | 375 size_t used = objectPayloadSize(); |
376 size_t used = heapStats->totalObjectSpace(); | |
377 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 376 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
378 getHeapStats(heapStats); | 377 if (objectPayloadSize() >= used) |
379 if (heapStats->totalObjectSpace() >= used) | |
380 break; | 378 break; |
381 } | 379 } |
382 } | 380 } |
383 | 381 |
384 class OffHeapInt : public RefCounted<OffHeapInt> { | 382 class OffHeapInt : public RefCounted<OffHeapInt> { |
385 public: | 383 public: |
386 static RefPtr<OffHeapInt> create(int x) | 384 static RefPtr<OffHeapInt> create(int x) |
387 { | 385 { |
388 return adoptRef(new OffHeapInt(x)); | 386 return adoptRef(new OffHeapInt(x)); |
389 } | 387 } |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 ThreadedHeapTester::test(); | 1506 ThreadedHeapTester::test(); |
1509 } | 1507 } |
1510 | 1508 |
1511 TEST(HeapTest, ThreadedWeakness) | 1509 TEST(HeapTest, ThreadedWeakness) |
1512 { | 1510 { |
1513 ThreadedWeaknessTester::test(); | 1511 ThreadedWeaknessTester::test(); |
1514 } | 1512 } |
1515 | 1513 |
1516 TEST(HeapTest, BasicFunctionality) | 1514 TEST(HeapTest, BasicFunctionality) |
1517 { | 1515 { |
1518 HeapStats heapStats; | 1516 clearOutOldGarbage(); |
1519 clearOutOldGarbage(&heapStats); | 1517 size_t initialObjectPayloadSize = objectPayloadSize(); |
1520 { | 1518 { |
1521 size_t slack = 0; | 1519 size_t slack = 0; |
1522 | 1520 |
1523 // When the test starts there may already have been leaked some memory | 1521 // When the test starts there may already have been leaked some memory |
1524 // on the heap, so we establish a base line. | 1522 // on the heap, so we establish a base line. |
1525 size_t baseLevel = heapStats.totalObjectSpace(); | 1523 size_t baseLevel = initialObjectPayloadSize; |
1526 bool testPagesAllocated = !baseLevel; | 1524 bool testPagesAllocated = !baseLevel; |
1527 if (testPagesAllocated) | 1525 if (testPagesAllocated) |
1528 EXPECT_EQ(heapStats.totalAllocatedSpace(), 0ul); | 1526 EXPECT_EQ(Heap::allocatedSpace(), 0ul); |
1529 | 1527 |
1530 // This allocates objects on the general heap which should add a page of
memory. | 1528 // This allocates objects on the general heap which should add a page of
memory. |
1531 DynamicallySizedObject* alloc32 = DynamicallySizedObject::create(32); | 1529 DynamicallySizedObject* alloc32 = DynamicallySizedObject::create(32); |
1532 slack += 4; | 1530 slack += 4; |
1533 memset(alloc32, 40, 32); | 1531 memset(alloc32, 40, 32); |
1534 DynamicallySizedObject* alloc64 = DynamicallySizedObject::create(64); | 1532 DynamicallySizedObject* alloc64 = DynamicallySizedObject::create(64); |
1535 slack += 4; | 1533 slack += 4; |
1536 memset(alloc64, 27, 64); | 1534 memset(alloc64, 27, 64); |
1537 | 1535 |
1538 size_t total = 96; | 1536 size_t total = 96; |
1539 | 1537 |
1540 getHeapStats(&heapStats); | 1538 CheckWithSlack(baseLevel + total, objectPayloadSize(), slack); |
1541 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); | |
1542 if (testPagesAllocated) | 1539 if (testPagesAllocated) |
1543 EXPECT_EQ(heapStats.totalAllocatedSpace(), 2 * blinkPageSize); | 1540 EXPECT_EQ(Heap::allocatedSpace(), 2 * blinkPageSize); |
1544 | 1541 |
1545 EXPECT_EQ(alloc32->get(0), 40); | 1542 EXPECT_EQ(alloc32->get(0), 40); |
1546 EXPECT_EQ(alloc32->get(31), 40); | 1543 EXPECT_EQ(alloc32->get(31), 40); |
1547 EXPECT_EQ(alloc64->get(0), 27); | 1544 EXPECT_EQ(alloc64->get(0), 27); |
1548 EXPECT_EQ(alloc64->get(63), 27); | 1545 EXPECT_EQ(alloc64->get(63), 27); |
1549 | 1546 |
1550 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 1547 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
1551 | 1548 |
1552 EXPECT_EQ(alloc32->get(0), 40); | 1549 EXPECT_EQ(alloc32->get(0), 40); |
1553 EXPECT_EQ(alloc32->get(31), 40); | 1550 EXPECT_EQ(alloc32->get(31), 40); |
1554 EXPECT_EQ(alloc64->get(0), 27); | 1551 EXPECT_EQ(alloc64->get(0), 27); |
1555 EXPECT_EQ(alloc64->get(63), 27); | 1552 EXPECT_EQ(alloc64->get(63), 27); |
1556 } | 1553 } |
1557 | 1554 |
1558 clearOutOldGarbage(&heapStats); | 1555 clearOutOldGarbage(); |
1559 size_t total = 0; | 1556 size_t total = 0; |
1560 size_t slack = 0; | 1557 size_t slack = 0; |
1561 size_t baseLevel = heapStats.totalObjectSpace(); | 1558 size_t baseLevel = objectPayloadSize(); |
1562 bool testPagesAllocated = !baseLevel; | 1559 bool testPagesAllocated = !baseLevel; |
1563 if (testPagesAllocated) | 1560 if (testPagesAllocated) |
1564 EXPECT_EQ(heapStats.totalAllocatedSpace(), 0ul); | 1561 EXPECT_EQ(Heap::allocatedSpace(), 0ul); |
1565 | 1562 |
1566 size_t big = 1008; | 1563 size_t big = 1008; |
1567 Persistent<DynamicallySizedObject> bigArea = DynamicallySizedObject::create(
big); | 1564 Persistent<DynamicallySizedObject> bigArea = DynamicallySizedObject::create(
big); |
1568 total += big; | 1565 total += big; |
1569 slack += 4; | 1566 slack += 4; |
1570 | 1567 |
1571 size_t persistentCount = 0; | 1568 size_t persistentCount = 0; |
1572 const size_t numPersistents = 100000; | 1569 const size_t numPersistents = 100000; |
1573 Persistent<DynamicallySizedObject>* persistents[numPersistents]; | 1570 Persistent<DynamicallySizedObject>* persistents[numPersistents]; |
1574 | 1571 |
1575 for (int i = 0; i < 1000; i++) { | 1572 for (int i = 0; i < 1000; i++) { |
1576 size_t size = 128 + i * 8; | 1573 size_t size = 128 + i * 8; |
1577 total += size; | 1574 total += size; |
1578 persistents[persistentCount++] = new Persistent<DynamicallySizedObject>(
DynamicallySizedObject::create(size)); | 1575 persistents[persistentCount++] = new Persistent<DynamicallySizedObject>(
DynamicallySizedObject::create(size)); |
1579 slack += 4; | 1576 slack += 4; |
1580 getHeapStats(&heapStats); | 1577 CheckWithSlack(baseLevel + total, objectPayloadSize(), slack); |
1581 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); | |
1582 if (testPagesAllocated) | 1578 if (testPagesAllocated) |
1583 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)
); | 1579 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); |
1584 } | 1580 } |
1585 | 1581 |
1586 { | 1582 { |
1587 DynamicallySizedObject* alloc32b(DynamicallySizedObject::create(32)); | 1583 DynamicallySizedObject* alloc32b(DynamicallySizedObject::create(32)); |
1588 slack += 4; | 1584 slack += 4; |
1589 memset(alloc32b, 40, 32); | 1585 memset(alloc32b, 40, 32); |
1590 DynamicallySizedObject* alloc64b(DynamicallySizedObject::create(64)); | 1586 DynamicallySizedObject* alloc64b(DynamicallySizedObject::create(64)); |
1591 slack += 4; | 1587 slack += 4; |
1592 memset(alloc64b, 27, 64); | 1588 memset(alloc64b, 27, 64); |
1593 EXPECT_TRUE(alloc32b != alloc64b); | 1589 EXPECT_TRUE(alloc32b != alloc64b); |
1594 | 1590 |
1595 total += 96; | 1591 total += 96; |
1596 getHeapStats(&heapStats); | 1592 CheckWithSlack(baseLevel + total, objectPayloadSize(), slack); |
1597 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); | |
1598 if (testPagesAllocated) | 1593 if (testPagesAllocated) |
1599 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)
); | 1594 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); |
1600 } | 1595 } |
1601 | 1596 |
1602 clearOutOldGarbage(&heapStats); | 1597 clearOutOldGarbage(); |
1603 total -= 96; | 1598 total -= 96; |
1604 slack -= 8; | 1599 slack -= 8; |
1605 if (testPagesAllocated) | 1600 if (testPagesAllocated) |
1606 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); | 1601 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); |
1607 | 1602 |
1608 // Clear the persistent, so that the big area will be garbage collected. | 1603 // Clear the persistent, so that the big area will be garbage collected. |
1609 bigArea.release(); | 1604 bigArea.release(); |
1610 clearOutOldGarbage(&heapStats); | 1605 clearOutOldGarbage(); |
1611 | 1606 |
1612 total -= big; | 1607 total -= big; |
1613 slack -= 4; | 1608 slack -= 4; |
1614 getHeapStats(&heapStats); | 1609 CheckWithSlack(baseLevel + total, objectPayloadSize(), slack); |
1615 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); | |
1616 if (testPagesAllocated) | 1610 if (testPagesAllocated) |
1617 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); | 1611 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); |
1618 | 1612 |
1619 getHeapStats(&heapStats); | 1613 CheckWithSlack(baseLevel + total, objectPayloadSize(), slack); |
1620 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); | |
1621 if (testPagesAllocated) | 1614 if (testPagesAllocated) |
1622 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); | 1615 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); |
1623 | 1616 |
1624 for (size_t i = 0; i < persistentCount; i++) { | 1617 for (size_t i = 0; i < persistentCount; i++) { |
1625 delete persistents[i]; | 1618 delete persistents[i]; |
1626 persistents[i] = 0; | 1619 persistents[i] = 0; |
1627 } | 1620 } |
1628 | 1621 |
1629 uint8_t* address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySi
zedObject>(0, 100)); | 1622 uint8_t* address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySi
zedObject>(0, 100)); |
1630 for (int i = 0; i < 100; i++) | 1623 for (int i = 0; i < 100; i++) |
1631 address[i] = i; | 1624 address[i] = i; |
1632 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 100000)); | 1625 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 100000)); |
1633 for (int i = 0; i < 100; i++) | 1626 for (int i = 0; i < 100; i++) |
1634 EXPECT_EQ(address[i], i); | 1627 EXPECT_EQ(address[i], i); |
1635 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 50)); | 1628 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 50)); |
1636 for (int i = 0; i < 50; i++) | 1629 for (int i = 0; i < 50; i++) |
1637 EXPECT_EQ(address[i], i); | 1630 EXPECT_EQ(address[i], i); |
1638 // This should be equivalent to free(address). | 1631 // This should be equivalent to free(address). |
1639 EXPECT_EQ(reinterpret_cast<uintptr_t>(Heap::reallocate<DynamicallySizedObjec
t>(address, 0)), 0ul); | 1632 EXPECT_EQ(reinterpret_cast<uintptr_t>(Heap::reallocate<DynamicallySizedObjec
t>(address, 0)), 0ul); |
1640 // This should be equivalent to malloc(0). | 1633 // This should be equivalent to malloc(0). |
1641 EXPECT_EQ(reinterpret_cast<uintptr_t>(Heap::reallocate<DynamicallySizedObjec
t>(0, 0)), 0ul); | 1634 EXPECT_EQ(reinterpret_cast<uintptr_t>(Heap::reallocate<DynamicallySizedObjec
t>(0, 0)), 0ul); |
1642 } | 1635 } |
1643 | 1636 |
1644 TEST(HeapTest, SimpleAllocation) | 1637 TEST(HeapTest, SimpleAllocation) |
1645 { | 1638 { |
1646 HeapStats initialHeapStats; | 1639 clearOutOldGarbage(); |
1647 clearOutOldGarbage(&initialHeapStats); | 1640 EXPECT_EQ(0ul, objectPayloadSize()); |
1648 EXPECT_EQ(0ul, initialHeapStats.totalObjectSpace()); | |
1649 | 1641 |
1650 // Allocate an object in the heap. | 1642 // Allocate an object in the heap. |
1651 HeapAllocatedArray* array = new HeapAllocatedArray(); | 1643 HeapAllocatedArray* array = new HeapAllocatedArray(); |
1652 HeapStats statsAfterAllocation; | 1644 EXPECT_TRUE(objectPayloadSize() >= sizeof(HeapAllocatedArray)); |
1653 getHeapStats(&statsAfterAllocation); | |
1654 EXPECT_TRUE(statsAfterAllocation.totalObjectSpace() >= sizeof(HeapAllocatedA
rray)); | |
1655 | 1645 |
1656 // Sanity check of the contents in the heap. | 1646 // Sanity check of the contents in the heap. |
1657 EXPECT_EQ(0, array->at(0)); | 1647 EXPECT_EQ(0, array->at(0)); |
1658 EXPECT_EQ(42, array->at(42)); | 1648 EXPECT_EQ(42, array->at(42)); |
1659 EXPECT_EQ(0, array->at(128)); | 1649 EXPECT_EQ(0, array->at(128)); |
1660 EXPECT_EQ(999 % 128, array->at(999)); | 1650 EXPECT_EQ(999 % 128, array->at(999)); |
1661 } | 1651 } |
1662 | 1652 |
1663 TEST(HeapTest, SimplePersistent) | 1653 TEST(HeapTest, SimplePersistent) |
1664 { | 1654 { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 // for the conservative stack scan to find. | 1805 // for the conservative stack scan to find. |
1816 EXPECT_EQ(width, bars->getWidth()); | 1806 EXPECT_EQ(width, bars->getWidth()); |
1817 } | 1807 } |
1818 EXPECT_EQ(Bars::width + 1, Bar::s_live); | 1808 EXPECT_EQ(Bars::width + 1, Bar::s_live); |
1819 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1809 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1820 EXPECT_EQ(0u, Bar::s_live); | 1810 EXPECT_EQ(0u, Bar::s_live); |
1821 } | 1811 } |
1822 | 1812 |
1823 TEST(HeapTest, HashMapOfMembers) | 1813 TEST(HeapTest, HashMapOfMembers) |
1824 { | 1814 { |
1825 HeapStats initialHeapSize; | |
1826 IntWrapper::s_destructorCalls = 0; | 1815 IntWrapper::s_destructorCalls = 0; |
1827 | 1816 |
1828 clearOutOldGarbage(&initialHeapSize); | 1817 clearOutOldGarbage(); |
| 1818 size_t initialObjectPayloadSize = objectPayloadSize(); |
1829 { | 1819 { |
1830 typedef HeapHashMap< | 1820 typedef HeapHashMap< |
1831 Member<IntWrapper>, | 1821 Member<IntWrapper>, |
1832 Member<IntWrapper>, | 1822 Member<IntWrapper>, |
1833 DefaultHash<Member<IntWrapper> >::Hash, | 1823 DefaultHash<Member<IntWrapper> >::Hash, |
1834 HashTraits<Member<IntWrapper> >, | 1824 HashTraits<Member<IntWrapper> >, |
1835 HashTraits<Member<IntWrapper> > > HeapObjectIdentityMap; | 1825 HashTraits<Member<IntWrapper> > > HeapObjectIdentityMap; |
1836 | 1826 |
1837 Persistent<HeapObjectIdentityMap> map = new HeapObjectIdentityMap(); | 1827 Persistent<HeapObjectIdentityMap> map = new HeapObjectIdentityMap(); |
1838 | 1828 |
1839 map->clear(); | 1829 map->clear(); |
1840 HeapStats afterSetWasCreated; | 1830 size_t afterSetWasCreated = objectPayloadSize(); |
1841 getHeapStats(&afterSetWasCreated); | 1831 EXPECT_TRUE(afterSetWasCreated > initialObjectPayloadSize); |
1842 EXPECT_TRUE(afterSetWasCreated.totalObjectSpace() > initialHeapSize.tota
lObjectSpace()); | |
1843 | 1832 |
1844 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1833 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1845 HeapStats afterGC; | 1834 size_t afterGC = objectPayloadSize(); |
1846 getHeapStats(&afterGC); | 1835 EXPECT_EQ(afterGC, afterSetWasCreated); |
1847 EXPECT_EQ(afterGC.totalObjectSpace(), afterSetWasCreated.totalObjectSpac
e()); | |
1848 | 1836 |
1849 // If the additions below cause garbage collections, these | 1837 // If the additions below cause garbage collections, these |
1850 // pointers should be found by conservative stack scanning. | 1838 // pointers should be found by conservative stack scanning. |
1851 IntWrapper* one(IntWrapper::create(1)); | 1839 IntWrapper* one(IntWrapper::create(1)); |
1852 IntWrapper* anotherOne(IntWrapper::create(1)); | 1840 IntWrapper* anotherOne(IntWrapper::create(1)); |
1853 | 1841 |
1854 map->add(one, one); | 1842 map->add(one, one); |
1855 | 1843 |
1856 HeapStats afterOneAdd; | 1844 size_t afterOneAdd = objectPayloadSize(); |
1857 getHeapStats(&afterOneAdd); | 1845 EXPECT_TRUE(afterOneAdd > afterGC); |
1858 EXPECT_TRUE(afterOneAdd.totalObjectSpace() > afterGC.totalObjectSpace())
; | |
1859 | 1846 |
1860 HeapObjectIdentityMap::iterator it(map->begin()); | 1847 HeapObjectIdentityMap::iterator it(map->begin()); |
1861 HeapObjectIdentityMap::iterator it2(map->begin()); | 1848 HeapObjectIdentityMap::iterator it2(map->begin()); |
1862 ++it; | 1849 ++it; |
1863 ++it2; | 1850 ++it2; |
1864 | 1851 |
1865 map->add(anotherOne, one); | 1852 map->add(anotherOne, one); |
1866 | 1853 |
1867 // The addition above can cause an allocation of a new | 1854 // The addition above can cause an allocation of a new |
1868 // backing store. We therefore garbage collect before | 1855 // backing store. We therefore garbage collect before |
1869 // taking the heap stats in order to get rid of the old | 1856 // taking the heap stats in order to get rid of the old |
1870 // backing store. We make sure to not use conservative | 1857 // backing store. We make sure to not use conservative |
1871 // stack scanning as that could find a pointer to the | 1858 // stack scanning as that could find a pointer to the |
1872 // old backing. | 1859 // old backing. |
1873 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1860 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1874 HeapStats afterAddAndGC; | 1861 size_t afterAddAndGC = objectPayloadSize(); |
1875 getHeapStats(&afterAddAndGC); | 1862 EXPECT_TRUE(afterAddAndGC >= afterOneAdd); |
1876 EXPECT_TRUE(afterAddAndGC.totalObjectSpace() >= afterOneAdd.totalObjectS
pace()); | |
1877 | 1863 |
1878 EXPECT_EQ(map->size(), 2u); // Two different wrappings of '1' are distin
ct. | 1864 EXPECT_EQ(map->size(), 2u); // Two different wrappings of '1' are distin
ct. |
1879 | 1865 |
1880 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1866 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1881 EXPECT_TRUE(map->contains(one)); | 1867 EXPECT_TRUE(map->contains(one)); |
1882 EXPECT_TRUE(map->contains(anotherOne)); | 1868 EXPECT_TRUE(map->contains(anotherOne)); |
1883 | 1869 |
1884 IntWrapper* gotten(map->get(one)); | 1870 IntWrapper* gotten(map->get(one)); |
1885 EXPECT_EQ(gotten->value(), one->value()); | 1871 EXPECT_EQ(gotten->value(), one->value()); |
1886 EXPECT_EQ(gotten, one); | 1872 EXPECT_EQ(gotten, one); |
1887 | 1873 |
1888 HeapStats afterGC2; | 1874 size_t afterGC2 = objectPayloadSize(); |
1889 getHeapStats(&afterGC2); | 1875 EXPECT_EQ(afterGC2, afterAddAndGC); |
1890 EXPECT_EQ(afterGC2.totalObjectSpace(), afterAddAndGC.totalObjectSpace())
; | |
1891 | 1876 |
1892 IntWrapper* dozen = 0; | 1877 IntWrapper* dozen = 0; |
1893 | 1878 |
1894 for (int i = 1; i < 1000; i++) { // 999 iterations. | 1879 for (int i = 1; i < 1000; i++) { // 999 iterations. |
1895 IntWrapper* iWrapper(IntWrapper::create(i)); | 1880 IntWrapper* iWrapper(IntWrapper::create(i)); |
1896 IntWrapper* iSquared(IntWrapper::create(i * i)); | 1881 IntWrapper* iSquared(IntWrapper::create(i * i)); |
1897 map->add(iWrapper, iSquared); | 1882 map->add(iWrapper, iSquared); |
1898 if (i == 12) | 1883 if (i == 12) |
1899 dozen = iWrapper; | 1884 dozen = iWrapper; |
1900 } | 1885 } |
1901 HeapStats afterAdding1000; | 1886 size_t afterAdding1000 = objectPayloadSize(); |
1902 getHeapStats(&afterAdding1000); | 1887 EXPECT_TRUE(afterAdding1000 > afterGC2); |
1903 EXPECT_TRUE(afterAdding1000.totalObjectSpace() > afterGC2.totalObjectSpa
ce()); | |
1904 | 1888 |
1905 IntWrapper* gross(map->get(dozen)); | 1889 IntWrapper* gross(map->get(dozen)); |
1906 EXPECT_EQ(gross->value(), 144); | 1890 EXPECT_EQ(gross->value(), 144); |
1907 | 1891 |
1908 // This should clear out any junk backings created by all the adds. | 1892 // This should clear out any junk backings created by all the adds. |
1909 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1893 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1910 HeapStats afterGC3; | 1894 size_t afterGC3 = objectPayloadSize(); |
1911 getHeapStats(&afterGC3); | 1895 EXPECT_TRUE(afterGC3 <= afterAdding1000); |
1912 EXPECT_TRUE(afterGC3.totalObjectSpace() <= afterAdding1000.totalObjectSp
ace()); | |
1913 } | 1896 } |
1914 | 1897 |
1915 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1898 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1916 // The objects 'one', anotherOne, and the 999 other pairs. | 1899 // The objects 'one', anotherOne, and the 999 other pairs. |
1917 EXPECT_EQ(IntWrapper::s_destructorCalls, 2000); | 1900 EXPECT_EQ(IntWrapper::s_destructorCalls, 2000); |
1918 HeapStats afterGC4; | 1901 size_t afterGC4 = objectPayloadSize(); |
1919 getHeapStats(&afterGC4); | 1902 EXPECT_EQ(afterGC4, initialObjectPayloadSize); |
1920 EXPECT_EQ(afterGC4.totalObjectSpace(), initialHeapSize.totalObjectSpace()); | |
1921 } | 1903 } |
1922 | 1904 |
1923 TEST(HeapTest, NestedAllocation) | 1905 TEST(HeapTest, NestedAllocation) |
1924 { | 1906 { |
1925 HeapStats initialHeapSize; | 1907 clearOutOldGarbage(); |
1926 clearOutOldGarbage(&initialHeapSize); | 1908 size_t initialObjectPayloadSize = objectPayloadSize(); |
1927 { | 1909 { |
1928 Persistent<ConstructorAllocation> constructorAllocation = ConstructorAll
ocation::create(); | 1910 Persistent<ConstructorAllocation> constructorAllocation = ConstructorAll
ocation::create(); |
1929 } | 1911 } |
1930 HeapStats afterFree; | 1912 clearOutOldGarbage(); |
1931 clearOutOldGarbage(&afterFree); | 1913 size_t afterFree = objectPayloadSize(); |
1932 EXPECT_TRUE(initialHeapSize == afterFree); | 1914 EXPECT_TRUE(initialObjectPayloadSize == afterFree); |
1933 } | 1915 } |
1934 | 1916 |
1935 TEST(HeapTest, LargeObjects) | 1917 TEST(HeapTest, LargeObjects) |
1936 { | 1918 { |
1937 HeapStats initialHeapSize; | 1919 clearOutOldGarbage(); |
1938 clearOutOldGarbage(&initialHeapSize); | 1920 size_t initialObjectPayloadSize = objectPayloadSize(); |
| 1921 size_t initialAllocatedSpace = Heap::allocatedSpace(); |
1939 IntWrapper::s_destructorCalls = 0; | 1922 IntWrapper::s_destructorCalls = 0; |
1940 LargeObject::s_destructorCalls = 0; | 1923 LargeObject::s_destructorCalls = 0; |
1941 { | 1924 { |
1942 int slack = 8; // LargeObject points to an IntWrapper that is also alloc
ated. | 1925 int slack = 8; // LargeObject points to an IntWrapper that is also alloc
ated. |
1943 Persistent<LargeObject> object = LargeObject::create(); | 1926 Persistent<LargeObject> object = LargeObject::create(); |
1944 EXPECT_TRUE(ThreadState::current()->contains(object)); | 1927 EXPECT_TRUE(ThreadState::current()->contains(object)); |
1945 EXPECT_TRUE(ThreadState::current()->contains(reinterpret_cast<char*>(obj
ect.get()) + sizeof(LargeObject) - 1)); | 1928 EXPECT_TRUE(ThreadState::current()->contains(reinterpret_cast<char*>(obj
ect.get()) + sizeof(LargeObject) - 1)); |
1946 #if ENABLE(GC_PROFILE_MARKING) | 1929 #if ENABLE(GC_PROFILE_MARKING) |
1947 const GCInfo* info = ThreadState::current()->findGCInfo(reinterpret_cast
<Address>(object.get())); | 1930 const GCInfo* info = ThreadState::current()->findGCInfo(reinterpret_cast
<Address>(object.get())); |
1948 EXPECT_NE(reinterpret_cast<const GCInfo*>(0), info); | 1931 EXPECT_NE(reinterpret_cast<const GCInfo*>(0), info); |
1949 EXPECT_EQ(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) + sizeof(LargeObject) - 1)); | 1932 EXPECT_EQ(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) + sizeof(LargeObject) - 1)); |
1950 EXPECT_NE(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) + sizeof(LargeObject))); | 1933 EXPECT_NE(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) + sizeof(LargeObject))); |
1951 EXPECT_NE(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) - 1)); | 1934 EXPECT_NE(info, ThreadState::current()->findGCInfo(reinterpret_cast<Addr
ess>(object.get()) - 1)); |
1952 #endif | 1935 #endif |
1953 HeapStats afterAllocation; | 1936 clearOutOldGarbage(); |
1954 clearOutOldGarbage(&afterAllocation); | 1937 size_t afterAllocation = Heap::allocatedSpace(); |
1955 { | 1938 { |
1956 object->set(0, 'a'); | 1939 object->set(0, 'a'); |
1957 EXPECT_EQ('a', object->get(0)); | 1940 EXPECT_EQ('a', object->get(0)); |
1958 object->set(object->length() - 1, 'b'); | 1941 object->set(object->length() - 1, 'b'); |
1959 EXPECT_EQ('b', object->get(object->length() - 1)); | 1942 EXPECT_EQ('b', object->get(object->length() - 1)); |
1960 size_t expectedObjectSpace = sizeof(LargeObject) + sizeof(IntWrapper
); | 1943 size_t expectedObjectPayloadSize = sizeof(LargeObject) + sizeof(IntW
rapper); |
1961 size_t actualObjectSpace = | 1944 size_t actualObjectPayloadSize = objectPayloadSize() - initialObject
PayloadSize; |
1962 afterAllocation.totalObjectSpace() - initialHeapSize.totalObject
Space(); | 1945 CheckWithSlack(expectedObjectPayloadSize, actualObjectPayloadSize, s
lack); |
1963 CheckWithSlack(expectedObjectSpace, actualObjectSpace, slack); | |
1964 // There is probably space for the IntWrapper in a heap page without | 1946 // There is probably space for the IntWrapper in a heap page without |
1965 // allocating extra pages. However, the IntWrapper allocation might
cause | 1947 // allocating extra pages. However, the IntWrapper allocation might
cause |
1966 // the addition of a heap page. | 1948 // the addition of a heap page. |
1967 size_t largeObjectAllocationSize = | 1949 size_t largeObjectAllocationSize = |
1968 sizeof(LargeObject) + sizeof(LargeHeapObject<FinalizedHeapObject
Header>) + sizeof(FinalizedHeapObjectHeader); | 1950 sizeof(LargeObject) + sizeof(LargeHeapObject<FinalizedHeapObject
Header>) + sizeof(FinalizedHeapObjectHeader); |
1969 size_t allocatedSpaceLowerBound = | 1951 size_t allocatedSpaceLowerBound = initialAllocatedSpace + largeObjec
tAllocationSize; |
1970 initialHeapSize.totalAllocatedSpace() + largeObjectAllocationSiz
e; | |
1971 size_t allocatedSpaceUpperBound = allocatedSpaceLowerBound + slack +
blinkPageSize; | 1952 size_t allocatedSpaceUpperBound = allocatedSpaceLowerBound + slack +
blinkPageSize; |
1972 EXPECT_LE(allocatedSpaceLowerBound, afterAllocation.totalAllocatedSp
ace()); | 1953 EXPECT_LE(allocatedSpaceLowerBound, afterAllocation); |
1973 EXPECT_LE(afterAllocation.totalAllocatedSpace(), allocatedSpaceUpper
Bound); | 1954 EXPECT_LE(afterAllocation, allocatedSpaceUpperBound); |
1974 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 1955 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
1975 EXPECT_EQ(0, LargeObject::s_destructorCalls); | 1956 EXPECT_EQ(0, LargeObject::s_destructorCalls); |
1976 for (int i = 0; i < 10; i++) | 1957 for (int i = 0; i < 10; i++) |
1977 object = LargeObject::create(); | 1958 object = LargeObject::create(); |
1978 } | 1959 } |
1979 HeapStats oneLargeObject; | 1960 clearOutOldGarbage(); |
1980 clearOutOldGarbage(&oneLargeObject); | 1961 EXPECT_TRUE(Heap::allocatedSpace() == afterAllocation); |
1981 EXPECT_TRUE(oneLargeObject == afterAllocation); | |
1982 EXPECT_EQ(10, IntWrapper::s_destructorCalls); | 1962 EXPECT_EQ(10, IntWrapper::s_destructorCalls); |
1983 EXPECT_EQ(10, LargeObject::s_destructorCalls); | 1963 EXPECT_EQ(10, LargeObject::s_destructorCalls); |
1984 } | 1964 } |
1985 HeapStats backToInitial; | 1965 clearOutOldGarbage(); |
1986 clearOutOldGarbage(&backToInitial); | 1966 EXPECT_TRUE(initialObjectPayloadSize == objectPayloadSize()); |
1987 EXPECT_TRUE(initialHeapSize == backToInitial); | 1967 EXPECT_TRUE(initialAllocatedSpace == Heap::allocatedSpace()); |
1988 EXPECT_EQ(11, IntWrapper::s_destructorCalls); | 1968 EXPECT_EQ(11, IntWrapper::s_destructorCalls); |
1989 EXPECT_EQ(11, LargeObject::s_destructorCalls); | 1969 EXPECT_EQ(11, LargeObject::s_destructorCalls); |
1990 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1970 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1991 } | 1971 } |
1992 | 1972 |
1993 typedef std::pair<Member<IntWrapper>, int> PairWrappedUnwrapped; | 1973 typedef std::pair<Member<IntWrapper>, int> PairWrappedUnwrapped; |
1994 typedef std::pair<int, Member<IntWrapper> > PairUnwrappedWrapped; | 1974 typedef std::pair<int, Member<IntWrapper> > PairUnwrappedWrapped; |
1995 typedef std::pair<WeakMember<IntWrapper>, Member<IntWrapper> > PairWeakStrong; | 1975 typedef std::pair<WeakMember<IntWrapper>, Member<IntWrapper> > PairWeakStrong; |
1996 typedef std::pair<Member<IntWrapper>, WeakMember<IntWrapper> > PairStrongWeak; | 1976 typedef std::pair<Member<IntWrapper>, WeakMember<IntWrapper> > PairStrongWeak; |
1997 typedef std::pair<WeakMember<IntWrapper>, int> PairWeakUnwrapped; | 1977 typedef std::pair<WeakMember<IntWrapper>, int> PairWeakUnwrapped; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2177 typedef typename HeapDeque<T, inlineCapacity>::iterator iterator; | 2157 typedef typename HeapDeque<T, inlineCapacity>::iterator iterator; |
2178 for (iterator it = deque.begin(); it != deque.end(); ++it) { | 2158 for (iterator it = deque.begin(); it != deque.end(); ++it) { |
2179 if (*it == u) | 2159 if (*it == u) |
2180 return true; | 2160 return true; |
2181 } | 2161 } |
2182 return false; | 2162 return false; |
2183 } | 2163 } |
2184 | 2164 |
2185 TEST(HeapTest, HeapCollectionTypes) | 2165 TEST(HeapTest, HeapCollectionTypes) |
2186 { | 2166 { |
2187 HeapStats initialHeapSize; | |
2188 IntWrapper::s_destructorCalls = 0; | 2167 IntWrapper::s_destructorCalls = 0; |
2189 | 2168 |
2190 typedef HeapHashMap<Member<IntWrapper>, Member<IntWrapper> > MemberMember; | 2169 typedef HeapHashMap<Member<IntWrapper>, Member<IntWrapper> > MemberMember; |
2191 typedef HeapHashMap<Member<IntWrapper>, int> MemberPrimitive; | 2170 typedef HeapHashMap<Member<IntWrapper>, int> MemberPrimitive; |
2192 typedef HeapHashMap<int, Member<IntWrapper> > PrimitiveMember; | 2171 typedef HeapHashMap<int, Member<IntWrapper> > PrimitiveMember; |
2193 | 2172 |
2194 typedef HeapHashSet<Member<IntWrapper> > MemberSet; | 2173 typedef HeapHashSet<Member<IntWrapper> > MemberSet; |
2195 typedef HeapHashCountedSet<Member<IntWrapper> > MemberCountedSet; | 2174 typedef HeapHashCountedSet<Member<IntWrapper> > MemberCountedSet; |
2196 | 2175 |
2197 typedef HeapVector<Member<IntWrapper>, 2> MemberVector; | 2176 typedef HeapVector<Member<IntWrapper>, 2> MemberVector; |
(...skipping 19 matching lines...) Expand all Loading... |
2217 Persistent<VectorUW> vectorUW = new VectorUW(); | 2196 Persistent<VectorUW> vectorUW = new VectorUW(); |
2218 Persistent<VectorUW> vectorUW2 = new VectorUW(); | 2197 Persistent<VectorUW> vectorUW2 = new VectorUW(); |
2219 Persistent<MemberDeque> deque = new MemberDeque(); | 2198 Persistent<MemberDeque> deque = new MemberDeque(); |
2220 Persistent<MemberDeque> deque2 = new MemberDeque(); | 2199 Persistent<MemberDeque> deque2 = new MemberDeque(); |
2221 Persistent<DequeWU> dequeWU = new DequeWU(); | 2200 Persistent<DequeWU> dequeWU = new DequeWU(); |
2222 Persistent<DequeWU> dequeWU2 = new DequeWU(); | 2201 Persistent<DequeWU> dequeWU2 = new DequeWU(); |
2223 Persistent<DequeUW> dequeUW = new DequeUW(); | 2202 Persistent<DequeUW> dequeUW = new DequeUW(); |
2224 Persistent<DequeUW> dequeUW2 = new DequeUW(); | 2203 Persistent<DequeUW> dequeUW2 = new DequeUW(); |
2225 Persistent<Container> container = Container::create(); | 2204 Persistent<Container> container = Container::create(); |
2226 | 2205 |
2227 clearOutOldGarbage(&initialHeapSize); | 2206 clearOutOldGarbage(); |
2228 { | 2207 { |
2229 Persistent<IntWrapper> one(IntWrapper::create(1)); | 2208 Persistent<IntWrapper> one(IntWrapper::create(1)); |
2230 Persistent<IntWrapper> two(IntWrapper::create(2)); | 2209 Persistent<IntWrapper> two(IntWrapper::create(2)); |
2231 Persistent<IntWrapper> oneB(IntWrapper::create(1)); | 2210 Persistent<IntWrapper> oneB(IntWrapper::create(1)); |
2232 Persistent<IntWrapper> twoB(IntWrapper::create(2)); | 2211 Persistent<IntWrapper> twoB(IntWrapper::create(2)); |
2233 Persistent<IntWrapper> oneC(IntWrapper::create(1)); | 2212 Persistent<IntWrapper> oneC(IntWrapper::create(1)); |
2234 Persistent<IntWrapper> oneD(IntWrapper::create(1)); | 2213 Persistent<IntWrapper> oneD(IntWrapper::create(1)); |
2235 Persistent<IntWrapper> oneE(IntWrapper::create(1)); | 2214 Persistent<IntWrapper> oneE(IntWrapper::create(1)); |
2236 Persistent<IntWrapper> oneF(IntWrapper::create(1)); | 2215 Persistent<IntWrapper> oneF(IntWrapper::create(1)); |
2237 { | 2216 { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2500 found++; | 2479 found++; |
2501 int value = (*it)->value(); | 2480 int value = (*it)->value(); |
2502 EXPECT_TRUE(value >= 0 && value < 1100); | 2481 EXPECT_TRUE(value >= 0 && value < 1100); |
2503 ++it; | 2482 ++it; |
2504 } | 2483 } |
2505 EXPECT_EQ(expected, found); | 2484 EXPECT_EQ(expected, found); |
2506 } | 2485 } |
2507 | 2486 |
2508 TEST(HeapTest, HeapWeakCollectionSimple) | 2487 TEST(HeapTest, HeapWeakCollectionSimple) |
2509 { | 2488 { |
2510 HeapStats initialHeapStats; | 2489 clearOutOldGarbage(); |
2511 clearOutOldGarbage(&initialHeapStats); | |
2512 IntWrapper::s_destructorCalls = 0; | 2490 IntWrapper::s_destructorCalls = 0; |
2513 | 2491 |
2514 PersistentHeapVector<Member<IntWrapper> > keepNumbersAlive; | 2492 PersistentHeapVector<Member<IntWrapper> > keepNumbersAlive; |
2515 | 2493 |
2516 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStrong; | 2494 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStrong; |
2517 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongWeak; | 2495 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongWeak; |
2518 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > WeakWea
k; | 2496 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > WeakWea
k; |
2519 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; | 2497 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; |
2520 typedef HeapHashCountedSet<WeakMember<IntWrapper> > WeakCountedSet; | 2498 typedef HeapHashCountedSet<WeakMember<IntWrapper> > WeakCountedSet; |
2521 | 2499 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2562 EXPECT_EQ(0u, weakStrong->size()); | 2540 EXPECT_EQ(0u, weakStrong->size()); |
2563 EXPECT_EQ(0u, strongWeak->size()); | 2541 EXPECT_EQ(0u, strongWeak->size()); |
2564 EXPECT_EQ(0u, weakWeak->size()); | 2542 EXPECT_EQ(0u, weakWeak->size()); |
2565 EXPECT_EQ(2u, weakSet->size()); | 2543 EXPECT_EQ(2u, weakSet->size()); |
2566 EXPECT_EQ(2u, weakCountedSet->size()); | 2544 EXPECT_EQ(2u, weakCountedSet->size()); |
2567 } | 2545 } |
2568 | 2546 |
2569 template<typename Set> | 2547 template<typename Set> |
2570 void orderedSetHelper(bool strong) | 2548 void orderedSetHelper(bool strong) |
2571 { | 2549 { |
2572 HeapStats initialHeapStats; | 2550 clearOutOldGarbage(); |
2573 clearOutOldGarbage(&initialHeapStats); | |
2574 IntWrapper::s_destructorCalls = 0; | 2551 IntWrapper::s_destructorCalls = 0; |
2575 | 2552 |
2576 PersistentHeapVector<Member<IntWrapper> > keepNumbersAlive; | 2553 PersistentHeapVector<Member<IntWrapper> > keepNumbersAlive; |
2577 | 2554 |
2578 Persistent<Set> set1 = new Set(); | 2555 Persistent<Set> set1 = new Set(); |
2579 Persistent<Set> set2 = new Set(); | 2556 Persistent<Set> set2 = new Set(); |
2580 | 2557 |
2581 const Set& constSet = *set1.get(); | 2558 const Set& constSet = *set1.get(); |
2582 | 2559 |
2583 keepNumbersAlive.append(IntWrapper::create(2)); | 2560 keepNumbersAlive.append(IntWrapper::create(2)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 }; | 2699 }; |
2723 | 2700 |
2724 int ThingWithDestructor::s_liveThingsWithDestructor; | 2701 int ThingWithDestructor::s_liveThingsWithDestructor; |
2725 | 2702 |
2726 struct ThingWithDestructorTraits : public HashTraits<ThingWithDestructor> { | 2703 struct ThingWithDestructorTraits : public HashTraits<ThingWithDestructor> { |
2727 static const bool needsDestruction = true; | 2704 static const bool needsDestruction = true; |
2728 }; | 2705 }; |
2729 | 2706 |
2730 static void heapMapDestructorHelper(bool clearMaps) | 2707 static void heapMapDestructorHelper(bool clearMaps) |
2731 { | 2708 { |
2732 HeapStats initialHeapStats; | 2709 clearOutOldGarbage(); |
2733 clearOutOldGarbage(&initialHeapStats); | |
2734 ThingWithDestructor::s_liveThingsWithDestructor = 0; | 2710 ThingWithDestructor::s_liveThingsWithDestructor = 0; |
2735 | 2711 |
2736 typedef HeapHashMap<WeakMember<IntWrapper>, Member<RefCountedAndGarbageColle
cted> > RefMap; | 2712 typedef HeapHashMap<WeakMember<IntWrapper>, Member<RefCountedAndGarbageColle
cted> > RefMap; |
2737 | 2713 |
2738 typedef HeapHashMap< | 2714 typedef HeapHashMap< |
2739 WeakMember<IntWrapper>, | 2715 WeakMember<IntWrapper>, |
2740 ThingWithDestructor, | 2716 ThingWithDestructor, |
2741 DefaultHash<WeakMember<IntWrapper> >::Hash, | 2717 DefaultHash<WeakMember<IntWrapper> >::Hash, |
2742 HashTraits<WeakMember<IntWrapper> >, | 2718 HashTraits<WeakMember<IntWrapper> >, |
2743 ThingWithDestructorTraits> Map; | 2719 ThingWithDestructorTraits> Map; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2947 typedef HeapLinkedHashSet<PairWeakStrong> WeakStrongSet; | 2923 typedef HeapLinkedHashSet<PairWeakStrong> WeakStrongSet; |
2948 typedef HeapLinkedHashSet<PairWeakUnwrapped> WeakUnwrappedSet; | 2924 typedef HeapLinkedHashSet<PairWeakUnwrapped> WeakUnwrappedSet; |
2949 typedef HeapLinkedHashSet<PairStrongWeak> StrongWeakSet; | 2925 typedef HeapLinkedHashSet<PairStrongWeak> StrongWeakSet; |
2950 typedef HeapLinkedHashSet<PairUnwrappedWeak> UnwrappedWeakSet; | 2926 typedef HeapLinkedHashSet<PairUnwrappedWeak> UnwrappedWeakSet; |
2951 weakPairsHelper<WeakStrongSet, StrongWeakSet, WeakUnwrappedSet, Unwrappe
dWeakSet>(); | 2927 weakPairsHelper<WeakStrongSet, StrongWeakSet, WeakUnwrappedSet, Unwrappe
dWeakSet>(); |
2952 } | 2928 } |
2953 } | 2929 } |
2954 | 2930 |
2955 TEST(HeapTest, HeapWeakCollectionTypes) | 2931 TEST(HeapTest, HeapWeakCollectionTypes) |
2956 { | 2932 { |
2957 HeapStats initialHeapSize; | |
2958 IntWrapper::s_destructorCalls = 0; | 2933 IntWrapper::s_destructorCalls = 0; |
2959 | 2934 |
2960 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStrong; | 2935 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStrong; |
2961 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongWeak; | 2936 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongWeak; |
2962 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > WeakWea
k; | 2937 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > WeakWea
k; |
2963 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; | 2938 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; |
2964 typedef HeapLinkedHashSet<WeakMember<IntWrapper> > WeakOrderedSet; | 2939 typedef HeapLinkedHashSet<WeakMember<IntWrapper> > WeakOrderedSet; |
2965 | 2940 |
2966 clearOutOldGarbage(&initialHeapSize); | 2941 clearOutOldGarbage(); |
2967 | 2942 |
2968 const int weakStrongIndex = 0; | 2943 const int weakStrongIndex = 0; |
2969 const int strongWeakIndex = 1; | 2944 const int strongWeakIndex = 1; |
2970 const int weakWeakIndex = 2; | 2945 const int weakWeakIndex = 2; |
2971 const int numberOfMapIndices = 3; | 2946 const int numberOfMapIndices = 3; |
2972 const int weakSetIndex = 3; | 2947 const int weakSetIndex = 3; |
2973 const int weakOrderedSetIndex = 4; | 2948 const int weakOrderedSetIndex = 4; |
2974 const int numberOfCollections = 5; | 2949 const int numberOfCollections = 5; |
2975 | 2950 |
2976 for (int testRun = 0; testRun < 4; testRun++) { | 2951 for (int testRun = 0; testRun < 4; testRun++) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3342 { | 3317 { |
3343 Persistent<Bar> barPersistent = Bar::create(); | 3318 Persistent<Bar> barPersistent = Bar::create(); |
3344 Persistent<Foo> fooPersistent = Foo::create(barPersistent); | 3319 Persistent<Foo> fooPersistent = Foo::create(barPersistent); |
3345 EXPECT_TRUE(barPersistent != fooPersistent); | 3320 EXPECT_TRUE(barPersistent != fooPersistent); |
3346 barPersistent = fooPersistent; | 3321 barPersistent = fooPersistent; |
3347 EXPECT_TRUE(barPersistent == fooPersistent); | 3322 EXPECT_TRUE(barPersistent == fooPersistent); |
3348 } | 3323 } |
3349 | 3324 |
3350 TEST(HeapTest, CheckAndMarkPointer) | 3325 TEST(HeapTest, CheckAndMarkPointer) |
3351 { | 3326 { |
3352 HeapStats initialHeapStats; | 3327 clearOutOldGarbage(); |
3353 clearOutOldGarbage(&initialHeapStats); | |
3354 | 3328 |
3355 Vector<Address> objectAddresses; | 3329 Vector<Address> objectAddresses; |
3356 Vector<Address> endAddresses; | 3330 Vector<Address> endAddresses; |
3357 Address largeObjectAddress; | 3331 Address largeObjectAddress; |
3358 Address largeObjectEndAddress; | 3332 Address largeObjectEndAddress; |
3359 CountingVisitor visitor; | 3333 CountingVisitor visitor; |
3360 for (int i = 0; i < 10; i++) { | 3334 for (int i = 0; i < 10; i++) { |
3361 SimpleObject* object = SimpleObject::create(); | 3335 SimpleObject* object = SimpleObject::create(); |
3362 Address objectAddress = reinterpret_cast<Address>(object); | 3336 Address objectAddress = reinterpret_cast<Address>(object); |
3363 objectAddresses.append(objectAddress); | 3337 objectAddresses.append(objectAddress); |
(...skipping 22 matching lines...) Expand all Loading... |
3386 EXPECT_EQ(objectAddresses.size() * 2, visitor.count()); | 3360 EXPECT_EQ(objectAddresses.size() * 2, visitor.count()); |
3387 visitor.reset(); | 3361 visitor.reset(); |
3388 EXPECT_TRUE(Heap::checkAndMarkPointer(&visitor, largeObjectAddress)); | 3362 EXPECT_TRUE(Heap::checkAndMarkPointer(&visitor, largeObjectAddress)); |
3389 EXPECT_TRUE(Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress)); | 3363 EXPECT_TRUE(Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress)); |
3390 EXPECT_EQ(2ul, visitor.count()); | 3364 EXPECT_EQ(2ul, visitor.count()); |
3391 visitor.reset(); | 3365 visitor.reset(); |
3392 } | 3366 } |
3393 // This forces a GC without stack scanning which results in the objects | 3367 // This forces a GC without stack scanning which results in the objects |
3394 // being collected. This will also rebuild the above mentioned freelists, | 3368 // being collected. This will also rebuild the above mentioned freelists, |
3395 // however we don't rely on that below since we don't have any allocations. | 3369 // however we don't rely on that below since we don't have any allocations. |
3396 clearOutOldGarbage(&initialHeapStats); | 3370 clearOutOldGarbage(); |
3397 { | 3371 { |
3398 TestGCScope scope(ThreadState::HeapPointersOnStack); | 3372 TestGCScope scope(ThreadState::HeapPointersOnStack); |
3399 EXPECT_TRUE(scope.allThreadsParked()); | 3373 EXPECT_TRUE(scope.allThreadsParked()); |
3400 Heap::prepareForGC(); | 3374 Heap::prepareForGC(); |
3401 Heap::flushHeapDoesNotContainCache(); | 3375 Heap::flushHeapDoesNotContainCache(); |
3402 for (size_t i = 0; i < objectAddresses.size(); i++) { | 3376 for (size_t i = 0; i < objectAddresses.size(); i++) { |
3403 // We would like to assert that checkAndMarkPointer returned false | 3377 // We would like to assert that checkAndMarkPointer returned false |
3404 // here because the pointers no longer point into a valid object | 3378 // here because the pointers no longer point into a valid object |
3405 // (it's been freed by the GCs. But checkAndMarkPointer will return | 3379 // (it's been freed by the GCs. But checkAndMarkPointer will return |
3406 // true for any pointer that points into a heap page, regardless of | 3380 // true for any pointer that points into a heap page, regardless of |
3407 // whether it points at a valid object (this ensures the | 3381 // whether it points at a valid object (this ensures the |
3408 // correctness of the page-based on-heap address caches), so we | 3382 // correctness of the page-based on-heap address caches), so we |
3409 // can't make that assert. | 3383 // can't make that assert. |
3410 Heap::checkAndMarkPointer(&visitor, objectAddresses[i]); | 3384 Heap::checkAndMarkPointer(&visitor, objectAddresses[i]); |
3411 Heap::checkAndMarkPointer(&visitor, endAddresses[i]); | 3385 Heap::checkAndMarkPointer(&visitor, endAddresses[i]); |
3412 } | 3386 } |
3413 EXPECT_EQ(0ul, visitor.count()); | 3387 EXPECT_EQ(0ul, visitor.count()); |
3414 Heap::checkAndMarkPointer(&visitor, largeObjectAddress); | 3388 Heap::checkAndMarkPointer(&visitor, largeObjectAddress); |
3415 Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress); | 3389 Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress); |
3416 EXPECT_EQ(0ul, visitor.count()); | 3390 EXPECT_EQ(0ul, visitor.count()); |
3417 } | 3391 } |
3418 // This round of GC is important to make sure that the object start | 3392 // This round of GC is important to make sure that the object start |
3419 // bitmap are cleared out and that the free lists are rebuild. | 3393 // bitmap are cleared out and that the free lists are rebuild. |
3420 clearOutOldGarbage(&initialHeapStats); | 3394 clearOutOldGarbage(); |
3421 } | 3395 } |
3422 | 3396 |
3423 TEST(HeapTest, VisitOffHeapCollections) | 3397 TEST(HeapTest, VisitOffHeapCollections) |
3424 { | 3398 { |
3425 HeapStats initialHeapStats; | 3399 clearOutOldGarbage(); |
3426 clearOutOldGarbage(&initialHeapStats); | |
3427 IntWrapper::s_destructorCalls = 0; | 3400 IntWrapper::s_destructorCalls = 0; |
3428 Persistent<OffHeapContainer> container = OffHeapContainer::create(); | 3401 Persistent<OffHeapContainer> container = OffHeapContainer::create(); |
3429 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3402 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3430 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3403 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3431 container = nullptr; | 3404 container = nullptr; |
3432 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3405 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3433 EXPECT_EQ(OffHeapContainer::deadWrappers, IntWrapper::s_destructorCalls); | 3406 EXPECT_EQ(OffHeapContainer::deadWrappers, IntWrapper::s_destructorCalls); |
3434 } | 3407 } |
3435 | 3408 |
3436 TEST(HeapTest, PersistentHeapCollectionTypes) | 3409 TEST(HeapTest, PersistentHeapCollectionTypes) |
3437 { | 3410 { |
3438 HeapStats initialHeapSize; | |
3439 IntWrapper::s_destructorCalls = 0; | 3411 IntWrapper::s_destructorCalls = 0; |
3440 | 3412 |
3441 typedef HeapVector<Member<IntWrapper> > Vec; | 3413 typedef HeapVector<Member<IntWrapper> > Vec; |
3442 typedef PersistentHeapVector<Member<IntWrapper> > PVec; | 3414 typedef PersistentHeapVector<Member<IntWrapper> > PVec; |
3443 typedef PersistentHeapHashSet<Member<IntWrapper> > PSet; | 3415 typedef PersistentHeapHashSet<Member<IntWrapper> > PSet; |
3444 typedef PersistentHeapListHashSet<Member<IntWrapper> > PListSet; | 3416 typedef PersistentHeapListHashSet<Member<IntWrapper> > PListSet; |
3445 typedef PersistentHeapLinkedHashSet<Member<IntWrapper> > PLinkedSet; | 3417 typedef PersistentHeapLinkedHashSet<Member<IntWrapper> > PLinkedSet; |
3446 typedef PersistentHeapHashMap<Member<IntWrapper>, Member<IntWrapper> > PMap; | 3418 typedef PersistentHeapHashMap<Member<IntWrapper>, Member<IntWrapper> > PMap; |
3447 typedef PersistentHeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > W
eakPMap; | 3419 typedef PersistentHeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > W
eakPMap; |
3448 typedef PersistentHeapDeque<Member<IntWrapper> > PDeque; | 3420 typedef PersistentHeapDeque<Member<IntWrapper> > PDeque; |
3449 | 3421 |
3450 clearOutOldGarbage(&initialHeapSize); | 3422 clearOutOldGarbage(); |
3451 { | 3423 { |
3452 PVec pVec; | 3424 PVec pVec; |
3453 PDeque pDeque; | 3425 PDeque pDeque; |
3454 PSet pSet; | 3426 PSet pSet; |
3455 PListSet pListSet; | 3427 PListSet pListSet; |
3456 PLinkedSet pLinkedSet; | 3428 PLinkedSet pLinkedSet; |
3457 PMap pMap; | 3429 PMap pMap; |
3458 WeakPMap wpMap; | 3430 WeakPMap wpMap; |
3459 | 3431 |
3460 IntWrapper* one(IntWrapper::create(1)); | 3432 IntWrapper* one(IntWrapper::create(1)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3522 EXPECT_EQ(0u, wpMap.size()); | 3494 EXPECT_EQ(0u, wpMap.size()); |
3523 } | 3495 } |
3524 | 3496 |
3525 // Collect previous roots. | 3497 // Collect previous roots. |
3526 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3498 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3527 EXPECT_EQ(11, IntWrapper::s_destructorCalls); | 3499 EXPECT_EQ(11, IntWrapper::s_destructorCalls); |
3528 } | 3500 } |
3529 | 3501 |
3530 TEST(HeapTest, CollectionNesting) | 3502 TEST(HeapTest, CollectionNesting) |
3531 { | 3503 { |
3532 HeapStats initialStats; | 3504 clearOutOldGarbage(); |
3533 clearOutOldGarbage(&initialStats); | |
3534 int* key = &IntWrapper::s_destructorCalls; | 3505 int* key = &IntWrapper::s_destructorCalls; |
3535 IntWrapper::s_destructorCalls = 0; | 3506 IntWrapper::s_destructorCalls = 0; |
3536 typedef HeapVector<Member<IntWrapper> > IntVector; | 3507 typedef HeapVector<Member<IntWrapper> > IntVector; |
3537 typedef HeapDeque<Member<IntWrapper> > IntDeque; | 3508 typedef HeapDeque<Member<IntWrapper> > IntDeque; |
3538 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); | 3509 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); |
3539 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); | 3510 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); |
3540 | 3511 |
3541 map->add(key, IntVector()); | 3512 map->add(key, IntVector()); |
3542 map2->add(key, IntDeque()); | 3513 map2->add(key, IntDeque()); |
3543 | 3514 |
(...skipping 23 matching lines...) Expand all Loading... |
3567 EXPECT_EQ(1u, map2->get(key).size()); | 3538 EXPECT_EQ(1u, map2->get(key).size()); |
3568 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3539 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3569 | 3540 |
3570 keepAlive = nullptr; | 3541 keepAlive = nullptr; |
3571 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3542 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3572 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 3543 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
3573 } | 3544 } |
3574 | 3545 |
3575 TEST(HeapTest, GarbageCollectedMixin) | 3546 TEST(HeapTest, GarbageCollectedMixin) |
3576 { | 3547 { |
3577 HeapStats initialHeapStats; | 3548 clearOutOldGarbage(); |
3578 clearOutOldGarbage(&initialHeapStats); | |
3579 | 3549 |
3580 Persistent<UseMixin> usemixin = UseMixin::create(); | 3550 Persistent<UseMixin> usemixin = UseMixin::create(); |
3581 EXPECT_EQ(0, UseMixin::s_traceCount); | 3551 EXPECT_EQ(0, UseMixin::s_traceCount); |
3582 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3552 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3583 EXPECT_EQ(1, UseMixin::s_traceCount); | 3553 EXPECT_EQ(1, UseMixin::s_traceCount); |
3584 | 3554 |
3585 Persistent<Mixin> mixin = usemixin; | 3555 Persistent<Mixin> mixin = usemixin; |
3586 usemixin = nullptr; | 3556 usemixin = nullptr; |
3587 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3557 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3588 EXPECT_EQ(2, UseMixin::s_traceCount); | 3558 EXPECT_EQ(2, UseMixin::s_traceCount); |
3589 | 3559 |
3590 PersistentHeapHashSet<WeakMember<Mixin> > weakMap; | 3560 PersistentHeapHashSet<WeakMember<Mixin> > weakMap; |
3591 weakMap.add(UseMixin::create()); | 3561 weakMap.add(UseMixin::create()); |
3592 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3562 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3593 EXPECT_EQ(0u, weakMap.size()); | 3563 EXPECT_EQ(0u, weakMap.size()); |
3594 } | 3564 } |
3595 | 3565 |
3596 TEST(HeapTest, CollectionNesting2) | 3566 TEST(HeapTest, CollectionNesting2) |
3597 { | 3567 { |
3598 HeapStats initialStats; | 3568 clearOutOldGarbage(); |
3599 clearOutOldGarbage(&initialStats); | |
3600 void* key = &IntWrapper::s_destructorCalls; | 3569 void* key = &IntWrapper::s_destructorCalls; |
3601 IntWrapper::s_destructorCalls = 0; | 3570 IntWrapper::s_destructorCalls = 0; |
3602 typedef HeapHashSet<Member<IntWrapper> > IntSet; | 3571 typedef HeapHashSet<Member<IntWrapper> > IntSet; |
3603 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); | 3572 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); |
3604 | 3573 |
3605 map->add(key, IntSet()); | 3574 map->add(key, IntSet()); |
3606 | 3575 |
3607 HeapHashMap<void*, IntSet>::iterator it = map->find(key); | 3576 HeapHashMap<void*, IntSet>::iterator it = map->find(key); |
3608 EXPECT_EQ(0u, map->get(key).size()); | 3577 EXPECT_EQ(0u, map->get(key).size()); |
3609 | 3578 |
3610 it->value.add(IntWrapper::create(42)); | 3579 it->value.add(IntWrapper::create(42)); |
3611 EXPECT_EQ(1u, map->get(key).size()); | 3580 EXPECT_EQ(1u, map->get(key).size()); |
3612 | 3581 |
3613 Persistent<HeapHashMap<void*, IntSet> > keepAlive(map); | 3582 Persistent<HeapHashMap<void*, IntSet> > keepAlive(map); |
3614 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3583 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3615 EXPECT_EQ(1u, map->get(key).size()); | 3584 EXPECT_EQ(1u, map->get(key).size()); |
3616 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3585 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3617 } | 3586 } |
3618 | 3587 |
3619 TEST(HeapTest, CollectionNesting3) | 3588 TEST(HeapTest, CollectionNesting3) |
3620 { | 3589 { |
3621 HeapStats initialStats; | 3590 clearOutOldGarbage(); |
3622 clearOutOldGarbage(&initialStats); | |
3623 IntWrapper::s_destructorCalls = 0; | 3591 IntWrapper::s_destructorCalls = 0; |
3624 typedef HeapVector<Member<IntWrapper> > IntVector; | 3592 typedef HeapVector<Member<IntWrapper> > IntVector; |
3625 typedef HeapDeque<Member<IntWrapper> > IntDeque; | 3593 typedef HeapDeque<Member<IntWrapper> > IntDeque; |
3626 HeapVector<IntVector>* vector = new HeapVector<IntVector>(); | 3594 HeapVector<IntVector>* vector = new HeapVector<IntVector>(); |
3627 HeapDeque<IntDeque>* deque = new HeapDeque<IntDeque>(); | 3595 HeapDeque<IntDeque>* deque = new HeapDeque<IntDeque>(); |
3628 | 3596 |
3629 vector->append(IntVector()); | 3597 vector->append(IntVector()); |
3630 deque->append(IntDeque()); | 3598 deque->append(IntDeque()); |
3631 | 3599 |
3632 HeapVector<IntVector>::iterator it = vector->begin(); | 3600 HeapVector<IntVector>::iterator it = vector->begin(); |
3633 HeapDeque<IntDeque>::iterator it2 = deque->begin(); | 3601 HeapDeque<IntDeque>::iterator it2 = deque->begin(); |
3634 EXPECT_EQ(0u, it->size()); | 3602 EXPECT_EQ(0u, it->size()); |
3635 EXPECT_EQ(0u, it2->size()); | 3603 EXPECT_EQ(0u, it2->size()); |
3636 | 3604 |
3637 it->append(IntWrapper::create(42)); | 3605 it->append(IntWrapper::create(42)); |
3638 it2->append(IntWrapper::create(42)); | 3606 it2->append(IntWrapper::create(42)); |
3639 EXPECT_EQ(1u, it->size()); | 3607 EXPECT_EQ(1u, it->size()); |
3640 EXPECT_EQ(1u, it2->size()); | 3608 EXPECT_EQ(1u, it2->size()); |
3641 | 3609 |
3642 Persistent<HeapVector<IntVector> > keepAlive(vector); | 3610 Persistent<HeapVector<IntVector> > keepAlive(vector); |
3643 Persistent<HeapDeque<IntDeque> > keepAlive2(deque); | 3611 Persistent<HeapDeque<IntDeque> > keepAlive2(deque); |
3644 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3612 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3645 EXPECT_EQ(1u, it->size()); | 3613 EXPECT_EQ(1u, it->size()); |
3646 EXPECT_EQ(1u, it2->size()); | 3614 EXPECT_EQ(1u, it2->size()); |
3647 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3615 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3648 } | 3616 } |
3649 | 3617 |
3650 TEST(HeapTest, EmbeddedInVector) | 3618 TEST(HeapTest, EmbeddedInVector) |
3651 { | 3619 { |
3652 HeapStats initialStats; | 3620 clearOutOldGarbage(); |
3653 clearOutOldGarbage(&initialStats); | |
3654 SimpleFinalizedObject::s_destructorCalls = 0; | 3621 SimpleFinalizedObject::s_destructorCalls = 0; |
3655 { | 3622 { |
3656 PersistentHeapVector<VectorObject, 2> inlineVector; | 3623 PersistentHeapVector<VectorObject, 2> inlineVector; |
3657 PersistentHeapVector<VectorObject> outlineVector; | 3624 PersistentHeapVector<VectorObject> outlineVector; |
3658 VectorObject i1, i2; | 3625 VectorObject i1, i2; |
3659 inlineVector.append(i1); | 3626 inlineVector.append(i1); |
3660 inlineVector.append(i2); | 3627 inlineVector.append(i2); |
3661 | 3628 |
3662 VectorObject o1, o2; | 3629 VectorObject o1, o2; |
3663 outlineVector.append(o1); | 3630 outlineVector.append(o1); |
(...skipping 18 matching lines...) Expand all Loading... |
3682 vectorNoTrace.append(n2); | 3649 vectorNoTrace.append(n2); |
3683 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3650 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3684 EXPECT_EQ(2, SimpleFinalizedObject::s_destructorCalls); | 3651 EXPECT_EQ(2, SimpleFinalizedObject::s_destructorCalls); |
3685 } | 3652 } |
3686 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3653 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3687 EXPECT_EQ(8, SimpleFinalizedObject::s_destructorCalls); | 3654 EXPECT_EQ(8, SimpleFinalizedObject::s_destructorCalls); |
3688 } | 3655 } |
3689 | 3656 |
3690 TEST(HeapTest, EmbeddedInDeque) | 3657 TEST(HeapTest, EmbeddedInDeque) |
3691 { | 3658 { |
3692 HeapStats initialStats; | 3659 clearOutOldGarbage(); |
3693 clearOutOldGarbage(&initialStats); | |
3694 SimpleFinalizedObject::s_destructorCalls = 0; | 3660 SimpleFinalizedObject::s_destructorCalls = 0; |
3695 { | 3661 { |
3696 PersistentHeapDeque<VectorObject, 2> inlineDeque; | 3662 PersistentHeapDeque<VectorObject, 2> inlineDeque; |
3697 PersistentHeapDeque<VectorObject> outlineDeque; | 3663 PersistentHeapDeque<VectorObject> outlineDeque; |
3698 VectorObject i1, i2; | 3664 VectorObject i1, i2; |
3699 inlineDeque.append(i1); | 3665 inlineDeque.append(i1); |
3700 inlineDeque.append(i2); | 3666 inlineDeque.append(i2); |
3701 | 3667 |
3702 VectorObject o1, o2; | 3668 VectorObject o1, o2; |
3703 outlineDeque.append(o1); | 3669 outlineDeque.append(o1); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3742 | 3708 |
3743 TEST(HeapTest, RawPtrInHash) | 3709 TEST(HeapTest, RawPtrInHash) |
3744 { | 3710 { |
3745 rawPtrInHashHelper<HashSet<RawPtr<int> > >(); | 3711 rawPtrInHashHelper<HashSet<RawPtr<int> > >(); |
3746 rawPtrInHashHelper<ListHashSet<RawPtr<int> > >(); | 3712 rawPtrInHashHelper<ListHashSet<RawPtr<int> > >(); |
3747 rawPtrInHashHelper<LinkedHashSet<RawPtr<int> > >(); | 3713 rawPtrInHashHelper<LinkedHashSet<RawPtr<int> > >(); |
3748 } | 3714 } |
3749 | 3715 |
3750 TEST(HeapTest, HeapTerminatedArray) | 3716 TEST(HeapTest, HeapTerminatedArray) |
3751 { | 3717 { |
3752 HeapStats initialHeapSize; | 3718 clearOutOldGarbage(); |
3753 clearOutOldGarbage(&initialHeapSize); | |
3754 IntWrapper::s_destructorCalls = 0; | 3719 IntWrapper::s_destructorCalls = 0; |
3755 | 3720 |
3756 HeapTerminatedArray<TerminatedArrayItem>* arr = 0; | 3721 HeapTerminatedArray<TerminatedArrayItem>* arr = 0; |
3757 | 3722 |
3758 const size_t prefixSize = 4; | 3723 const size_t prefixSize = 4; |
3759 const size_t suffixSize = 4; | 3724 const size_t suffixSize = 4; |
3760 | 3725 |
3761 { | 3726 { |
3762 HeapTerminatedArrayBuilder<TerminatedArrayItem> builder(arr); | 3727 HeapTerminatedArrayBuilder<TerminatedArrayItem> builder(arr); |
3763 builder.grow(prefixSize); | 3728 builder.grow(prefixSize); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3797 EXPECT_EQ(i, static_cast<size_t>(arr->at(i).payload()->value())); | 3762 EXPECT_EQ(i, static_cast<size_t>(arr->at(i).payload()->value())); |
3798 } | 3763 } |
3799 | 3764 |
3800 arr = 0; | 3765 arr = 0; |
3801 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3766 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3802 EXPECT_EQ(8, IntWrapper::s_destructorCalls); | 3767 EXPECT_EQ(8, IntWrapper::s_destructorCalls); |
3803 } | 3768 } |
3804 | 3769 |
3805 TEST(HeapTest, HeapLinkedStack) | 3770 TEST(HeapTest, HeapLinkedStack) |
3806 { | 3771 { |
3807 HeapStats initialHeapSize; | 3772 clearOutOldGarbage(); |
3808 clearOutOldGarbage(&initialHeapSize); | |
3809 IntWrapper::s_destructorCalls = 0; | 3773 IntWrapper::s_destructorCalls = 0; |
3810 | 3774 |
3811 HeapLinkedStack<TerminatedArrayItem>* stack = new HeapLinkedStack<Terminated
ArrayItem>(); | 3775 HeapLinkedStack<TerminatedArrayItem>* stack = new HeapLinkedStack<Terminated
ArrayItem>(); |
3812 | 3776 |
3813 const size_t stackSize = 10; | 3777 const size_t stackSize = 10; |
3814 | 3778 |
3815 for (size_t i = 0; i < stackSize; i++) | 3779 for (size_t i = 0; i < stackSize; i++) |
3816 stack->push(TerminatedArrayItem(IntWrapper::create(i))); | 3780 stack->push(TerminatedArrayItem(IntWrapper::create(i))); |
3817 | 3781 |
3818 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 3782 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
3819 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3783 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3820 EXPECT_EQ(stackSize, stack->size()); | 3784 EXPECT_EQ(stackSize, stack->size()); |
3821 while (!stack->isEmpty()) { | 3785 while (!stack->isEmpty()) { |
3822 EXPECT_EQ(stack->size() - 1, static_cast<size_t>(stack->peek().payload()
->value())); | 3786 EXPECT_EQ(stack->size() - 1, static_cast<size_t>(stack->peek().payload()
->value())); |
3823 stack->pop(); | 3787 stack->pop(); |
3824 } | 3788 } |
3825 | 3789 |
3826 Persistent<HeapLinkedStack<TerminatedArrayItem> > pStack = stack; | 3790 Persistent<HeapLinkedStack<TerminatedArrayItem> > pStack = stack; |
3827 | 3791 |
3828 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3792 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3829 EXPECT_EQ(stackSize, static_cast<size_t>(IntWrapper::s_destructorCalls)); | 3793 EXPECT_EQ(stackSize, static_cast<size_t>(IntWrapper::s_destructorCalls)); |
3830 EXPECT_EQ(0u, pStack->size()); | 3794 EXPECT_EQ(0u, pStack->size()); |
3831 } | 3795 } |
3832 | 3796 |
3833 TEST(HeapTest, AllocationDuringFinalization) | 3797 TEST(HeapTest, AllocationDuringFinalization) |
3834 { | 3798 { |
3835 HeapStats initialHeapSize; | 3799 clearOutOldGarbage(); |
3836 clearOutOldGarbage(&initialHeapSize); | |
3837 IntWrapper::s_destructorCalls = 0; | 3800 IntWrapper::s_destructorCalls = 0; |
3838 OneKiloByteObject::s_destructorCalls = 0; | 3801 OneKiloByteObject::s_destructorCalls = 0; |
3839 | 3802 |
3840 Persistent<IntWrapper> wrapper; | 3803 Persistent<IntWrapper> wrapper; |
3841 new FinalizationAllocator(&wrapper); | 3804 new FinalizationAllocator(&wrapper); |
3842 | 3805 |
3843 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3806 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3844 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3807 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
3845 // Check that the wrapper allocated during finalization is not | 3808 // Check that the wrapper allocated during finalization is not |
3846 // swept away and zapped later in the same sweeping phase. | 3809 // swept away and zapped later in the same sweeping phase. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3982 }; | 3945 }; |
3983 | 3946 |
3984 static const bool s_isMixinTrue = IsGarbageCollectedMixin<MultipleMixins>::value
; | 3947 static const bool s_isMixinTrue = IsGarbageCollectedMixin<MultipleMixins>::value
; |
3985 static const bool s_isMixinFalse = IsGarbageCollectedMixin<IntWrapper>::value; | 3948 static const bool s_isMixinFalse = IsGarbageCollectedMixin<IntWrapper>::value; |
3986 | 3949 |
3987 TEST(HeapTest, MultipleMixins) | 3950 TEST(HeapTest, MultipleMixins) |
3988 { | 3951 { |
3989 EXPECT_TRUE(s_isMixinTrue); | 3952 EXPECT_TRUE(s_isMixinTrue); |
3990 EXPECT_FALSE(s_isMixinFalse); | 3953 EXPECT_FALSE(s_isMixinFalse); |
3991 | 3954 |
3992 HeapStats initialHeapSize; | 3955 clearOutOldGarbage(); |
3993 clearOutOldGarbage(&initialHeapSize); | |
3994 IntWrapper::s_destructorCalls = 0; | 3956 IntWrapper::s_destructorCalls = 0; |
3995 MultipleMixins* obj = new MultipleMixins(); | 3957 MultipleMixins* obj = new MultipleMixins(); |
3996 { | 3958 { |
3997 Persistent<MixinA> a = obj; | 3959 Persistent<MixinA> a = obj; |
3998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3960 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
3999 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3961 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
4000 } | 3962 } |
4001 { | 3963 { |
4002 Persistent<MixinB> b = obj; | 3964 Persistent<MixinB> b = obj; |
4003 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 3965 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4138 TEST(HeapTest, SetWithCustomWeaknessHandling) | 4100 TEST(HeapTest, SetWithCustomWeaknessHandling) |
4139 { | 4101 { |
4140 setWithCustomWeaknessHandling<HeapHashSet<PairWithWeakHandling> >(); | 4102 setWithCustomWeaknessHandling<HeapHashSet<PairWithWeakHandling> >(); |
4141 setWithCustomWeaknessHandling<HeapLinkedHashSet<PairWithWeakHandling> >(); | 4103 setWithCustomWeaknessHandling<HeapLinkedHashSet<PairWithWeakHandling> >(); |
4142 } | 4104 } |
4143 | 4105 |
4144 TEST(HeapTest, MapWithCustomWeaknessHandling) | 4106 TEST(HeapTest, MapWithCustomWeaknessHandling) |
4145 { | 4107 { |
4146 typedef HeapHashMap<PairWithWeakHandling, RefPtr<OffHeapInt> > Map; | 4108 typedef HeapHashMap<PairWithWeakHandling, RefPtr<OffHeapInt> > Map; |
4147 typedef Map::iterator Iterator; | 4109 typedef Map::iterator Iterator; |
4148 HeapStats initialHeapSize; | 4110 clearOutOldGarbage(); |
4149 clearOutOldGarbage(&initialHeapSize); | |
4150 OffHeapInt::s_destructorCalls = 0; | 4111 OffHeapInt::s_destructorCalls = 0; |
4151 | 4112 |
4152 Persistent<Map> map1(new Map()); | 4113 Persistent<Map> map1(new Map()); |
4153 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4114 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
4154 { | 4115 { |
4155 Map map2; | 4116 Map map2; |
4156 Map* map3 = new Map(); | 4117 Map* map3 = new Map(); |
4157 map2.add(PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(
1)), OffHeapInt::create(1001)); | 4118 map2.add(PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(
1)), OffHeapInt::create(1001)); |
4158 map3->add(PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create
(3)), OffHeapInt::create(1002)); | 4119 map3->add(PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create
(3)), OffHeapInt::create(1002)); |
4159 map1->add(PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create
(5)), OffHeapInt::create(1003)); | 4120 map1->add(PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create
(5)), OffHeapInt::create(1003)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4208 EXPECT_EQ(livingInt, i1->key.second); | 4169 EXPECT_EQ(livingInt, i1->key.second); |
4209 ++i1; | 4170 ++i1; |
4210 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); | 4171 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); |
4211 EXPECT_EQ(livingInt, i1->key.second); | 4172 EXPECT_EQ(livingInt, i1->key.second); |
4212 } | 4173 } |
4213 | 4174 |
4214 TEST(HeapTest, MapWithCustomWeaknessHandling2) | 4175 TEST(HeapTest, MapWithCustomWeaknessHandling2) |
4215 { | 4176 { |
4216 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map; | 4177 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map; |
4217 typedef Map::iterator Iterator; | 4178 typedef Map::iterator Iterator; |
4218 HeapStats initialHeapSize; | 4179 clearOutOldGarbage(); |
4219 clearOutOldGarbage(&initialHeapSize); | |
4220 OffHeapInt::s_destructorCalls = 0; | 4180 OffHeapInt::s_destructorCalls = 0; |
4221 | 4181 |
4222 Persistent<Map> map1(new Map()); | 4182 Persistent<Map> map1(new Map()); |
4223 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4183 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
4224 | 4184 |
4225 { | 4185 { |
4226 Map map2; | 4186 Map map2; |
4227 Map* map3 = new Map(); | 4187 Map* map3 = new Map(); |
4228 map2.add(OffHeapInt::create(1001), PairWithWeakHandling(IntWrapper::crea
te(0), IntWrapper::create(1))); | 4188 map2.add(OffHeapInt::create(1001), PairWithWeakHandling(IntWrapper::crea
te(0), IntWrapper::create(1))); |
4229 map3->add(OffHeapInt::create(1002), PairWithWeakHandling(IntWrapper::cre
ate(2), IntWrapper::create(3))); | 4189 map3->add(OffHeapInt::create(1002), PairWithWeakHandling(IntWrapper::cre
ate(2), IntWrapper::create(3))); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4353 // 1) We can't just override the HashTrait for the type since this would affect | 4313 // 1) We can't just override the HashTrait for the type since this would affect |
4354 // all collections that use this kind of weak set. Instead we have our own | 4314 // all collections that use this kind of weak set. Instead we have our own |
4355 // traits and use a map with custom traits for the value type. These traits | 4315 // traits and use a map with custom traits for the value type. These traits |
4356 // are the 5th template parameter, so we have to supply default values for | 4316 // are the 5th template parameter, so we have to supply default values for |
4357 // the 3rd and 4th template parameters | 4317 // the 3rd and 4th template parameters |
4358 // 2) We can't just inherit from WeakHandlingHashTraits, since that trait | 4318 // 2) We can't just inherit from WeakHandlingHashTraits, since that trait |
4359 // assumes we can add methods to the type, but we can't add methods to | 4319 // assumes we can add methods to the type, but we can't add methods to |
4360 // HeapHashSet. | 4320 // HeapHashSet. |
4361 TEST(HeapTest, RemoveEmptySets) | 4321 TEST(HeapTest, RemoveEmptySets) |
4362 { | 4322 { |
4363 HeapStats initialHeapSize; | 4323 clearOutOldGarbage(); |
4364 clearOutOldGarbage(&initialHeapSize); | |
4365 OffHeapInt::s_destructorCalls = 0; | 4324 OffHeapInt::s_destructorCalls = 0; |
4366 | 4325 |
4367 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4326 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
4368 | 4327 |
4369 typedef RefPtr<OffHeapInt> Key; | 4328 typedef RefPtr<OffHeapInt> Key; |
4370 typedef HeapHashMap<Key, WeakSet, WTF::DefaultHash<Key>::Hash, HashTraits<Ke
y>, EmptyClearingHashSetTraits> Map; | 4329 typedef HeapHashMap<Key, WeakSet, WTF::DefaultHash<Key>::Hash, HashTraits<Ke
y>, EmptyClearingHashSetTraits> Map; |
4371 Persistent<Map> map(new Map()); | 4330 Persistent<Map> map(new Map()); |
4372 map->add(OffHeapInt::create(1), WeakSet()); | 4331 map->add(OffHeapInt::create(1), WeakSet()); |
4373 { | 4332 { |
4374 WeakSet& set = map->begin()->value; | 4333 WeakSet& set = map->begin()->value; |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5390 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5349 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
5391 { | 5350 { |
5392 new NonNodeAllocatingNodeInDestructor(); | 5351 new NonNodeAllocatingNodeInDestructor(); |
5393 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5352 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
5394 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5353 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
5395 delete NonNodeAllocatingNodeInDestructor::s_node; | 5354 delete NonNodeAllocatingNodeInDestructor::s_node; |
5396 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5355 NonNodeAllocatingNodeInDestructor::s_node = 0; |
5397 } | 5356 } |
5398 | 5357 |
5399 } // namespace blink | 5358 } // namespace blink |
OLD | NEW |