OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1777 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1777 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); |
1778 | 1778 |
1779 // Waiting for sweeper threads should not change heap size. | 1779 // Waiting for sweeper threads should not change heap size. |
1780 if (collector->sweeping_in_progress()) { | 1780 if (collector->sweeping_in_progress()) { |
1781 collector->EnsureSweepingCompleted(); | 1781 collector->EnsureSweepingCompleted(); |
1782 } | 1782 } |
1783 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1783 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); |
1784 } | 1784 } |
1785 | 1785 |
1786 | 1786 |
1787 TEST(TestAlignmentCalculations) { | |
1788 // Maximum fill amounts should be consistent. | |
1789 int maximum_double_misalignment = kDoubleSize - kPointerSize; | |
1790 int max_word_fill = Heap::GetMaximumFillToAlign(kWordAligned); | |
1791 CHECK_EQ(0, max_word_fill); | |
1792 int max_double_fill = Heap::GetMaximumFillToAlign(kDoubleAligned); | |
1793 CHECK_EQ(maximum_double_misalignment, max_double_fill); | |
1794 int max_double_unaligned_fill = Heap::GetMaximumFillToAlign(kDoubleUnaligned); | |
1795 CHECK_EQ(maximum_double_misalignment, max_double_unaligned_fill); | |
1796 | |
1797 Address base = reinterpret_cast<Address>(NULL); | |
1798 int fill = 0; | |
1799 | |
1800 // Word alignment never requires fill. | |
1801 fill = Heap::GetFillToAlign(base, kWordAligned); | |
1802 CHECK_EQ(0, fill); | |
1803 fill = Heap::GetFillToAlign(base + kPointerSize, kWordAligned); | |
1804 CHECK_EQ(0, fill); | |
1805 | |
1806 // No fill is required when address is double aligned. | |
1807 fill = Heap::GetFillToAlign(base, kDoubleAligned); | |
1808 CHECK_EQ(0, fill); | |
1809 // Fill is required if address is not double aligned. | |
1810 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleAligned); | |
1811 CHECK_EQ(maximum_double_misalignment, fill); | |
1812 // kDoubleUnaligned has the opposite fill amounts. | |
1813 fill = Heap::GetFillToAlign(base, kDoubleUnaligned); | |
1814 CHECK_EQ(maximum_double_misalignment, fill); | |
1815 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleUnaligned); | |
1816 CHECK_EQ(0, fill); | |
1817 } | |
1818 | |
1819 | |
1820 static HeapObject* AllocateAligned(int size, AllocationAlignment alignment) { | |
1821 Heap* heap = CcTest::heap(); | |
1822 AllocationResult allocation = | |
1823 heap->new_space()->AllocateRawAligned(size, alignment); | |
1824 HeapObject* obj = NULL; | |
1825 allocation.To(&obj); | |
1826 heap->CreateFillerObjectAt(obj->address(), size); | |
1827 return obj; | |
1828 } | |
1829 | |
1830 | |
1831 TEST(TestAlignedAllocation) { | |
1832 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | |
1833 const intptr_t double_misalignment = kDoubleSize - kPointerSize; | |
1834 if (double_misalignment) { | |
1835 // Allocate a pointer sized object that must be double aligned. | |
1836 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); | |
1837 Address start = *top_addr; | |
1838 HeapObject* obj1 = AllocateAligned(kPointerSize, kDoubleAligned); | |
1839 CHECK(IsAddressAligned(obj1->address(), kDoubleAlignment, 0)); | |
1840 // Allocate a second pointer sized object. These two allocations should | |
1841 // cause exactly one filler object to be created. | |
Hannes Payer (out of office)
2015/05/27 14:12:45
Let's also check if the filler is there.
bbudge
2015/05/28 09:28:33
Done.
| |
1842 HeapObject* obj2 = AllocateAligned(kPointerSize, kDoubleAligned); | |
1843 CHECK(IsAddressAligned(obj2->address(), kDoubleAlignment, 0)); | |
1844 CHECK_EQ(2 * kPointerSize + double_misalignment, *top_addr - start); | |
1845 | |
1846 // Similarly for kDoubleUnaligned. | |
1847 start = *top_addr; | |
1848 obj1 = AllocateAligned(kPointerSize, kDoubleUnaligned); | |
1849 CHECK(IsAddressAligned(obj1->address(), kDoubleAlignment, kPointerSize)); | |
Hannes Payer (out of office)
2015/05/27 14:12:45
This address should not be double aligned.
bbudge
2015/05/28 09:28:33
address + offset is aligned
(confusing, I'm not a
| |
1850 obj2 = AllocateAligned(kPointerSize, kDoubleUnaligned); | |
1851 CHECK(IsAddressAligned(obj2->address(), kDoubleAlignment, kPointerSize)); | |
1852 CHECK_EQ(2 * kPointerSize + double_misalignment, *top_addr - start); | |
1853 } | |
1854 } | |
1855 | |
1856 | |
1857 static HeapObject* AllocateUnalignedAndFill(int size, int allocated, | |
1858 AllocationAlignment alignment) { | |
1859 Heap* heap = CcTest::heap(); | |
1860 AllocationResult allocation = | |
1861 heap->new_space()->AllocateRawUnaligned(allocated); | |
1862 HeapObject* obj = NULL; | |
1863 allocation.To(&obj); | |
1864 obj = heap->AlignWithFiller(obj, kPointerSize, allocated, kDoubleAligned); | |
1865 heap->CreateFillerObjectAt(obj->address(), size); | |
1866 return obj; | |
1867 } | |
1868 | |
1869 | |
1870 TEST(TestAlignedOverAllocation) { | |
1871 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | |
1872 const intptr_t double_misalignment = kDoubleSize - kPointerSize; | |
1873 if (double_misalignment) { | |
1874 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); | |
1875 Address start = *top_addr; | |
1876 HeapObject* obj1 = AllocateUnalignedAndFill( | |
Hannes Payer (out of office)
2015/05/27 14:12:45
Here, I would rather test the free-list allocation
bbudge
2015/05/28 09:28:33
Done.
| |
1877 kPointerSize, kPointerSize + double_misalignment, kDoubleAligned); | |
1878 CHECK(IsAddressAligned(obj1->address(), kDoubleAlignment, 0)); | |
1879 CHECK((start == obj1->address()) || | |
1880 (start == obj1->address() + double_misalignment)); | |
1881 } | |
1882 } | |
1883 | |
1884 | |
1787 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1885 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
1788 CcTest::InitializeVM(); | 1886 CcTest::InitializeVM(); |
1789 HeapIterator iterator(CcTest::heap()); | 1887 HeapIterator iterator(CcTest::heap()); |
1790 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects(); | 1888 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects(); |
1791 intptr_t size_of_objects_2 = 0; | 1889 intptr_t size_of_objects_2 = 0; |
1792 for (HeapObject* obj = iterator.next(); | 1890 for (HeapObject* obj = iterator.next(); |
1793 obj != NULL; | 1891 obj != NULL; |
1794 obj = iterator.next()) { | 1892 obj = iterator.next()) { |
1795 if (!obj->IsFreeSpace()) { | 1893 if (!obj->IsFreeSpace()) { |
1796 size_of_objects_2 += obj->Size(); | 1894 size_of_objects_2 += obj->Size(); |
(...skipping 3754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5551 size_t counter2 = 2000; | 5649 size_t counter2 = 2000; |
5552 tracer->SampleNewSpaceAllocation(time2, counter2); | 5650 tracer->SampleNewSpaceAllocation(time2, counter2); |
5553 size_t bytes = tracer->NewSpaceAllocatedBytesInLast(1000); | 5651 size_t bytes = tracer->NewSpaceAllocatedBytesInLast(1000); |
5554 CHECK_EQ(10000, bytes); | 5652 CHECK_EQ(10000, bytes); |
5555 int time3 = 1000; | 5653 int time3 = 1000; |
5556 size_t counter3 = 30000; | 5654 size_t counter3 = 30000; |
5557 tracer->SampleNewSpaceAllocation(time3, counter3); | 5655 tracer->SampleNewSpaceAllocation(time3, counter3); |
5558 bytes = tracer->NewSpaceAllocatedBytesInLast(100); | 5656 bytes = tracer->NewSpaceAllocatedBytesInLast(100); |
5559 CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes); | 5657 CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes); |
5560 } | 5658 } |
OLD | NEW |