| 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 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2020       heap->new_space()->AllocateRawAligned(size, alignment); | 2020       heap->new_space()->AllocateRawAligned(size, alignment); | 
| 2021   HeapObject* obj = NULL; | 2021   HeapObject* obj = NULL; | 
| 2022   allocation.To(&obj); | 2022   allocation.To(&obj); | 
| 2023   heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2023   heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 
| 2024   return obj; | 2024   return obj; | 
| 2025 } | 2025 } | 
| 2026 | 2026 | 
| 2027 | 2027 | 
| 2028 // Get new space allocation into the desired alignment. | 2028 // Get new space allocation into the desired alignment. | 
| 2029 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { | 2029 static Address AlignNewSpace(AllocationAlignment alignment, int offset) { | 
| 2030   Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); | 2030   Address top = CcTest::heap()->new_space()->top(); | 
| 2031   int fill = Heap::GetFillToAlign(*top_addr, alignment); | 2031   int fill = Heap::GetFillToAlign(top, alignment); | 
| 2032   if (fill) { | 2032   if (fill) { | 
| 2033     NewSpaceAllocateAligned(fill + offset, kWordAligned); | 2033     NewSpaceAllocateAligned(fill + offset, kWordAligned); | 
| 2034   } | 2034   } | 
| 2035   return *top_addr; | 2035   return CcTest::heap()->new_space()->top(); | 
| 2036 } | 2036 } | 
| 2037 | 2037 | 
| 2038 | 2038 | 
| 2039 TEST(TestAlignedAllocation) { | 2039 TEST(TestAlignedAllocation) { | 
| 2040   // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2040   // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 
| 2041   const intptr_t double_misalignment = kDoubleSize - kPointerSize; | 2041   const intptr_t double_misalignment = kDoubleSize - kPointerSize; | 
| 2042   Address* top_addr = CcTest::heap()->new_space()->allocation_top_address(); |  | 
| 2043   Address start; | 2042   Address start; | 
| 2044   HeapObject* obj; | 2043   HeapObject* obj; | 
| 2045   HeapObject* filler; | 2044   HeapObject* filler; | 
| 2046   if (double_misalignment) { | 2045   if (double_misalignment) { | 
| 2047     // Allocate a pointer sized object that must be double aligned at an | 2046     // Allocate a pointer sized object that must be double aligned at an | 
| 2048     // aligned address. | 2047     // aligned address. | 
| 2049     start = AlignNewSpace(kDoubleAligned, 0); | 2048     start = AlignNewSpace(kDoubleAligned, 0); | 
| 2050     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2049     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 
| 2051     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2050     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 
| 2052     // There is no filler. | 2051     // There is no filler. | 
| 2053     CHECK_EQ(kPointerSize, *top_addr - start); | 2052     CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 
| 2054 | 2053 | 
| 2055     // Allocate a second pointer sized object that must be double aligned at an | 2054     // Allocate a second pointer sized object that must be double aligned at an | 
| 2056     // unaligned address. | 2055     // unaligned address. | 
| 2057     start = AlignNewSpace(kDoubleAligned, kPointerSize); | 2056     start = AlignNewSpace(kDoubleAligned, kPointerSize); | 
| 2058     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 2057     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); | 
| 2059     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 2058     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); | 
| 2060     // There is a filler object before the object. | 2059     // There is a filler object before the object. | 
| 2061     filler = HeapObject::FromAddress(start); | 2060     filler = HeapObject::FromAddress(start); | 
| 2062     CHECK(obj != filler && filler->IsFiller() && | 2061     CHECK(obj != filler && filler->IsFiller() && | 
| 2063           filler->Size() == kPointerSize); | 2062           filler->Size() == kPointerSize); | 
| 2064     CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); | 2063     CHECK_EQ(kPointerSize + double_misalignment, | 
|  | 2064              CcTest::heap()->new_space()->top() - start); | 
| 2065 | 2065 | 
| 2066     // Similarly for kDoubleUnaligned. | 2066     // Similarly for kDoubleUnaligned. | 
| 2067     start = AlignNewSpace(kDoubleUnaligned, 0); | 2067     start = AlignNewSpace(kDoubleUnaligned, 0); | 
| 2068     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2068     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 
| 2069     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2069     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 
| 2070     CHECK_EQ(kPointerSize, *top_addr - start); | 2070     CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 
| 2071     start = AlignNewSpace(kDoubleUnaligned, kPointerSize); | 2071     start = AlignNewSpace(kDoubleUnaligned, kPointerSize); | 
| 2072     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 2072     obj = NewSpaceAllocateAligned(kPointerSize, kDoubleUnaligned); | 
| 2073     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 2073     CHECK(IsAddressAligned(obj->address(), kDoubleAlignment, kPointerSize)); | 
| 2074     // There is a filler object before the object. | 2074     // There is a filler object before the object. | 
| 2075     filler = HeapObject::FromAddress(start); | 2075     filler = HeapObject::FromAddress(start); | 
| 2076     CHECK(obj != filler && filler->IsFiller() && | 2076     CHECK(obj != filler && filler->IsFiller() && | 
| 2077           filler->Size() == kPointerSize); | 2077           filler->Size() == kPointerSize); | 
| 2078     CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start); | 2078     CHECK_EQ(kPointerSize + double_misalignment, | 
|  | 2079              CcTest::heap()->new_space()->top() - start); | 
| 2079   } | 2080   } | 
| 2080 | 2081 | 
| 2081   // Now test SIMD alignment. There are 2 or 4 possible alignments, depending | 2082   // Now test SIMD alignment. There are 2 or 4 possible alignments, depending | 
| 2082   // on platform. | 2083   // on platform. | 
| 2083   start = AlignNewSpace(kSimd128Unaligned, 0); | 2084   start = AlignNewSpace(kSimd128Unaligned, 0); | 
| 2084   obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2085   obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 
| 2085   CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2086   CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 
| 2086   // There is no filler. | 2087   // There is no filler. | 
| 2087   CHECK_EQ(kPointerSize, *top_addr - start); | 2088   CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); | 
| 2088   start = AlignNewSpace(kSimd128Unaligned, kPointerSize); | 2089   start = AlignNewSpace(kSimd128Unaligned, kPointerSize); | 
| 2089   obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2090   obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 
| 2090   CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2091   CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 
| 2091   // There is a filler object before the object. | 2092   // There is a filler object before the object. | 
| 2092   filler = HeapObject::FromAddress(start); | 2093   filler = HeapObject::FromAddress(start); | 
| 2093   CHECK(obj != filler && filler->IsFiller() && | 2094   CHECK(obj != filler && filler->IsFiller() && | 
| 2094         filler->Size() == kSimd128Size - kPointerSize); | 2095         filler->Size() == kSimd128Size - kPointerSize); | 
| 2095   CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, *top_addr - start); | 2096   CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, | 
|  | 2097            CcTest::heap()->new_space()->top() - start); | 
| 2096 | 2098 | 
| 2097   if (double_misalignment) { | 2099   if (double_misalignment) { | 
| 2098     // Test the 2 other alignments possible on 32 bit platforms. | 2100     // Test the 2 other alignments possible on 32 bit platforms. | 
| 2099     start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); | 2101     start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); | 
| 2100     obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2102     obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 
| 2101     CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2103     CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 
| 2102     // There is a filler object before the object. | 2104     // There is a filler object before the object. | 
| 2103     filler = HeapObject::FromAddress(start); | 2105     filler = HeapObject::FromAddress(start); | 
| 2104     CHECK(obj != filler && filler->IsFiller() && | 2106     CHECK(obj != filler && filler->IsFiller() && | 
| 2105           filler->Size() == 2 * kPointerSize); | 2107           filler->Size() == 2 * kPointerSize); | 
| 2106     CHECK_EQ(kPointerSize + 2 * kPointerSize, *top_addr - start); | 2108     CHECK_EQ(kPointerSize + 2 * kPointerSize, | 
|  | 2109              CcTest::heap()->new_space()->top() - start); | 
| 2107     start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); | 2110     start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); | 
| 2108     obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 2111     obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); | 
| 2109     CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 2112     CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); | 
| 2110     // There is a filler object before the object. | 2113     // There is a filler object before the object. | 
| 2111     filler = HeapObject::FromAddress(start); | 2114     filler = HeapObject::FromAddress(start); | 
| 2112     CHECK(obj != filler && filler->IsFiller() && | 2115     CHECK(obj != filler && filler->IsFiller() && | 
| 2113           filler->Size() == kPointerSize); | 2116           filler->Size() == kPointerSize); | 
| 2114     CHECK_EQ(kPointerSize + kPointerSize, *top_addr - start); | 2117     CHECK_EQ(kPointerSize + kPointerSize, | 
|  | 2118              CcTest::heap()->new_space()->top() - start); | 
| 2115   } | 2119   } | 
| 2116 } | 2120 } | 
| 2117 | 2121 | 
| 2118 | 2122 | 
| 2119 static HeapObject* OldSpaceAllocateAligned(int size, | 2123 static HeapObject* OldSpaceAllocateAligned(int size, | 
| 2120                                            AllocationAlignment alignment) { | 2124                                            AllocationAlignment alignment) { | 
| 2121   Heap* heap = CcTest::heap(); | 2125   Heap* heap = CcTest::heap(); | 
| 2122   AllocationResult allocation = | 2126   AllocationResult allocation = | 
| 2123       heap->old_space()->AllocateRawAligned(size, alignment); | 2127       heap->old_space()->AllocateRawAligned(size, alignment); | 
| 2124   HeapObject* obj = NULL; | 2128   HeapObject* obj = NULL; | 
| 2125   allocation.To(&obj); | 2129   allocation.To(&obj); | 
| 2126   heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 2130   heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); | 
| 2127   return obj; | 2131   return obj; | 
| 2128 } | 2132 } | 
| 2129 | 2133 | 
| 2130 | 2134 | 
| 2131 // Get old space allocation into the desired alignment. | 2135 // Get old space allocation into the desired alignment. | 
| 2132 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { | 2136 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { | 
| 2133   Address* top_addr = CcTest::heap()->old_space()->allocation_top_address(); | 2137   Address top = CcTest::heap()->old_space()->top(); | 
| 2134   int fill = Heap::GetFillToAlign(*top_addr, alignment); | 2138   int fill = Heap::GetFillToAlign(top, alignment); | 
| 2135   int allocation = fill + offset; | 2139   int allocation = fill + offset; | 
| 2136   if (allocation) { | 2140   if (allocation) { | 
| 2137     OldSpaceAllocateAligned(allocation, kWordAligned); | 2141     OldSpaceAllocateAligned(allocation, kWordAligned); | 
| 2138   } | 2142   } | 
| 2139   Address top = *top_addr; | 2143   top = CcTest::heap()->old_space()->top(); | 
| 2140   // Now force the remaining allocation onto the free list. | 2144   // Now force the remaining allocation onto the free list. | 
| 2141   CcTest::heap()->old_space()->EmptyAllocationInfo(); | 2145   CcTest::heap()->old_space()->EmptyAllocationInfo(); | 
| 2142   return top; | 2146   return top; | 
| 2143 } | 2147 } | 
| 2144 | 2148 | 
| 2145 | 2149 | 
| 2146 // Test the case where allocation must be done from the free list, so filler | 2150 // Test the case where allocation must be done from the free list, so filler | 
| 2147 // may precede or follow the object. | 2151 // may precede or follow the object. | 
| 2148 TEST(TestAlignedOverAllocation) { | 2152 TEST(TestAlignedOverAllocation) { | 
| 2149   // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 2153   // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. | 
| (...skipping 4600 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6750 | 6754 | 
| 6751   intptr_t size_before = heap->SizeOfObjects(); | 6755   intptr_t size_before = heap->SizeOfObjects(); | 
| 6752   Handle<FixedArray> array = isolate->factory()->NewFixedArray(200000); | 6756   Handle<FixedArray> array = isolate->factory()->NewFixedArray(200000); | 
| 6753   array->Shrink(1); | 6757   array->Shrink(1); | 
| 6754   intptr_t size_after = heap->SizeOfObjects(); | 6758   intptr_t size_after = heap->SizeOfObjects(); | 
| 6755   CHECK_EQ(size_after, size_before + array->Size()); | 6759   CHECK_EQ(size_after, size_before + array->Size()); | 
| 6756 } | 6760 } | 
| 6757 | 6761 | 
| 6758 }  // namespace internal | 6762 }  // namespace internal | 
| 6759 }  // namespace v8 | 6763 }  // namespace v8 | 
| OLD | NEW | 
|---|