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); |
} |