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 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 heap->new_space()->AllocateRawAligned(size, alignment); | 2059 heap->new_space()->AllocateRawAligned(size, alignment); |
2060 HeapObject* obj = NULL; | 2060 HeapObject* obj = NULL; |
2061 allocation.To(&obj); | 2061 allocation.To(&obj); |
2062 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2062 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); |
2063 return obj; | 2063 return obj; |
2064 } | 2064 } |
2065 | 2065 |
2066 | 2066 |
2067 // Get new space allocation into the desired alignment. | 2067 // Get new space allocation into the desired alignment. |
2068 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { | 2068 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { |
2069 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); | 2069 Address top = CcTest::heap()->new_space()->top(); |
2070 int fill = Heap::GetFillToAlign(*top_addr, alignment); | 2070 int fill = Heap::GetFillToAlign(top, alignment); |
2071 if (fill) { | 2071 if (fill) { |
2072 NewSpaceAllocateAligned(fill + offset, kWordAligned); | 2072 NewSpaceAllocateAligned(fill + offset, kWordAligned); |
2073 } | 2073 } |
2074 return *top_addr; | 2074 return CcTest::heap()->new_space()->top(); |
2075 } | 2075 } |
2076 | 2076 |
2077 | 2077 |
2078 TEST(TestAlignedAllocation) { | 2078 TEST(TestAlignedAllocation) { |
2079 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2079 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. |
2080 const intptr_t double_misalignment = kDoubleSize - kPointerSize; | 2080 const intptr_t double_misalignment = kDoubleSize - kPointerSize; |
2081 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); | |
2082 Address start; | 2081 Address start; |
2083 HeapObject* obj; | 2082 HeapObject* obj; |
2084 HeapObject* filler; | 2083 HeapObject* filler; |
2085 if (double_misalignment) { | 2084 if (double_misalignment) { |
2086 // 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 |
2087 // aligned address. | 2086 // aligned address. |
2088 start = AlignNewSpace(kDoubleAligned, 0); | 2087 start = AlignNewSpace(kDoubleAligned, 0); |
2089 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2088 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); |
2090 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2089 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); |
2091 // There is no filler. | 2090 // There is no filler. |
2092 CHECK_EQ(kPointerSize, *top_addr - start); | 2091 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); |
2093 | 2092 |
2094 // 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 |
2095 // unaligned address. | 2094 // unaligned address. |
2096 start = AlignNewSpace(kDoubleAligned, kPointerSize); | 2095 start = AlignNewSpace(kDoubleAligned, kPointerSize); |
2097 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2096 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); |
2098 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2097 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); |
2099 // There is a filler object before the object. | 2098 // There is a filler object before the object. |
2100 filler = HeapObject::FromAddress(start); | 2099 filler = HeapObject::FromAddress(start); |
2101 CHECK(obj != filler && filler->IsFiller() && | 2100 CHECK(obj != filler && filler->IsFiller() && |
2102 filler->Size() == kPointerSize); | 2101 filler->Size() == kPointerSize); |
2103 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); | 2102 CHECK_EQ(kPointerSize + double_misalignment, |
| 2103 CcTest::heap()->new_space()->top() - start); |
2104 | 2104 |
2105 // Similarly for kDoubleUnaligned. | 2105 // Similarly for kDoubleUnaligned. |
2106 start = AlignNewSpace(kDoubleUnaligned, 0); | 2106 start = AlignNewSpace(kDoubleUnaligned, 0); |
2107 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2107 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); |
2108 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2108 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); |
2109 CHECK_EQ(kPointerSize, *top_addr - start); | 2109 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); |
2110 start = AlignNewSpace(kDoubleUnaligned, kPointerSize); | 2110 start = AlignNewSpace(kDoubleUnaligned, kPointerSize); |
2111 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2111 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); |
2112 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2112 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); |
2113 // There is a filler object before the object. | 2113 // There is a filler object before the object. |
2114 filler = HeapObject::FromAddress(start); | 2114 filler = HeapObject::FromAddress(start); |
2115 CHECK(obj != filler && filler->IsFiller() && | 2115 CHECK(obj != filler && filler->IsFiller() && |
2116 filler->Size() == kPointerSize); | 2116 filler->Size() == kPointerSize); |
2117 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); | 2117 CHECK_EQ(kPointerSize + double_misalignment, |
| 2118 CcTest::heap()->new_space()->top() - start); |
2118 } | 2119 } |
2119 | 2120 |
2120 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending | 2121 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending |
2121 // on platform. | 2122 // on platform. |
2122 start = AlignNewSpace(kSimd128Unaligned, 0); | 2123 start = AlignNewSpace(kSimd128Unaligned, 0); |
2123 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2124 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2124 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2125 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2125 // There is no filler. | 2126 // There is no filler. |
2126 CHECK_EQ(kPointerSize, *top_addr - start); | 2127 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); |
2127 start = AlignNewSpace(kSimd128Unaligned, kPointerSize); | 2128 start = AlignNewSpace(kSimd128Unaligned, kPointerSize); |
2128 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2129 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2129 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2130 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2130 // There is a filler object before the object. | 2131 // There is a filler object before the object. |
2131 filler = HeapObject::FromAddress(start); | 2132 filler = HeapObject::FromAddress(start); |
2132 CHECK(obj != filler && filler->IsFiller() && | 2133 CHECK(obj != filler && filler->IsFiller() && |
2133 filler->Size() == kSimd128Size - kPointerSize); | 2134 filler->Size() == kSimd128Size - kPointerSize); |
2134 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, *top_addr - start); | 2135 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, |
| 2136 CcTest::heap()->new_space()->top() - start); |
2135 | 2137 |
2136 if (double_misalignment) { | 2138 if (double_misalignment) { |
2137 // Test the 2 other alignments possible on 32 bit platforms. | 2139 // Test the 2 other alignments possible on 32 bit platforms. |
2138 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); | 2140 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); |
2139 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2141 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2140 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2142 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2141 // There is a filler object before the object. | 2143 // There is a filler object before the object. |
2142 filler = HeapObject::FromAddress(start); | 2144 filler = HeapObject::FromAddress(start); |
2143 CHECK(obj != filler && filler->IsFiller() && | 2145 CHECK(obj != filler && filler->IsFiller() && |
2144 filler->Size() == 2 * kPointerSize); | 2146 filler->Size() == 2 * kPointerSize); |
2145 CHECK_EQ(kPointerSize + 2 * kPointerSize, *top_addr - start); | 2147 CHECK_EQ(kPointerSize + 2 * kPointerSize, |
| 2148 CcTest::heap()->new_space()->top() - start); |
2146 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); | 2149 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); |
2147 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2150 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); |
2148 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2151 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); |
2149 // There is a filler object before the object. | 2152 // There is a filler object before the object. |
2150 filler = HeapObject::FromAddress(start); | 2153 filler = HeapObject::FromAddress(start); |
2151 CHECK(obj != filler && filler->IsFiller() && | 2154 CHECK(obj != filler && filler->IsFiller() && |
2152 filler->Size() == kPointerSize); | 2155 filler->Size() == kPointerSize); |
2153 CHECK_EQ(kPointerSize + kPointerSize, *top_addr - start); | 2156 CHECK_EQ(kPointerSize + kPointerSize, |
| 2157 CcTest::heap()->new_space()->top() - start); |
2154 } | 2158 } |
2155 } | 2159 } |
2156 | 2160 |
2157 | 2161 |
2158 static HeapObject* OldSpaceAllocateAligned(int size, | 2162 static HeapObject* OldSpaceAllocateAligned(int size, |
2159 AllocationAlignment alignment) { | 2163 AllocationAlignment alignment) { |
2160 Heap* heap = CcTest::heap(); | 2164 Heap* heap = CcTest::heap(); |
2161 AllocationResult allocation = | 2165 AllocationResult allocation = |
2162 heap->old_space()->AllocateRawAligned(size, alignment); | 2166 heap->old_space()->AllocateRawAligned(size, alignment); |
2163 HeapObject* obj = NULL; | 2167 HeapObject* obj = NULL; |
2164 allocation.To(&obj); | 2168 allocation.To(&obj); |
2165 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2169 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); |
2166 return obj; | 2170 return obj; |
2167 } | 2171 } |
2168 | 2172 |
2169 | 2173 |
2170 // Get old space allocation into the desired alignment. | 2174 // Get old space allocation into the desired alignment. |
2171 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { | 2175 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { |
2172 Address* top_addr = CcTest::heap()->old_space()->allocation_top_address(); | 2176 Address top = CcTest::heap()->old_space()->top(); |
2173 int fill = Heap::GetFillToAlign(*top_addr, alignment); | 2177 int fill = Heap::GetFillToAlign(top, alignment); |
2174 int allocation = fill + offset; | 2178 int allocation = fill + offset; |
2175 if (allocation) { | 2179 if (allocation) { |
2176 OldSpaceAllocateAligned(allocation, kWordAligned); | 2180 OldSpaceAllocateAligned(allocation, kWordAligned); |
2177 } | 2181 } |
2178 Address top = *top_addr; | 2182 top = CcTest::heap()->old_space()->top(); |
2179 // Now force the remaining allocation onto the free list. | 2183 // Now force the remaining allocation onto the free list. |
2180 CcTest::heap()->old_space()->EmptyAllocationInfo(); | 2184 CcTest::heap()->old_space()->EmptyAllocationInfo(); |
2181 return top; | 2185 return top; |
2182 } | 2186 } |
2183 | 2187 |
2184 | 2188 |
2185 // Test the case where allocation must be done from the free list, so filler | 2189 // Test the case where allocation must be done from the free list, so filler |
2186 // may precede or follow the object. | 2190 // may precede or follow the object. |
2187 TEST(TestAlignedOverAllocation) { | 2191 TEST(TestAlignedOverAllocation) { |
2188 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2192 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. |
(...skipping 4586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6775 int mark_sweeps_performed = mark_sweep_count_after - mark_sweep_count_before; | 6779 int mark_sweeps_performed = mark_sweep_count_after - mark_sweep_count_before; |
6776 // The memory pressuer handler either performed two GCs or performed one and | 6780 // The memory pressuer handler either performed two GCs or performed one and |
6777 // started incremental marking. | 6781 // started incremental marking. |
6778 CHECK(mark_sweeps_performed == 2 || | 6782 CHECK(mark_sweeps_performed == 2 || |
6779 (mark_sweeps_performed == 1 && | 6783 (mark_sweeps_performed == 1 && |
6780 !heap->incremental_marking()->IsStopped())); | 6784 !heap->incremental_marking()->IsStopped())); |
6781 } | 6785 } |
6782 | 6786 |
6783 } // namespace internal | 6787 } // namespace internal |
6784 } // namespace v8 | 6788 } // namespace v8 |
OLD | NEW |