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

Side by Side Diff: src/heap/heap.cc

Issue 1138643005: Clean-up aligned allocation logic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | src/heap/heap-inl.h » ('j') | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 if (space == LO_SPACE) { 1029 if (space == LO_SPACE) {
1030 DCHECK_EQ(1, reservation->length()); 1030 DCHECK_EQ(1, reservation->length());
1031 perform_gc = !lo_space()->CanAllocateSize(reservation->at(0).size); 1031 perform_gc = !lo_space()->CanAllocateSize(reservation->at(0).size);
1032 } else { 1032 } else {
1033 for (auto& chunk : *reservation) { 1033 for (auto& chunk : *reservation) {
1034 AllocationResult allocation; 1034 AllocationResult allocation;
1035 int size = chunk.size; 1035 int size = chunk.size;
1036 DCHECK_LE(size, MemoryAllocator::PageAreaSize( 1036 DCHECK_LE(size, MemoryAllocator::PageAreaSize(
1037 static_cast<AllocationSpace>(space))); 1037 static_cast<AllocationSpace>(space)));
1038 if (space == NEW_SPACE) { 1038 if (space == NEW_SPACE) {
1039 allocation = new_space()->AllocateRaw(size); 1039 allocation = new_space()->AllocateRawUnaligned(size);
1040 } else { 1040 } else {
1041 allocation = paged_space(space)->AllocateRaw(size); 1041 allocation = paged_space(space)->AllocateRawUnaligned(size);
1042 } 1042 }
1043 HeapObject* free_space; 1043 HeapObject* free_space;
1044 if (allocation.To(&free_space)) { 1044 if (allocation.To(&free_space)) {
1045 // Mark with a free list node, in case we have a GC before 1045 // Mark with a free list node, in case we have a GC before
1046 // deserializing. 1046 // deserializing.
1047 Address free_space_address = free_space->address(); 1047 Address free_space_address = free_space->address();
1048 CreateFillerObjectAt(free_space_address, size); 1048 CreateFillerObjectAt(free_space_address, size);
1049 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces); 1049 DCHECK(space < Serializer::kNumberOfPreallocatedSpaces);
1050 chunk.start = free_space_address; 1050 chunk.start = free_space_address;
1051 chunk.end = free_space_address + size; 1051 chunk.end = free_space_address + size;
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 } 2139 }
2140 } 2140 }
2141 } 2141 }
2142 2142
2143 template <int alignment> 2143 template <int alignment>
2144 static inline bool SemiSpaceCopyObject(Map* map, HeapObject** slot, 2144 static inline bool SemiSpaceCopyObject(Map* map, HeapObject** slot,
2145 HeapObject* object, int object_size) { 2145 HeapObject* object, int object_size) {
2146 Heap* heap = map->GetHeap(); 2146 Heap* heap = map->GetHeap();
2147 2147
2148 DCHECK(heap->AllowedToBeMigrated(object, NEW_SPACE)); 2148 DCHECK(heap->AllowedToBeMigrated(object, NEW_SPACE));
2149 AllocationResult allocation; 2149 AllocationAlignment align =
2150 #ifdef V8_HOST_ARCH_32_BIT 2150 alignment == kDoubleAlignment ? kDoubleAligned : kWordAligned;
2151 if (alignment == kDoubleAlignment) { 2151 AllocationResult allocation =
2152 allocation = 2152 heap->new_space()->AllocateRaw(object_size, align);
2153 heap->new_space()->AllocateRawAligned(object_size, kDoubleAligned);
2154 } else {
2155 allocation = heap->new_space()->AllocateRaw(object_size);
2156 }
2157 #else
2158 allocation = heap->new_space()->AllocateRaw(object_size);
2159 #endif
2160 2153
2161 HeapObject* target = NULL; // Initialization to please compiler. 2154 HeapObject* target = NULL; // Initialization to please compiler.
2162 if (allocation.To(&target)) { 2155 if (allocation.To(&target)) {
2163 // Order is important here: Set the promotion limit before storing a 2156 // Order is important here: Set the promotion limit before storing a
2164 // filler for double alignment or migrating the object. Otherwise we 2157 // filler for double alignment or migrating the object. Otherwise we
2165 // may end up overwriting promotion queue entries when we migrate the 2158 // may end up overwriting promotion queue entries when we migrate the
2166 // object. 2159 // object.
2167 heap->promotion_queue()->SetNewLimit(heap->new_space()->top()); 2160 heap->promotion_queue()->SetNewLimit(heap->new_space()->top());
2168 2161
2169 MigrateObject(heap, object, target, object_size); 2162 MigrateObject(heap, object, target, object_size);
2170 2163
2171 // Update slot to new target. 2164 // Update slot to new target.
2172 *slot = target; 2165 *slot = target;
2173 2166
2174 heap->IncrementSemiSpaceCopiedObjectSize(object_size); 2167 heap->IncrementSemiSpaceCopiedObjectSize(object_size);
2175 return true; 2168 return true;
2176 } 2169 }
2177 return false; 2170 return false;
2178 } 2171 }
2179 2172
2180 2173
2181 template <ObjectContents object_contents, int alignment> 2174 template <ObjectContents object_contents, int alignment>
2182 static inline bool PromoteObject(Map* map, HeapObject** slot, 2175 static inline bool PromoteObject(Map* map, HeapObject** slot,
2183 HeapObject* object, int object_size) { 2176 HeapObject* object, int object_size) {
2184 Heap* heap = map->GetHeap(); 2177 Heap* heap = map->GetHeap();
2185 2178
2186 AllocationResult allocation; 2179 AllocationAlignment align =
2187 #ifdef V8_HOST_ARCH_32_BIT 2180 alignment == kDoubleAlignment ? kDoubleAligned : kWordAligned;
2188 if (alignment == kDoubleAlignment) { 2181 AllocationResult allocation =
2189 allocation = 2182 heap->old_space()->AllocateRaw(object_size, align);
2190 heap->old_space()->AllocateRawAligned(object_size, kDoubleAligned);
2191 } else {
2192 allocation = heap->old_space()->AllocateRaw(object_size);
2193 }
2194 #else
2195 allocation = heap->old_space()->AllocateRaw(object_size);
2196 #endif
2197 2183
2198 HeapObject* target = NULL; // Initialization to please compiler. 2184 HeapObject* target = NULL; // Initialization to please compiler.
2199 if (allocation.To(&target)) { 2185 if (allocation.To(&target)) {
2200 MigrateObject(heap, object, target, object_size); 2186 MigrateObject(heap, object, target, object_size);
2201 2187
2202 // Update slot to new target. 2188 // Update slot to new target.
2203 *slot = target; 2189 *slot = target;
2204 2190
2205 if (object_contents == POINTER_OBJECT) { 2191 if (object_contents == POINTER_OBJECT) {
2206 if (map->instance_type() == JS_FUNCTION_TYPE) { 2192 if (map->instance_type() == JS_FUNCTION_TYPE) {
(...skipping 4323 matching lines...) Expand 10 before | Expand all | Expand 10 after
6530 } 6516 }
6531 delete list; 6517 delete list;
6532 } else { 6518 } else {
6533 prev = list; 6519 prev = list;
6534 } 6520 }
6535 list = next; 6521 list = next;
6536 } 6522 }
6537 } 6523 }
6538 } 6524 }
6539 } // namespace v8::internal 6525 } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698