Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: test/cctest/heap/test-heap.cc

Issue 2694063005: [HEAP] Remove SIMD 128 bit alignment from heap. (Closed)
Patch Set: Restore deleted bounds check in deserializer. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot/deserializer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 if (collector->sweeping_in_progress()) { 1862 if (collector->sweeping_in_progress()) {
1863 collector->EnsureSweepingCompleted(); 1863 collector->EnsureSweepingCompleted();
1864 } 1864 }
1865 CHECK_EQ(initial_size, static_cast<int>(heap->SizeOfObjects())); 1865 CHECK_EQ(initial_size, static_cast<int>(heap->SizeOfObjects()));
1866 } 1866 }
1867 1867
1868 1868
1869 TEST(TestAlignmentCalculations) { 1869 TEST(TestAlignmentCalculations) {
1870 // Maximum fill amounts are consistent. 1870 // Maximum fill amounts are consistent.
1871 int maximum_double_misalignment = kDoubleSize - kPointerSize; 1871 int maximum_double_misalignment = kDoubleSize - kPointerSize;
1872 int maximum_simd128_misalignment = kSimd128Size - kPointerSize;
1873 int max_word_fill = Heap::GetMaximumFillToAlign(kWordAligned); 1872 int max_word_fill = Heap::GetMaximumFillToAlign(kWordAligned);
1874 CHECK_EQ(0, max_word_fill); 1873 CHECK_EQ(0, max_word_fill);
1875 int max_double_fill = Heap::GetMaximumFillToAlign(kDoubleAligned); 1874 int max_double_fill = Heap::GetMaximumFillToAlign(kDoubleAligned);
1876 CHECK_EQ(maximum_double_misalignment, max_double_fill); 1875 CHECK_EQ(maximum_double_misalignment, max_double_fill);
1877 int max_double_unaligned_fill = Heap::GetMaximumFillToAlign(kDoubleUnaligned); 1876 int max_double_unaligned_fill = Heap::GetMaximumFillToAlign(kDoubleUnaligned);
1878 CHECK_EQ(maximum_double_misalignment, max_double_unaligned_fill); 1877 CHECK_EQ(maximum_double_misalignment, max_double_unaligned_fill);
1879 int max_simd128_unaligned_fill =
1880 Heap::GetMaximumFillToAlign(kSimd128Unaligned);
1881 CHECK_EQ(maximum_simd128_misalignment, max_simd128_unaligned_fill);
1882 1878
1883 Address base = static_cast<Address>(NULL); 1879 Address base = static_cast<Address>(NULL);
1884 int fill = 0; 1880 int fill = 0;
1885 1881
1886 // Word alignment never requires fill. 1882 // Word alignment never requires fill.
1887 fill = Heap::GetFillToAlign(base, kWordAligned); 1883 fill = Heap::GetFillToAlign(base, kWordAligned);
1888 CHECK_EQ(0, fill); 1884 CHECK_EQ(0, fill);
1889 fill = Heap::GetFillToAlign(base + kPointerSize, kWordAligned); 1885 fill = Heap::GetFillToAlign(base + kPointerSize, kWordAligned);
1890 CHECK_EQ(0, fill); 1886 CHECK_EQ(0, fill);
1891 1887
1892 // No fill is required when address is double aligned. 1888 // No fill is required when address is double aligned.
1893 fill = Heap::GetFillToAlign(base, kDoubleAligned); 1889 fill = Heap::GetFillToAlign(base, kDoubleAligned);
1894 CHECK_EQ(0, fill); 1890 CHECK_EQ(0, fill);
1895 // Fill is required if address is not double aligned. 1891 // Fill is required if address is not double aligned.
1896 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleAligned); 1892 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleAligned);
1897 CHECK_EQ(maximum_double_misalignment, fill); 1893 CHECK_EQ(maximum_double_misalignment, fill);
1898 // kDoubleUnaligned has the opposite fill amounts. 1894 // kDoubleUnaligned has the opposite fill amounts.
1899 fill = Heap::GetFillToAlign(base, kDoubleUnaligned); 1895 fill = Heap::GetFillToAlign(base, kDoubleUnaligned);
1900 CHECK_EQ(maximum_double_misalignment, fill); 1896 CHECK_EQ(maximum_double_misalignment, fill);
1901 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleUnaligned); 1897 fill = Heap::GetFillToAlign(base + kPointerSize, kDoubleUnaligned);
1902 CHECK_EQ(0, fill); 1898 CHECK_EQ(0, fill);
1903
1904 // 128 bit SIMD types have 2 or 4 possible alignments, depending on platform.
1905 fill = Heap::GetFillToAlign(base, kSimd128Unaligned);
1906 CHECK_EQ((3 * kPointerSize) & kSimd128AlignmentMask, fill);
1907 fill = Heap::GetFillToAlign(base + kPointerSize, kSimd128Unaligned);
1908 CHECK_EQ((2 * kPointerSize) & kSimd128AlignmentMask, fill);
1909 fill = Heap::GetFillToAlign(base + 2 * kPointerSize, kSimd128Unaligned);
1910 CHECK_EQ(kPointerSize, fill);
1911 fill = Heap::GetFillToAlign(base + 3 * kPointerSize, kSimd128Unaligned);
1912 CHECK_EQ(0, fill);
1913 } 1899 }
1914 1900
1915 1901
1916 static HeapObject* NewSpaceAllocateAligned(int size, 1902 static HeapObject* NewSpaceAllocateAligned(int size,
1917 AllocationAlignment alignment) { 1903 AllocationAlignment alignment) {
1918 Heap* heap = CcTest::heap(); 1904 Heap* heap = CcTest::heap();
1919 AllocationResult allocation = 1905 AllocationResult allocation =
1920 heap->new_space()->AllocateRawAligned(size, alignment); 1906 heap->new_space()->AllocateRawAligned(size, alignment);
1921 HeapObject* obj = NULL; 1907 HeapObject* obj = NULL;
1922 allocation.To(&obj); 1908 allocation.To(&obj);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 CHECK_EQ(kPointerSize, *top_addr - start); 1956 CHECK_EQ(kPointerSize, *top_addr - start);
1971 start = AlignNewSpace(kDoubleUnaligned, kPointerSize); 1957 start = AlignNewSpace(kDoubleUnaligned, kPointerSize);
1972 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); 1958 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned);
1973 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); 1959 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize));
1974 // There is a filler object before the object. 1960 // There is a filler object before the object.
1975 filler = HeapObject::FromAddress(start); 1961 filler = HeapObject::FromAddress(start);
1976 CHECK(obj != filler && filler->IsFiller() && 1962 CHECK(obj != filler && filler->IsFiller() &&
1977 filler->Size() == kPointerSize); 1963 filler->Size() == kPointerSize);
1978 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); 1964 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start);
1979 } 1965 }
1980
1981 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending
1982 // on platform.
1983 start = AlignNewSpace(kSimd128Unaligned, 0);
1984 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
1985 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
1986 // There is no filler.
1987 CHECK_EQ(kPointerSize, *top_addr - start);
1988 start = AlignNewSpace(kSimd128Unaligned, kPointerSize);
1989 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
1990 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
1991 // There is a filler object before the object.
1992 filler = HeapObject::FromAddress(start);
1993 CHECK(obj != filler && filler->IsFiller() &&
1994 filler->Size() == kSimd128Size - kPointerSize);
1995 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, *top_addr - start);
1996
1997 if (double_misalignment) {
1998 // Test the 2 other alignments possible on 32 bit platforms.
1999 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize);
2000 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2001 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2002 // There is a filler object before the object.
2003 filler = HeapObject::FromAddress(start);
2004 CHECK(obj != filler && filler->IsFiller() &&
2005 filler->Size() == 2 * kPointerSize);
2006 CHECK_EQ(kPointerSize + 2 * kPointerSize, *top_addr - start);
2007 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize);
2008 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2009 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2010 // There is a filler object before the object.
2011 filler = HeapObject::FromAddress(start);
2012 CHECK(obj != filler && filler->IsFiller() &&
2013 filler->Size() == kPointerSize);
2014 CHECK_EQ(kPointerSize + kPointerSize, *top_addr - start);
2015 }
2016 } 1966 }
2017 1967
2018 1968
2019 static HeapObject* OldSpaceAllocateAligned(int size, 1969 static HeapObject* OldSpaceAllocateAligned(int size,
2020 AllocationAlignment alignment) { 1970 AllocationAlignment alignment) {
2021 Heap* heap = CcTest::heap(); 1971 Heap* heap = CcTest::heap();
2022 AllocationResult allocation = 1972 AllocationResult allocation =
2023 heap->old_space()->AllocateRawAligned(size, alignment); 1973 heap->old_space()->AllocateRawAligned(size, alignment);
2024 HeapObject* obj = NULL; 1974 HeapObject* obj = NULL;
2025 allocation.To(&obj); 1975 allocation.To(&obj);
(...skipping 28 matching lines...) Expand all
2054 AllocationResult dummy = 2004 AllocationResult dummy =
2055 heap->old_space()->AllocateRawUnaligned(kPointerSize); 2005 heap->old_space()->AllocateRawUnaligned(kPointerSize);
2056 CHECK(!dummy.IsRetry()); 2006 CHECK(!dummy.IsRetry());
2057 heap->CreateFillerObjectAt(dummy.ToObjectChecked()->address(), kPointerSize, 2007 heap->CreateFillerObjectAt(dummy.ToObjectChecked()->address(), kPointerSize,
2058 ClearRecordedSlots::kNo); 2008 ClearRecordedSlots::kNo);
2059 2009
2060 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. 2010 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones.
2061 const intptr_t double_misalignment = kDoubleSize - kPointerSize; 2011 const intptr_t double_misalignment = kDoubleSize - kPointerSize;
2062 Address start; 2012 Address start;
2063 HeapObject* obj; 2013 HeapObject* obj;
2064 HeapObject* filler1; 2014 HeapObject* filler;
2065 HeapObject* filler2;
2066 if (double_misalignment) { 2015 if (double_misalignment) {
2067 start = AlignOldSpace(kDoubleAligned, 0); 2016 start = AlignOldSpace(kDoubleAligned, 0);
2068 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleAligned); 2017 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleAligned);
2069 // The object is aligned, and a filler object is created after. 2018 // The object is aligned, and a filler object is created after.
2070 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); 2019 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment));
2071 filler1 = HeapObject::FromAddress(start + kPointerSize); 2020 filler = HeapObject::FromAddress(start + kPointerSize);
2072 CHECK(obj != filler1 && filler1->IsFiller() && 2021 CHECK(obj != filler && filler->IsFiller() &&
2073 filler1->Size() == kPointerSize); 2022 filler->Size() == kPointerSize);
2074 // Try the opposite alignment case. 2023 // Try the opposite alignment case.
2075 start = AlignOldSpace(kDoubleAligned, kPointerSize); 2024 start = AlignOldSpace(kDoubleAligned, kPointerSize);
2076 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleAligned); 2025 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleAligned);
2077 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); 2026 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment));
2078 filler1 = HeapObject::FromAddress(start); 2027 filler = HeapObject::FromAddress(start);
2079 CHECK(obj != filler1); 2028 CHECK(obj != filler);
2080 CHECK(filler1->IsFiller()); 2029 CHECK(filler->IsFiller());
2081 CHECK(filler1->Size() == kPointerSize); 2030 CHECK(filler->Size() == kPointerSize);
2082 CHECK(obj != filler1 && filler1->IsFiller() && 2031 CHECK(obj != filler && filler->IsFiller() &&
2083 filler1->Size() == kPointerSize); 2032 filler->Size() == kPointerSize);
2084 2033
2085 // Similarly for kDoubleUnaligned. 2034 // Similarly for kDoubleUnaligned.
2086 start = AlignOldSpace(kDoubleUnaligned, 0); 2035 start = AlignOldSpace(kDoubleUnaligned, 0);
2087 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); 2036 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleUnaligned);
2088 // The object is aligned, and a filler object is created after. 2037 // The object is aligned, and a filler object is created after.
2089 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); 2038 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize));
2090 filler1 = HeapObject::FromAddress(start + kPointerSize); 2039 filler = HeapObject::FromAddress(start + kPointerSize);
2091 CHECK(obj != filler1 && filler1->IsFiller() && 2040 CHECK(obj != filler && filler->IsFiller() &&
2092 filler1->Size() == kPointerSize); 2041 filler->Size() == kPointerSize);
2093 // Try the opposite alignment case. 2042 // Try the opposite alignment case.
2094 start = AlignOldSpace(kDoubleUnaligned, kPointerSize); 2043 start = AlignOldSpace(kDoubleUnaligned, kPointerSize);
2095 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); 2044 obj = OldSpaceAllocateAligned(kPointerSize, kDoubleUnaligned);
2096 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); 2045 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize));
2097 filler1 = HeapObject::FromAddress(start); 2046 filler = HeapObject::FromAddress(start);
2098 CHECK(obj != filler1 && filler1->IsFiller() && 2047 CHECK(obj != filler && filler->IsFiller() &&
2099 filler1->Size() == kPointerSize); 2048 filler->Size() == kPointerSize);
2100 }
2101
2102 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending
2103 // on platform.
2104 start = AlignOldSpace(kSimd128Unaligned, 0);
2105 obj = OldSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2106 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2107 // There is a filler object after the object.
2108 filler1 = HeapObject::FromAddress(start + kPointerSize);
2109 CHECK(obj != filler1 && filler1->IsFiller() &&
2110 filler1->Size() == kSimd128Size - kPointerSize);
2111 start = AlignOldSpace(kSimd128Unaligned, kPointerSize);
2112 obj = OldSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2113 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2114 // There is a filler object before the object.
2115 filler1 = HeapObject::FromAddress(start);
2116 CHECK(obj != filler1 && filler1->IsFiller() &&
2117 filler1->Size() == kSimd128Size - kPointerSize);
2118
2119 if (double_misalignment) {
2120 // Test the 2 other alignments possible on 32 bit platforms.
2121 start = AlignOldSpace(kSimd128Unaligned, 2 * kPointerSize);
2122 obj = OldSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2123 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2124 // There are filler objects before and after the object.
2125 filler1 = HeapObject::FromAddress(start);
2126 CHECK(obj != filler1 && filler1->IsFiller() &&
2127 filler1->Size() == 2 * kPointerSize);
2128 filler2 = HeapObject::FromAddress(start + 3 * kPointerSize);
2129 CHECK(obj != filler2 && filler2->IsFiller() &&
2130 filler2->Size() == kPointerSize);
2131 start = AlignOldSpace(kSimd128Unaligned, 3 * kPointerSize);
2132 obj = OldSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2133 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2134 // There are filler objects before and after the object.
2135 filler1 = HeapObject::FromAddress(start);
2136 CHECK(obj != filler1 && filler1->IsFiller() &&
2137 filler1->Size() == kPointerSize);
2138 filler2 = HeapObject::FromAddress(start + 2 * kPointerSize);
2139 CHECK(obj != filler2 && filler2->IsFiller() &&
2140 filler2->Size() == 2 * kPointerSize);
2141 } 2049 }
2142 } 2050 }
2143 2051
2144 2052
2145 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { 2053 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
2146 CcTest::InitializeVM(); 2054 CcTest::InitializeVM();
2147 HeapIterator iterator(CcTest::heap()); 2055 HeapIterator iterator(CcTest::heap());
2148 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects(); 2056 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects();
2149 intptr_t size_of_objects_2 = 0; 2057 intptr_t size_of_objects_2 = 0;
2150 for (HeapObject* obj = iterator.next(); 2058 for (HeapObject* obj = iterator.next();
(...skipping 4588 matching lines...) Expand 10 before | Expand all | Expand 10 after
6739 CHECK(!heap->code_space()->FirstPage()->Contains(code->address())); 6647 CHECK(!heap->code_space()->FirstPage()->Contains(code->address()));
6740 6648
6741 // Ensure it's not in large object space. 6649 // Ensure it's not in large object space.
6742 MemoryChunk* chunk = MemoryChunk::FromAddress(code->address()); 6650 MemoryChunk* chunk = MemoryChunk::FromAddress(code->address());
6743 CHECK(chunk->owner()->identity() != LO_SPACE); 6651 CHECK(chunk->owner()->identity() != LO_SPACE);
6744 CHECK(chunk->NeverEvacuate()); 6652 CHECK(chunk->NeverEvacuate());
6745 } 6653 }
6746 6654
6747 } // namespace internal 6655 } // namespace internal
6748 } // namespace v8 6656 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/deserializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698