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

Unified Diff: src/heap/heap.cc

Issue 1150593003: Clean up aligned allocation code in preparation for SIMD alignments. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix DoubleAlignForDeserialization, fix test when top is misaligned. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/spaces.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 3b291d2916cd8228d645f619f779adff0b5e9419..b7cc3299cfea764fb94748c7c8a5876ba71e9310 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -1986,31 +1986,54 @@ STATIC_ASSERT((HeapNumber::kValueOffset & kDoubleAlignmentMask) !=
#endif
-HeapObject* Heap::EnsureAligned(HeapObject* object, int size,
- AllocationAlignment alignment) {
- if (alignment == kDoubleAligned &&
- (OffsetFrom(object->address()) & kDoubleAlignmentMask) != 0) {
- CreateFillerObjectAt(object->address(), kPointerSize);
- return HeapObject::FromAddress(object->address() + kPointerSize);
- } else if (alignment == kDoubleUnaligned &&
- (OffsetFrom(object->address()) & kDoubleAlignmentMask) == 0) {
- CreateFillerObjectAt(object->address(), kPointerSize);
- return HeapObject::FromAddress(object->address() + kPointerSize);
- } else {
- CreateFillerObjectAt(object->address() + size - kPointerSize, kPointerSize);
- return object;
+int Heap::GetMaximumFillToAlign(AllocationAlignment alignment) {
+ switch (alignment) {
+ case kWordAligned:
+ return 0;
+ case kDoubleAligned:
+ case kDoubleUnaligned:
+ return kDoubleSize - kPointerSize;
+ default:
+ UNREACHABLE();
}
+ return 0;
+}
+
+
+int Heap::GetFillToAlign(Address address, AllocationAlignment alignment) {
+ intptr_t offset = OffsetFrom(address);
+ if (alignment == kDoubleAligned && (offset & kDoubleAlignmentMask) != 0)
+ return kPointerSize;
+ if (alignment == kDoubleUnaligned && (offset & kDoubleAlignmentMask) == 0)
+ return kDoubleSize - kPointerSize; // No fill if double is always aligned.
+ return 0;
}
-HeapObject* Heap::PrecedeWithFiller(HeapObject* object) {
- CreateFillerObjectAt(object->address(), kPointerSize);
- return HeapObject::FromAddress(object->address() + kPointerSize);
+HeapObject* Heap::PrecedeWithFiller(HeapObject* object, int filler_size) {
+ CreateFillerObjectAt(object->address(), filler_size);
+ return HeapObject::FromAddress(object->address() + filler_size);
+}
+
+
+HeapObject* Heap::AlignWithFiller(HeapObject* object, int object_size,
+ int allocation_size,
+ AllocationAlignment alignment) {
+ int filler_size = allocation_size - object_size;
+ DCHECK(filler_size > 0);
+ int pre_filler = GetFillToAlign(object->address(), alignment);
+ if (pre_filler) {
+ object = PrecedeWithFiller(object, pre_filler);
+ filler_size -= pre_filler;
+ }
+ if (filler_size)
+ CreateFillerObjectAt(object->address() + object_size, filler_size);
+ return object;
}
HeapObject* Heap::DoubleAlignForDeserialization(HeapObject* object, int size) {
- return EnsureAligned(object, size, kDoubleAligned);
+ return AlignWithFiller(object, size - kPointerSize, size, kDoubleAligned);
}
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698