diff options
Diffstat (limited to 'deps/v8/src/heap/local-allocator.h')
-rw-r--r-- | deps/v8/src/heap/local-allocator.h | 98 |
1 files changed, 11 insertions, 87 deletions
diff --git a/deps/v8/src/heap/local-allocator.h b/deps/v8/src/heap/local-allocator.h index 4646a3783de..e84c7188c2d 100644 --- a/deps/v8/src/heap/local-allocator.h +++ b/deps/v8/src/heap/local-allocator.h @@ -41,95 +41,19 @@ class LocalAllocator { } } - AllocationResult Allocate(AllocationSpace space, int object_size, - AllocationAlignment alignment) { - switch (space) { - case NEW_SPACE: - return AllocateInNewSpace(object_size, alignment); - case OLD_SPACE: - return compaction_spaces_.Get(OLD_SPACE)->AllocateRaw(object_size, - alignment); - case CODE_SPACE: - return compaction_spaces_.Get(CODE_SPACE) - ->AllocateRaw(object_size, alignment); - default: - UNREACHABLE(); - break; - } - } - - void FreeLast(AllocationSpace space, HeapObject* object, int object_size) { - switch (space) { - case NEW_SPACE: - FreeLastInNewSpace(object, object_size); - return; - case OLD_SPACE: - FreeLastInOldSpace(object, object_size); - return; - default: - // Only new and old space supported. - UNREACHABLE(); - break; - } - } + inline AllocationResult Allocate(AllocationSpace space, int object_size, + AllocationAlignment alignment); + inline void FreeLast(AllocationSpace space, HeapObject* object, + int object_size); private: - AllocationResult AllocateInNewSpace(int object_size, - AllocationAlignment alignment) { - if (object_size > kMaxLabObjectSize) { - return new_space_->AllocateRawSynchronized(object_size, alignment); - } - return AllocateInLAB(object_size, alignment); - } - - inline bool NewLocalAllocationBuffer() { - if (lab_allocation_will_fail_) return false; - LocalAllocationBuffer saved_lab_ = new_space_lab_; - AllocationResult result = - new_space_->AllocateRawSynchronized(kLabSize, kWordAligned); - new_space_lab_ = LocalAllocationBuffer::FromResult(heap_, result, kLabSize); - if (new_space_lab_.IsValid()) { - new_space_lab_.TryMerge(&saved_lab_); - return true; - } - new_space_lab_ = saved_lab_; - lab_allocation_will_fail_ = true; - return false; - } - - AllocationResult AllocateInLAB(int object_size, - AllocationAlignment alignment) { - AllocationResult allocation; - if (!new_space_lab_.IsValid() && !NewLocalAllocationBuffer()) { - return AllocationResult::Retry(OLD_SPACE); - } - allocation = new_space_lab_.AllocateRawAligned(object_size, alignment); - if (allocation.IsRetry()) { - if (!NewLocalAllocationBuffer()) { - return AllocationResult::Retry(OLD_SPACE); - } else { - allocation = new_space_lab_.AllocateRawAligned(object_size, alignment); - CHECK(!allocation.IsRetry()); - } - } - return allocation; - } - - void FreeLastInNewSpace(HeapObject* object, int object_size) { - if (!new_space_lab_.TryFreeLast(object, object_size)) { - // We couldn't free the last object so we have to write a proper filler. - heap_->CreateFillerObjectAt(object->address(), object_size, - ClearRecordedSlots::kNo); - } - } - - void FreeLastInOldSpace(HeapObject* object, int object_size) { - if (!compaction_spaces_.Get(OLD_SPACE)->TryFreeLast(object, object_size)) { - // We couldn't free the last object so we have to write a proper filler. - heap_->CreateFillerObjectAt(object->address(), object_size, - ClearRecordedSlots::kNo); - } - } + inline AllocationResult AllocateInNewSpace(int object_size, + AllocationAlignment alignment); + inline bool NewLocalAllocationBuffer(); + inline AllocationResult AllocateInLAB(int object_size, + AllocationAlignment alignment); + inline void FreeLastInNewSpace(HeapObject* object, int object_size); + inline void FreeLastInOldSpace(HeapObject* object, int object_size); Heap* const heap_; NewSpace* const new_space_; |