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

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

Issue 2031493002: Revert of Provide a tagged allocation top pointer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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 | « test/cctest/heap/heap-utils.cc ('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 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = CcTest::heap()->new_space()->top(); 2030 Address* top_addr = CcTest::heap()->new_space()->allocation_top_address();
2031 int fill = Heap::GetFillToAlign(top, alignment); 2031 int fill = Heap::GetFillToAlign(*top_addr, alignment);
2032 if (fill) { 2032 if (fill) {
2033 NewSpaceAllocateAligned(fill + offset, kWordAligned); 2033 NewSpaceAllocateAligned(fill + offset, kWordAligned);
2034 } 2034 }
2035 return CcTest::heap()->new_space()->top(); 2035 return *top_addr;
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();
2042 Address start; 2043 Address start;
2043 HeapObject* obj; 2044 HeapObject* obj;
2044 HeapObject* filler; 2045 HeapObject* filler;
2045 if (double_misalignment) { 2046 if (double_misalignment) {
2046 // Allocate a pointer sized object that must be double aligned at an 2047 // Allocate a pointer sized object that must be double aligned at an
2047 // aligned address. 2048 // aligned address.
2048 start = AlignNewSpace(kDoubleAligned, 0); 2049 start = AlignNewSpace(kDoubleAligned, 0);
2049 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); 2050 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned);
2050 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); 2051 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment));
2051 // There is no filler. 2052 // There is no filler.
2052 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); 2053 CHECK_EQ(kPointerSize, *top_addr - start);
2053 2054
2054 // Allocate a second pointer sized object that must be double aligned at an 2055 // Allocate a second pointer sized object that must be double aligned at an
2055 // unaligned address. 2056 // unaligned address.
2056 start = AlignNewSpace(kDoubleAligned, kPointerSize); 2057 start = AlignNewSpace(kDoubleAligned, kPointerSize);
2057 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned); 2058 obj = NewSpaceAllocateAligned(kPointerSize, kDoubleAligned);
2058 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment)); 2059 CHECK(IsAddressAligned(obj->address(), kDoubleAlignment));
2059 // There is a filler object before the object. 2060 // There is a filler object before the object.
2060 filler = HeapObject::FromAddress(start); 2061 filler = HeapObject::FromAddress(start);
2061 CHECK(obj != filler && filler->IsFiller() && 2062 CHECK(obj != filler && filler->IsFiller() &&
2062 filler->Size() == kPointerSize); 2063 filler->Size() == kPointerSize);
2063 CHECK_EQ(kPointerSize + double_misalignment, 2064 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start);
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, CcTest::heap()->new_space()->top() - start); 2070 CHECK_EQ(kPointerSize, *top_addr - 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, 2078 CHECK_EQ(kPointerSize + double_misalignment, *top_addr - start);
2079 CcTest::heap()->new_space()->top() - start);
2080 } 2079 }
2081 2080
2082 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending 2081 // Now test SIMD alignment. There are 2 or 4 possible alignments, depending
2083 // on platform. 2082 // on platform.
2084 start = AlignNewSpace(kSimd128Unaligned, 0); 2083 start = AlignNewSpace(kSimd128Unaligned, 0);
2085 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); 2084 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2086 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); 2085 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2087 // There is no filler. 2086 // There is no filler.
2088 CHECK_EQ(kPointerSize, CcTest::heap()->new_space()->top() - start); 2087 CHECK_EQ(kPointerSize, *top_addr - start);
2089 start = AlignNewSpace(kSimd128Unaligned, kPointerSize); 2088 start = AlignNewSpace(kSimd128Unaligned, kPointerSize);
2090 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); 2089 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2091 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); 2090 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2092 // There is a filler object before the object. 2091 // There is a filler object before the object.
2093 filler = HeapObject::FromAddress(start); 2092 filler = HeapObject::FromAddress(start);
2094 CHECK(obj != filler && filler->IsFiller() && 2093 CHECK(obj != filler && filler->IsFiller() &&
2095 filler->Size() == kSimd128Size - kPointerSize); 2094 filler->Size() == kSimd128Size - kPointerSize);
2096 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, 2095 CHECK_EQ(kPointerSize + kSimd128Size - kPointerSize, *top_addr - start);
2097 CcTest::heap()->new_space()->top() - start);
2098 2096
2099 if (double_misalignment) { 2097 if (double_misalignment) {
2100 // Test the 2 other alignments possible on 32 bit platforms. 2098 // Test the 2 other alignments possible on 32 bit platforms.
2101 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize); 2099 start = AlignNewSpace(kSimd128Unaligned, 2 * kPointerSize);
2102 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); 2100 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2103 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); 2101 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2104 // There is a filler object before the object. 2102 // There is a filler object before the object.
2105 filler = HeapObject::FromAddress(start); 2103 filler = HeapObject::FromAddress(start);
2106 CHECK(obj != filler && filler->IsFiller() && 2104 CHECK(obj != filler && filler->IsFiller() &&
2107 filler->Size() == 2 * kPointerSize); 2105 filler->Size() == 2 * kPointerSize);
2108 CHECK_EQ(kPointerSize + 2 * kPointerSize, 2106 CHECK_EQ(kPointerSize + 2 * kPointerSize, *top_addr - start);
2109 CcTest::heap()->new_space()->top() - start);
2110 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize); 2107 start = AlignNewSpace(kSimd128Unaligned, 3 * kPointerSize);
2111 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned); 2108 obj = NewSpaceAllocateAligned(kPointerSize, kSimd128Unaligned);
2112 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize)); 2109 CHECK(IsAddressAligned(obj->address(), kSimd128Alignment, kPointerSize));
2113 // There is a filler object before the object. 2110 // There is a filler object before the object.
2114 filler = HeapObject::FromAddress(start); 2111 filler = HeapObject::FromAddress(start);
2115 CHECK(obj != filler && filler->IsFiller() && 2112 CHECK(obj != filler && filler->IsFiller() &&
2116 filler->Size() == kPointerSize); 2113 filler->Size() == kPointerSize);
2117 CHECK_EQ(kPointerSize + kPointerSize, 2114 CHECK_EQ(kPointerSize + kPointerSize, *top_addr - start);
2118 CcTest::heap()->new_space()->top() - start);
2119 } 2115 }
2120 } 2116 }
2121 2117
2122 2118
2123 static HeapObject* OldSpaceAllocateAligned(int size, 2119 static HeapObject* OldSpaceAllocateAligned(int size,
2124 AllocationAlignment alignment) { 2120 AllocationAlignment alignment) {
2125 Heap* heap = CcTest::heap(); 2121 Heap* heap = CcTest::heap();
2126 AllocationResult allocation = 2122 AllocationResult allocation =
2127 heap->old_space()->AllocateRawAligned(size, alignment); 2123 heap->old_space()->AllocateRawAligned(size, alignment);
2128 HeapObject* obj = NULL; 2124 HeapObject* obj = NULL;
2129 allocation.To(&obj); 2125 allocation.To(&obj);
2130 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo); 2126 heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
2131 return obj; 2127 return obj;
2132 } 2128 }
2133 2129
2134 2130
2135 // Get old space allocation into the desired alignment. 2131 // Get old space allocation into the desired alignment.
2136 static Address AlignOldSpace(AllocationAlignment alignment, int offset) { 2132 static Address AlignOldSpace(AllocationAlignment alignment, int offset) {
2137 Address top = CcTest::heap()->old_space()->top(); 2133 Address* top_addr = CcTest::heap()->old_space()->allocation_top_address();
2138 int fill = Heap::GetFillToAlign(top, alignment); 2134 int fill = Heap::GetFillToAlign(*top_addr, alignment);
2139 int allocation = fill + offset; 2135 int allocation = fill + offset;
2140 if (allocation) { 2136 if (allocation) {
2141 OldSpaceAllocateAligned(allocation, kWordAligned); 2137 OldSpaceAllocateAligned(allocation, kWordAligned);
2142 } 2138 }
2143 top = CcTest::heap()->old_space()->top(); 2139 Address top = *top_addr;
2144 // Now force the remaining allocation onto the free list. 2140 // Now force the remaining allocation onto the free list.
2145 CcTest::heap()->old_space()->EmptyAllocationInfo(); 2141 CcTest::heap()->old_space()->EmptyAllocationInfo();
2146 return top; 2142 return top;
2147 } 2143 }
2148 2144
2149 2145
2150 // Test the case where allocation must be done from the free list, so filler 2146 // Test the case where allocation must be done from the free list, so filler
2151 // may precede or follow the object. 2147 // may precede or follow the object.
2152 TEST(TestAlignedOverAllocation) { 2148 TEST(TestAlignedOverAllocation) {
2153 // Double misalignment is 4 on 32-bit platforms, 0 on 64-bit ones. 2149 // 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
6721 CHECK(marking->IsComplete()); 6717 CHECK(marking->IsComplete());
6722 intptr_t size_before = heap->SizeOfObjects(); 6718 intptr_t size_before = heap->SizeOfObjects();
6723 CcTest::heap()->CollectAllGarbage(); 6719 CcTest::heap()->CollectAllGarbage();
6724 intptr_t size_after = heap->SizeOfObjects(); 6720 intptr_t size_after = heap->SizeOfObjects();
6725 // Live size does not increase after garbage collection. 6721 // Live size does not increase after garbage collection.
6726 CHECK_LE(size_after, size_before); 6722 CHECK_LE(size_after, size_before);
6727 } 6723 }
6728 6724
6729 } // namespace internal 6725 } // namespace internal
6730 } // namespace v8 6726 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/heap/heap-utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698