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 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 heap->new_space()->AllocateRawAligned(size, alignment); | 2058 heap->new_space()->AllocateRawAligned(size, alignment); |
2059 HeapObject* obj = NULL; | 2059 HeapObject* obj = NULL; |
2060 allocation.To(&obj); | 2060 allocation.To(&obj); |
2061 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2061 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); |
2062 return obj; | 2062 return obj; |
2063 } | 2063 } |
2064 | 2064 |
2065 | 2065 |
2066 // Get new space allocation into the desired alignment. | 2066 // Get new space allocation into the desired alignment. |
2067 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { | 2067 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { |
2068 Address top = CcTest::heap()->new_space()->top(); | 2068 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); |
2069 int fill = Heap::GetFillToAlign(top, alignment); | 2069 int fill = Heap::GetFillToAlign(*top_addr, alignment); |
2070 if (fill) { | 2070 if (fill) { |
2071 NewSpaceAllocateAligned(fill + offset, kWordAligned); | 2071 NewSpaceAllocateAligned(fill + offset, kWordAligned); |
2072 } | 2072 } |
2073 return CcTest::heap()->new_space()->top(); | 2073 return *top_addr; |
2074 } | 2074 } |
2075 | 2075 |
2076 | 2076 |
2077 TEST(TestAlignedAllocation) { | 2077 TEST(TestAlignedAllocation) { |
2078 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2078 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. |
2079 const intptr_t double_misalignment = kDoubleSize - kPointerSize; | 2079 const intptr_t double_misalignment = kDoubleSize - kPointerSize; |
| 2080 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); |
2080 Address start; | 2081 Address start; |
2081 HeapObject* obj; | 2082 HeapObject* obj; |
2082 HeapObject* filler; | 2083 HeapObject* filler; |
2083 if (double_misalignment) { | 2084 if (double_misalignment) { |
2084 // Allocate a pointer sized object that must be double aligned at an | 2085 // Allocate a pointer sized object that must be double aligned at an |
2085 // aligned address. | 2086 // aligned address. |
2086 start = AlignNewSpace(kDoubleAligned, 0); | 2087 start = AlignNewSpace(kDoubleAligned, 0); |
2087 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2088 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); |
2088 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2089 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); |
2089 // There is no filler. | 2090 // There is no filler. |
2090 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 2091 CHECK_EQ(kPointerSize, *top_addr - start); |
2091 | 2092 |
2092 // Allocate a second pointer sized object that must be double aligned at an | 2093 // Allocate a second pointer sized object that must be double aligned at an |
2093 // unaligned address. | 2094 // unaligned address. |
2094 start = AlignNewSpace(kDoubleAligned, kPointerSize); | 2095 start = AlignNewSpace(kDoubleAligned, kPointerSize); |
2095 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2096 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); |
2096 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2097 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); |
2097 // There is a filler object before the object. | 2098 // There is a filler object before the object. |
2098 filler = HeapObject::FromAddress(start); | 2099 filler = HeapObject::FromAddress(start); |
2099 CHECK(obj != filler && filler->IsFiller() && | 2100 CHECK(obj != filler && filler->IsFiller() && |
2100 filler->Size() == kPointerSize); | 2101 filler->Size() == kPointerSize); |
2101 CHECK_EQ(kPointerSize + double_misalignment, | 2102 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); |
2102 CcTest::heap()->new_space()->top() - start); | |
2103 | 2103 |
2104 // Similarly for kDoubleUnaligned. | 2104 // Similarly for kDoubleUnaligned. |
2105 start = AlignNewSpace(kDoubleUnaligned, 0); | 2105 start = AlignNewSpace(kDoubleUnaligned, 0); |
2106 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2106 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); |
2107 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2107 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); |
2108 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 2108 CHECK_EQ(kPointerSize, *top_addr - start); |
2109 start = AlignNewSpace(kDoubleUnaligned, kPointerSize); | 2109 start = AlignNewSpace(kDoubleUnaligned, kPointerSize); |
2110 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2110 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); |
2111 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2111 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); |
2112 // There is a filler object before the object. | 2112 // There is a filler object before the object. |
2113 filler = HeapObject::FromAddress(start); | 2113 filler = HeapObject::FromAddress(start); |
2114 CHECK(obj != filler && filler->IsFiller() && | 2114 CHECK(obj != filler && filler->IsFiller() && |
2115 filler->Size() == kPointerSize); | 2115 filler->Size() == kPointerSize); |
2116 CHECK_EQ(kPointerSize + double_misalignment, | 2116 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); |
2117 CcTest::heap()->new_space()->top() - start); | |
2118 } | 2117 } |
2119 | 2118 |
2120 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending | 2119 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending |
2121 // on platform. | 2120 // on platform. |
2122 start = AlignNewSpace(kSimd128Unaligned, 0); | 2121 start = AlignNewSpace(kSimd128Unaligned, 0); |
2123 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2122 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2124 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2123 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2125 // There is no filler. | 2124 // There is no filler. |
2126 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 2125 CHECK_EQ(kPointerSize, *top_addr - start); |
2127 start = AlignNewSpace(kSimd128Unaligned, kPointerSize); | 2126 start = AlignNewSpace(kSimd128Unaligned, kPointerSize); |
2128 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2127 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2129 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2128 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2130 // There is a filler object before the object. | 2129 // There is a filler object before the object. |
2131 filler = HeapObject::FromAddress(start); | 2130 filler = HeapObject::FromAddress(start); |
2132 CHECK(obj != filler && filler->IsFiller() && | 2131 CHECK(obj != filler && filler->IsFiller() && |
2133 filler->Size() == kSimd128Size - kPointerSize); | 2132 filler->Size() == kSimd128Size - kPointerSize); |
2134 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, | 2133 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, *top_addr - start); |
2135 CcTest::heap()->new_space()->top() - start); | |
2136 | 2134 |
2137 if (double_misalignment) { | 2135 if (double_misalignment) { |
2138 // Test the 2 other alignments possible on 32 bit platforms. | 2136 // Test the 2 other alignments possible on 32 bit platforms. |
2139 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); | 2137 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); |
2140 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2138 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2141 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2139 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2142 // There is a filler object before the object. | 2140 // There is a filler object before the object. |
2143 filler = HeapObject::FromAddress(start); | 2141 filler = HeapObject::FromAddress(start); |
2144 CHECK(obj != filler && filler->IsFiller() && | 2142 CHECK(obj != filler && filler->IsFiller() && |
2145 filler->Size() == 2 * kPointerSize); | 2143 filler->Size() == 2 * kPointerSize); |
2146 CHECK_EQ(kPointerSize + 2 * kPointerSize, | 2144 CHECK_EQ(kPointerSize + 2 * kPointerSize, *top_addr - start); |
2147 CcTest::heap()->new_space()->top() - start); | |
2148 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); | 2145 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); |
2149 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2146 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2150 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2147 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2151 // There is a filler object before the object. | 2148 // There is a filler object before the object. |
2152 filler = HeapObject::FromAddress(start); | 2149 filler = HeapObject::FromAddress(start); |
2153 CHECK(obj != filler && filler->IsFiller() && | 2150 CHECK(obj != filler && filler->IsFiller() && |
2154 filler->Size() == kPointerSize); | 2151 filler->Size() == kPointerSize); |
2155 CHECK_EQ(kPointerSize + kPointerSize, | 2152 CHECK_EQ(kPointerSize + kPointerSize, *top_addr - start); |
2156 CcTest::heap()->new_space()->top() - start); | |
2157 } | 2153 } |
2158 } | 2154 } |
2159 | 2155 |
2160 | 2156 |
2161 static HeapObject* OldSpaceAllocateAligned(int size, | 2157 static HeapObject* OldSpaceAllocateAligned(int size, |
2162 AllocationAlignment alignment) { | 2158 AllocationAlignment alignment) { |
2163 Heap* heap = CcTest::heap(); | 2159 Heap* heap = CcTest::heap(); |
2164 AllocationResult allocation = | 2160 AllocationResult allocation = |
2165 heap->old_space()->AllocateRawAligned(size, alignment); | 2161 heap->old_space()->AllocateRawAligned(size, alignment); |
2166 HeapObject* obj = NULL; | 2162 HeapObject* obj = NULL; |
2167 allocation.To(&obj); | 2163 allocation.To(&obj); |
2168 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2164 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); |
2169 return obj; | 2165 return obj; |
2170 } | 2166 } |
2171 | 2167 |
2172 | 2168 |
2173 // Get old space allocation into the desired alignment. | 2169 // Get old space allocation into the desired alignment. |
2174 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { | 2170 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { |
2175 Address top = CcTest::heap()->old_space()->top(); | 2171 Address* top_addr = CcTest::heap()->old_space()->allocation_top_address(); |
2176 int fill = Heap::GetFillToAlign(top, alignment); | 2172 int fill = Heap::GetFillToAlign(*top_addr, alignment); |
2177 int allocation = fill + offset; | 2173 int allocation = fill + offset; |
2178 if (allocation) { | 2174 if (allocation) { |
2179 OldSpaceAllocateAligned(allocation, kWordAligned); | 2175 OldSpaceAllocateAligned(allocation, kWordAligned); |
2180 } | 2176 } |
2181 top = CcTest::heap()->old_space()->top(); | 2177 Address top = *top_addr; |
2182 // Now force the remaining allocation onto the free list. | 2178 // Now force the remaining allocation onto the free list. |
2183 CcTest::heap()->old_space()->EmptyAllocationInfo(); | 2179 CcTest::heap()->old_space()->EmptyAllocationInfo(); |
2184 return top; | 2180 return top; |
2185 } | 2181 } |
2186 | 2182 |
2187 | 2183 |
2188 // Test the case where allocation must be done from the free list, so filler | 2184 // Test the case where allocation must be done from the free list, so filler |
2189 // may precede or follow the object. | 2185 // may precede or follow the object. |
2190 TEST(TestAlignedOverAllocation) { | 2186 TEST(TestAlignedOverAllocation) { |
2191 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2187 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. |
(...skipping 4567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6759 CHECK(marking->IsComplete()); | 6755 CHECK(marking->IsComplete()); |
6760 intptr_t size_before = heap->SizeOfObjects(); | 6756 intptr_t size_before = heap->SizeOfObjects(); |
6761 CcTest::heap()->CollectAllGarbage(); | 6757 CcTest::heap()->CollectAllGarbage(); |
6762 intptr_t size_after = heap->SizeOfObjects(); | 6758 intptr_t size_after = heap->SizeOfObjects(); |
6763 // Live size does not increase after garbage collection. | 6759 // Live size does not increase after garbage collection. |
6764 CHECK_LE(size_after, size_before); | 6760 CHECK_LE(size_after, size_before); |
6765 } | 6761 } |
6766 | 6762 |
6767 } // namespace internal | 6763 } // namespace internal |
6768 } // namespace v8 | 6764 } // namespace v8 |
OLD | NEW |