diff options
Diffstat (limited to 'deps/v8/src/heap/spaces-inl.h')
-rw-r--r-- | deps/v8/src/heap/spaces-inl.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/deps/v8/src/heap/spaces-inl.h b/deps/v8/src/heap/spaces-inl.h index fb290feee5..f24df06a1d 100644 --- a/deps/v8/src/heap/spaces-inl.h +++ b/deps/v8/src/heap/spaces-inl.h @@ -192,6 +192,122 @@ MemoryChunk* MemoryChunkIterator::Next() { return chunk; } +AllocationResult SpaceWithLinearArea::AllocateFastUnaligned( + int size_in_bytes, AllocationOrigin origin) { + if (!allocation_info_->CanIncrementTop(size_in_bytes)) { + return AllocationResult::Failure(); + } + HeapObject obj = + HeapObject::FromAddress(allocation_info_->IncrementTop(size_in_bytes)); + + MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj.address(), size_in_bytes); + + if (FLAG_trace_allocations_origins) { + UpdateAllocationOrigins(origin); + } + + return AllocationResult::FromObject(obj); +} + +AllocationResult SpaceWithLinearArea::AllocateFastAligned( + int size_in_bytes, int* result_aligned_size_in_bytes, + AllocationAlignment alignment, AllocationOrigin origin) { + Address top = allocation_info_->top(); + int filler_size = Heap::GetFillToAlign(top, alignment); + int aligned_size_in_bytes = size_in_bytes + filler_size; + + if (!allocation_info_->CanIncrementTop(aligned_size_in_bytes)) { + return AllocationResult::Failure(); + } + HeapObject obj = HeapObject::FromAddress( + allocation_info_->IncrementTop(aligned_size_in_bytes)); + if (result_aligned_size_in_bytes) + *result_aligned_size_in_bytes = aligned_size_in_bytes; + + if (filler_size > 0) { + obj = heap()->PrecedeWithFiller(obj, filler_size); + } + + MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj.address(), size_in_bytes); + + if (FLAG_trace_allocations_origins) { + UpdateAllocationOrigins(origin); + } + + return AllocationResult::FromObject(obj); +} + +AllocationResult SpaceWithLinearArea::AllocateRaw(int size_in_bytes, + AllocationAlignment alignment, + AllocationOrigin origin) { + DCHECK(!FLAG_enable_third_party_heap); + + AllocationResult result; + + if (USE_ALLOCATION_ALIGNMENT_BOOL && alignment != kTaggedAligned) { + result = AllocateFastAligned(size_in_bytes, nullptr, alignment, origin); + } else { + result = AllocateFastUnaligned(size_in_bytes, origin); + } + + return result.IsFailure() ? AllocateRawSlow(size_in_bytes, alignment, origin) + : result; +} + +AllocationResult SpaceWithLinearArea::AllocateRawUnaligned( + int size_in_bytes, AllocationOrigin origin) { + DCHECK(!FLAG_enable_third_party_heap); + int max_aligned_size; + if (!EnsureAllocation(size_in_bytes, kTaggedAligned, origin, + &max_aligned_size)) { + return AllocationResult::Failure(); + } + + DCHECK_EQ(max_aligned_size, size_in_bytes); + DCHECK_LE(allocation_info_->start(), allocation_info_->top()); + + AllocationResult result = AllocateFastUnaligned(size_in_bytes, origin); + DCHECK(!result.IsFailure()); + + InvokeAllocationObservers(result.ToAddress(), size_in_bytes, size_in_bytes, + size_in_bytes); + + return result; +} + +AllocationResult SpaceWithLinearArea::AllocateRawAligned( + int size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin) { + DCHECK(!FLAG_enable_third_party_heap); + int max_aligned_size; + if (!EnsureAllocation(size_in_bytes, alignment, origin, &max_aligned_size)) { + return AllocationResult::Failure(); + } + + DCHECK_GE(max_aligned_size, size_in_bytes); + DCHECK_LE(allocation_info_->start(), allocation_info_->top()); + + int aligned_size_in_bytes; + + AllocationResult result = AllocateFastAligned( + size_in_bytes, &aligned_size_in_bytes, alignment, origin); + DCHECK_GE(max_aligned_size, aligned_size_in_bytes); + DCHECK(!result.IsFailure()); + + InvokeAllocationObservers(result.ToAddress(), size_in_bytes, + aligned_size_in_bytes, max_aligned_size); + + return result; +} + +AllocationResult SpaceWithLinearArea::AllocateRawSlow( + int size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin) { + AllocationResult result = + USE_ALLOCATION_ALIGNMENT_BOOL && alignment != kTaggedAligned + ? AllocateRawAligned(size_in_bytes, alignment, origin) + : AllocateRawUnaligned(size_in_bytes, origin); + return result; +} + } // namespace internal } // namespace v8 |