Index: src/heap/spaces-inl.h |
diff --git a/src/heap/spaces-inl.h b/src/heap/spaces-inl.h |
index f7367650ebb24974226fe5a45e11dbdcb83be9e7..4416b5ead7872e600591e665696a2a8a40e61663 100644 |
--- a/src/heap/spaces-inl.h |
+++ b/src/heap/spaces-inl.h |
@@ -250,28 +250,21 @@ HeapObject* PagedSpace::AllocateLinearly(int size_in_bytes) { |
} |
-HeapObject* PagedSpace::AllocateLinearlyAligned(int size_in_bytes, |
+HeapObject* PagedSpace::AllocateLinearlyAligned(int* size_in_bytes, |
AllocationAlignment alignment) { |
Address current_top = allocation_info_.top(); |
- int alignment_size = 0; |
- |
- if (alignment == kDoubleAligned && |
- (OffsetFrom(current_top) & kDoubleAlignmentMask) != 0) { |
- alignment_size = kPointerSize; |
- size_in_bytes += alignment_size; |
- } else if (alignment == kDoubleUnaligned && |
- (OffsetFrom(current_top) & kDoubleAlignmentMask) == 0) { |
- alignment_size = kPointerSize; |
- size_in_bytes += alignment_size; |
- } |
- Address new_top = current_top + size_in_bytes; |
+ int alignment_size = Heap::GetAlignmentSize(current_top, alignment); |
+ |
+ Address new_top = current_top + alignment_size + *size_in_bytes; |
if (new_top > allocation_info_.limit()) return NULL; |
allocation_info_.set_top(new_top); |
if (alignment_size > 0) { |
- return heap()->EnsureAligned(HeapObject::FromAddress(current_top), |
- size_in_bytes, alignment); |
+ *size_in_bytes += alignment_size; |
+ return heap()->PrecedeWithFiller(HeapObject::FromAddress(current_top), |
+ alignment_size); |
} |
+ |
return HeapObject::FromAddress(current_top); |
} |
@@ -303,8 +296,9 @@ AllocationResult PagedSpace::AllocateRawUnaligned(int size_in_bytes) { |
AllocationResult PagedSpace::AllocateRawAligned(int size_in_bytes, |
AllocationAlignment alignment) { |
DCHECK(identity() == OLD_SPACE); |
- HeapObject* object = AllocateLinearlyAligned(size_in_bytes, alignment); |
- int aligned_size_in_bytes = size_in_bytes + kPointerSize; |
+ int aligned_size_in_bytes = size_in_bytes; |
+ HeapObject* object = |
+ AllocateLinearlyAligned(&aligned_size_in_bytes, alignment); |
if (object == NULL) { |
object = free_list_.Allocate(aligned_size_in_bytes); |
Hannes Payer (out of office)
2015/05/21 10:38:17
I don't see how alignment works for free-list allo
bbudge
2015/05/21 10:55:45
Thanks for pointing this out. I'll have to modify
|
@@ -312,7 +306,8 @@ AllocationResult PagedSpace::AllocateRawAligned(int size_in_bytes, |
object = SlowAllocateRaw(aligned_size_in_bytes); |
} |
if (object != NULL) { |
- object = heap()->EnsureAligned(object, aligned_size_in_bytes, alignment); |
+ object = heap()->PrecedeWithFiller(object, |
+ aligned_size_in_bytes - size_in_bytes); |
} |
} |
@@ -344,19 +339,8 @@ AllocationResult PagedSpace::AllocateRaw(int size_in_bytes, |
AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes, |
AllocationAlignment alignment) { |
Address old_top = allocation_info_.top(); |
- int alignment_size = 0; |
- int aligned_size_in_bytes = 0; |
- |
- // If double alignment is required and top pointer is not aligned, we allocate |
- // additional memory to take care of the alignment. |
- if (alignment == kDoubleAligned && |
- (OffsetFrom(old_top) & kDoubleAlignmentMask) != 0) { |
- alignment_size += kPointerSize; |
- } else if (alignment == kDoubleUnaligned && |
- (OffsetFrom(old_top) & kDoubleAlignmentMask) == 0) { |
- alignment_size += kPointerSize; |
- } |
- aligned_size_in_bytes = size_in_bytes + alignment_size; |
+ int alignment_size = Heap::GetAlignmentSize(old_top, alignment); |
+ int aligned_size_in_bytes = size_in_bytes + alignment_size; |
if (allocation_info_.limit() - old_top < aligned_size_in_bytes) { |
return SlowAllocateRaw(size_in_bytes, alignment); |
@@ -367,15 +351,12 @@ AllocationResult NewSpace::AllocateRawAligned(int size_in_bytes, |
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
if (alignment_size > 0) { |
- obj = heap()->PrecedeWithFiller(obj); |
+ obj = heap()->PrecedeWithFiller(obj, alignment_size); |
} |
// The slow path above ultimately goes through AllocateRaw, so this suffices. |
MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj->address(), size_in_bytes); |
- DCHECK((kDoubleAligned && (OffsetFrom(obj) & kDoubleAlignmentMask) == 0) || |
- (kDoubleUnaligned && (OffsetFrom(obj) & kDoubleAlignmentMask) != 0)); |
bbudge
2015/05/20 15:39:38
I eliminated this since it can never assert.
|
- |
return obj; |
} |