| 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 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 clearOutOldGarbage(); | 1767 clearOutOldGarbage(); |
| 1768 size_t initialObjectPayloadSize = Heap::objectPayloadSizeForTesting(); | 1768 size_t initialObjectPayloadSize = Heap::objectPayloadSizeForTesting(); |
| 1769 { | 1769 { |
| 1770 size_t slack = 0; | 1770 size_t slack = 0; |
| 1771 | 1771 |
| 1772 // When the test starts there may already have been leaked some memory | 1772 // When the test starts there may already have been leaked some memory |
| 1773 // on the heap, so we establish a base line. | 1773 // on the heap, so we establish a base line. |
| 1774 size_t baseLevel = initialObjectPayloadSize; | 1774 size_t baseLevel = initialObjectPayloadSize; |
| 1775 bool testPagesAllocated = !baseLevel; | 1775 bool testPagesAllocated = !baseLevel; |
| 1776 if (testPagesAllocated) | 1776 if (testPagesAllocated) |
| 1777 EXPECT_EQ(Heap::allocatedSpace(), 0ul); | 1777 EXPECT_EQ(Heap::heapStats().allocatedSpace(), 0ul); |
| 1778 | 1778 |
| 1779 // This allocates objects on the general heap which should add a page of
memory. | 1779 // This allocates objects on the general heap which should add a page of
memory. |
| 1780 DynamicallySizedObject* alloc32 = DynamicallySizedObject::create(32); | 1780 DynamicallySizedObject* alloc32 = DynamicallySizedObject::create(32); |
| 1781 slack += 4; | 1781 slack += 4; |
| 1782 memset(alloc32, 40, 32); | 1782 memset(alloc32, 40, 32); |
| 1783 DynamicallySizedObject* alloc64 = DynamicallySizedObject::create(64); | 1783 DynamicallySizedObject* alloc64 = DynamicallySizedObject::create(64); |
| 1784 slack += 4; | 1784 slack += 4; |
| 1785 memset(alloc64, 27, 64); | 1785 memset(alloc64, 27, 64); |
| 1786 | 1786 |
| 1787 size_t total = 96; | 1787 size_t total = 96; |
| 1788 | 1788 |
| 1789 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); | 1789 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); |
| 1790 if (testPagesAllocated) | 1790 if (testPagesAllocated) |
| 1791 EXPECT_EQ(Heap::allocatedSpace(), blinkPageSize * 2); | 1791 EXPECT_EQ(Heap::heapStats().allocatedSpace(), blinkPageSize * 2); |
| 1792 | 1792 |
| 1793 EXPECT_EQ(alloc32->get(0), 40); | 1793 EXPECT_EQ(alloc32->get(0), 40); |
| 1794 EXPECT_EQ(alloc32->get(31), 40); | 1794 EXPECT_EQ(alloc32->get(31), 40); |
| 1795 EXPECT_EQ(alloc64->get(0), 27); | 1795 EXPECT_EQ(alloc64->get(0), 27); |
| 1796 EXPECT_EQ(alloc64->get(63), 27); | 1796 EXPECT_EQ(alloc64->get(63), 27); |
| 1797 | 1797 |
| 1798 conservativelyCollectGarbage(); | 1798 conservativelyCollectGarbage(); |
| 1799 | 1799 |
| 1800 EXPECT_EQ(alloc32->get(0), 40); | 1800 EXPECT_EQ(alloc32->get(0), 40); |
| 1801 EXPECT_EQ(alloc32->get(31), 40); | 1801 EXPECT_EQ(alloc32->get(31), 40); |
| 1802 EXPECT_EQ(alloc64->get(0), 27); | 1802 EXPECT_EQ(alloc64->get(0), 27); |
| 1803 EXPECT_EQ(alloc64->get(63), 27); | 1803 EXPECT_EQ(alloc64->get(63), 27); |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 clearOutOldGarbage(); | 1806 clearOutOldGarbage(); |
| 1807 size_t total = 0; | 1807 size_t total = 0; |
| 1808 size_t slack = 0; | 1808 size_t slack = 0; |
| 1809 size_t baseLevel = Heap::objectPayloadSizeForTesting(); | 1809 size_t baseLevel = Heap::objectPayloadSizeForTesting(); |
| 1810 bool testPagesAllocated = !baseLevel; | 1810 bool testPagesAllocated = !baseLevel; |
| 1811 if (testPagesAllocated) | 1811 if (testPagesAllocated) |
| 1812 EXPECT_EQ(Heap::allocatedSpace(), 0ul); | 1812 EXPECT_EQ(Heap::heapStats().allocatedSpace(), 0ul); |
| 1813 | 1813 |
| 1814 size_t big = 1008; | 1814 size_t big = 1008; |
| 1815 Persistent<DynamicallySizedObject> bigArea = DynamicallySizedObject::create(
big); | 1815 Persistent<DynamicallySizedObject> bigArea = DynamicallySizedObject::create(
big); |
| 1816 total += big; | 1816 total += big; |
| 1817 slack += 4; | 1817 slack += 4; |
| 1818 | 1818 |
| 1819 size_t persistentCount = 0; | 1819 size_t persistentCount = 0; |
| 1820 const size_t numPersistents = 100000; | 1820 const size_t numPersistents = 100000; |
| 1821 Persistent<DynamicallySizedObject>* persistents[numPersistents]; | 1821 Persistent<DynamicallySizedObject>* persistents[numPersistents]; |
| 1822 | 1822 |
| 1823 for (int i = 0; i < 1000; i++) { | 1823 for (int i = 0; i < 1000; i++) { |
| 1824 size_t size = 128 + i * 8; | 1824 size_t size = 128 + i * 8; |
| 1825 total += size; | 1825 total += size; |
| 1826 persistents[persistentCount++] = new Persistent<DynamicallySizedObject>(
DynamicallySizedObject::create(size)); | 1826 persistents[persistentCount++] = new Persistent<DynamicallySizedObject>(
DynamicallySizedObject::create(size)); |
| 1827 slack += 4; | 1827 slack += 4; |
| 1828 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); | 1828 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); |
| 1829 if (testPagesAllocated) | 1829 if (testPagesAllocated) |
| 1830 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); | 1830 EXPECT_EQ(0ul, Heap::heapStats().allocatedSpace() & (blinkPageSize -
1)); |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 { | 1833 { |
| 1834 DynamicallySizedObject* alloc32b(DynamicallySizedObject::create(32)); | 1834 DynamicallySizedObject* alloc32b(DynamicallySizedObject::create(32)); |
| 1835 slack += 4; | 1835 slack += 4; |
| 1836 memset(alloc32b, 40, 32); | 1836 memset(alloc32b, 40, 32); |
| 1837 DynamicallySizedObject* alloc64b(DynamicallySizedObject::create(64)); | 1837 DynamicallySizedObject* alloc64b(DynamicallySizedObject::create(64)); |
| 1838 slack += 4; | 1838 slack += 4; |
| 1839 memset(alloc64b, 27, 64); | 1839 memset(alloc64b, 27, 64); |
| 1840 EXPECT_TRUE(alloc32b != alloc64b); | 1840 EXPECT_TRUE(alloc32b != alloc64b); |
| 1841 | 1841 |
| 1842 total += 96; | 1842 total += 96; |
| 1843 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); | 1843 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), s
lack); |
| 1844 if (testPagesAllocated) | 1844 if (testPagesAllocated) |
| 1845 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); | 1845 EXPECT_EQ(0ul, Heap::heapStats().allocatedSpace() & (blinkPageSize -
1)); |
| 1846 } | 1846 } |
| 1847 | 1847 |
| 1848 clearOutOldGarbage(); | 1848 clearOutOldGarbage(); |
| 1849 total -= 96; | 1849 total -= 96; |
| 1850 slack -= 8; | 1850 slack -= 8; |
| 1851 if (testPagesAllocated) | 1851 if (testPagesAllocated) |
| 1852 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); | 1852 EXPECT_EQ(0ul, Heap::heapStats().allocatedSpace() & (blinkPageSize - 1))
; |
| 1853 | 1853 |
| 1854 // Clear the persistent, so that the big area will be garbage collected. | 1854 // Clear the persistent, so that the big area will be garbage collected. |
| 1855 bigArea.release(); | 1855 bigArea.release(); |
| 1856 clearOutOldGarbage(); | 1856 clearOutOldGarbage(); |
| 1857 | 1857 |
| 1858 total -= big; | 1858 total -= big; |
| 1859 slack -= 4; | 1859 slack -= 4; |
| 1860 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), slack
); | 1860 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), slack
); |
| 1861 if (testPagesAllocated) | 1861 if (testPagesAllocated) |
| 1862 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); | 1862 EXPECT_EQ(0ul, Heap::heapStats().allocatedSpace() & (blinkPageSize - 1))
; |
| 1863 | 1863 |
| 1864 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), slack
); | 1864 CheckWithSlack(baseLevel + total, Heap::objectPayloadSizeForTesting(), slack
); |
| 1865 if (testPagesAllocated) | 1865 if (testPagesAllocated) |
| 1866 EXPECT_EQ(0ul, Heap::allocatedSpace() & (blinkPageSize - 1)); | 1866 EXPECT_EQ(0ul, Heap::heapStats().allocatedSpace() & (blinkPageSize - 1))
; |
| 1867 | 1867 |
| 1868 for (size_t i = 0; i < persistentCount; i++) { | 1868 for (size_t i = 0; i < persistentCount; i++) { |
| 1869 delete persistents[i]; | 1869 delete persistents[i]; |
| 1870 persistents[i] = 0; | 1870 persistents[i] = 0; |
| 1871 } | 1871 } |
| 1872 | 1872 |
| 1873 uint8_t* address = reinterpret_cast<uint8_t*>(Heap::allocate<DynamicallySize
dObject>(100)); | 1873 uint8_t* address = reinterpret_cast<uint8_t*>(Heap::allocate<DynamicallySize
dObject>(100)); |
| 1874 for (int i = 0; i < 100; i++) | 1874 for (int i = 0; i < 100; i++) |
| 1875 address[i] = i; | 1875 address[i] = i; |
| 1876 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 100000)); | 1876 address = reinterpret_cast<uint8_t*>(Heap::reallocate<DynamicallySizedObject
>(address, 100000)); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 } | 2319 } |
| 2320 clearOutOldGarbage(); | 2320 clearOutOldGarbage(); |
| 2321 size_t afterFree = Heap::objectPayloadSizeForTesting(); | 2321 size_t afterFree = Heap::objectPayloadSizeForTesting(); |
| 2322 EXPECT_TRUE(initialObjectPayloadSize == afterFree); | 2322 EXPECT_TRUE(initialObjectPayloadSize == afterFree); |
| 2323 } | 2323 } |
| 2324 | 2324 |
| 2325 TEST(HeapTest, LargeHeapObjects) | 2325 TEST(HeapTest, LargeHeapObjects) |
| 2326 { | 2326 { |
| 2327 clearOutOldGarbage(); | 2327 clearOutOldGarbage(); |
| 2328 size_t initialObjectPayloadSize = Heap::objectPayloadSizeForTesting(); | 2328 size_t initialObjectPayloadSize = Heap::objectPayloadSizeForTesting(); |
| 2329 size_t initialAllocatedSpace = Heap::allocatedSpace(); | 2329 size_t initialAllocatedSpace = Heap::heapStats().allocatedSpace(); |
| 2330 IntWrapper::s_destructorCalls = 0; | 2330 IntWrapper::s_destructorCalls = 0; |
| 2331 LargeHeapObject::s_destructorCalls = 0; | 2331 LargeHeapObject::s_destructorCalls = 0; |
| 2332 { | 2332 { |
| 2333 int slack = 8; // LargeHeapObject points to an IntWrapper that is also a
llocated. | 2333 int slack = 8; // LargeHeapObject points to an IntWrapper that is also a
llocated. |
| 2334 Persistent<LargeHeapObject> object = LargeHeapObject::create(); | 2334 Persistent<LargeHeapObject> object = LargeHeapObject::create(); |
| 2335 ASSERT(ThreadState::current()->findPageFromAddress(object)); | 2335 ASSERT(ThreadState::current()->findPageFromAddress(object)); |
| 2336 ASSERT(ThreadState::current()->findPageFromAddress(reinterpret_cast<char
*>(object.get()) + sizeof(LargeHeapObject) - 1)); | 2336 ASSERT(ThreadState::current()->findPageFromAddress(reinterpret_cast<char
*>(object.get()) + sizeof(LargeHeapObject) - 1)); |
| 2337 clearOutOldGarbage(); | 2337 clearOutOldGarbage(); |
| 2338 size_t afterAllocation = Heap::allocatedSpace(); | 2338 size_t afterAllocation = Heap::heapStats().allocatedSpace(); |
| 2339 { | 2339 { |
| 2340 object->set(0, 'a'); | 2340 object->set(0, 'a'); |
| 2341 EXPECT_EQ('a', object->get(0)); | 2341 EXPECT_EQ('a', object->get(0)); |
| 2342 object->set(object->length() - 1, 'b'); | 2342 object->set(object->length() - 1, 'b'); |
| 2343 EXPECT_EQ('b', object->get(object->length() - 1)); | 2343 EXPECT_EQ('b', object->get(object->length() - 1)); |
| 2344 size_t expectedLargeHeapObjectPayloadSize = Heap::allocationSizeFrom
Size(sizeof(LargeHeapObject)); | 2344 size_t expectedLargeHeapObjectPayloadSize = Heap::allocationSizeFrom
Size(sizeof(LargeHeapObject)); |
| 2345 size_t expectedObjectPayloadSize = expectedLargeHeapObjectPayloadSiz
e + sizeof(IntWrapper); | 2345 size_t expectedObjectPayloadSize = expectedLargeHeapObjectPayloadSiz
e + sizeof(IntWrapper); |
| 2346 size_t actualObjectPayloadSize = Heap::objectPayloadSizeForTesting()
- initialObjectPayloadSize; | 2346 size_t actualObjectPayloadSize = Heap::objectPayloadSizeForTesting()
- initialObjectPayloadSize; |
| 2347 CheckWithSlack(expectedObjectPayloadSize, actualObjectPayloadSize, s
lack); | 2347 CheckWithSlack(expectedObjectPayloadSize, actualObjectPayloadSize, s
lack); |
| 2348 // There is probably space for the IntWrapper in a heap page without | 2348 // There is probably space for the IntWrapper in a heap page without |
| 2349 // allocating extra pages. However, the IntWrapper allocation might
cause | 2349 // allocating extra pages. However, the IntWrapper allocation might
cause |
| 2350 // the addition of a heap page. | 2350 // the addition of a heap page. |
| 2351 size_t largeObjectAllocationSize = sizeof(LargeObjectPage) + expecte
dLargeHeapObjectPayloadSize; | 2351 size_t largeObjectAllocationSize = sizeof(LargeObjectPage) + expecte
dLargeHeapObjectPayloadSize; |
| 2352 size_t allocatedSpaceLowerBound = initialAllocatedSpace + largeObjec
tAllocationSize; | 2352 size_t allocatedSpaceLowerBound = initialAllocatedSpace + largeObjec
tAllocationSize; |
| 2353 size_t allocatedSpaceUpperBound = allocatedSpaceLowerBound + slack +
blinkPageSize; | 2353 size_t allocatedSpaceUpperBound = allocatedSpaceLowerBound + slack +
blinkPageSize; |
| 2354 EXPECT_LE(allocatedSpaceLowerBound, afterAllocation); | 2354 EXPECT_LE(allocatedSpaceLowerBound, afterAllocation); |
| 2355 EXPECT_LE(afterAllocation, allocatedSpaceUpperBound); | 2355 EXPECT_LE(afterAllocation, allocatedSpaceUpperBound); |
| 2356 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 2356 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
| 2357 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | 2357 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 2358 for (int i = 0; i < 10; i++) | 2358 for (int i = 0; i < 10; i++) |
| 2359 object = LargeHeapObject::create(); | 2359 object = LargeHeapObject::create(); |
| 2360 } | 2360 } |
| 2361 clearOutOldGarbage(); | 2361 clearOutOldGarbage(); |
| 2362 EXPECT_TRUE(Heap::allocatedSpace() == afterAllocation); | 2362 EXPECT_TRUE(Heap::heapStats().allocatedSpace() == afterAllocation); |
| 2363 EXPECT_EQ(10, IntWrapper::s_destructorCalls); | 2363 EXPECT_EQ(10, IntWrapper::s_destructorCalls); |
| 2364 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); | 2364 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); |
| 2365 } | 2365 } |
| 2366 clearOutOldGarbage(); | 2366 clearOutOldGarbage(); |
| 2367 EXPECT_TRUE(initialObjectPayloadSize == Heap::objectPayloadSizeForTesting())
; | 2367 EXPECT_TRUE(initialObjectPayloadSize == Heap::objectPayloadSizeForTesting())
; |
| 2368 EXPECT_TRUE(initialAllocatedSpace == Heap::allocatedSpace()); | 2368 EXPECT_TRUE(initialAllocatedSpace == Heap::heapStats().allocatedSpace()); |
| 2369 EXPECT_EQ(11, IntWrapper::s_destructorCalls); | 2369 EXPECT_EQ(11, IntWrapper::s_destructorCalls); |
| 2370 EXPECT_EQ(11, LargeHeapObject::s_destructorCalls); | 2370 EXPECT_EQ(11, LargeHeapObject::s_destructorCalls); |
| 2371 preciselyCollectGarbage(); | 2371 preciselyCollectGarbage(); |
| 2372 } | 2372 } |
| 2373 | 2373 |
| 2374 typedef std::pair<Member<IntWrapper>, int> PairWrappedUnwrapped; | 2374 typedef std::pair<Member<IntWrapper>, int> PairWrappedUnwrapped; |
| 2375 typedef std::pair<int, Member<IntWrapper>> PairUnwrappedWrapped; | 2375 typedef std::pair<int, Member<IntWrapper>> PairUnwrappedWrapped; |
| 2376 typedef std::pair<WeakMember<IntWrapper>, Member<IntWrapper>> PairWeakStrong; | 2376 typedef std::pair<WeakMember<IntWrapper>, Member<IntWrapper>> PairWeakStrong; |
| 2377 typedef std::pair<Member<IntWrapper>, WeakMember<IntWrapper>> PairStrongWeak; | 2377 typedef std::pair<Member<IntWrapper>, WeakMember<IntWrapper>> PairStrongWeak; |
| 2378 typedef std::pair<WeakMember<IntWrapper>, int> PairWeakUnwrapped; | 2378 typedef std::pair<WeakMember<IntWrapper>, int> PairWeakUnwrapped; |
| (...skipping 4104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6483 EXPECT_EQ(1u, vector2.size()); | 6483 EXPECT_EQ(1u, vector2.size()); |
| 6484 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables | 6484 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables |
| 6485 // Vector<>s with inline capacity, remove. | 6485 // Vector<>s with inline capacity, remove. |
| 6486 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) | 6486 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
| 6487 EXPECT_EQ(16u, vector1.capacity()); | 6487 EXPECT_EQ(16u, vector1.capacity()); |
| 6488 EXPECT_EQ(16u, vector2.capacity()); | 6488 EXPECT_EQ(16u, vector2.capacity()); |
| 6489 #endif | 6489 #endif |
| 6490 } | 6490 } |
| 6491 | 6491 |
| 6492 } // namespace blink | 6492 } // namespace blink |
| OLD | NEW |