5 #ifndef V8_HEAP_LOCAL_ALLOCATOR_INL_H_ 6 #define V8_HEAP_LOCAL_ALLOCATOR_INL_H_ 8 #include "src/heap/local-allocator.h" 10 #include "src/heap/spaces-inl.h" 15 AllocationResult LocalAllocator::Allocate(AllocationSpace space,
17 AllocationAlignment alignment) {
20 return AllocateInNewSpace(object_size, alignment);
22 return compaction_spaces_.Get(OLD_SPACE)->AllocateRaw(object_size,
25 return compaction_spaces_.Get(CODE_SPACE)
26 ->AllocateRaw(object_size, alignment);
33 void LocalAllocator::FreeLast(AllocationSpace space, HeapObject*
object,
37 FreeLastInNewSpace(
object, object_size);
40 FreeLastInOldSpace(
object, object_size);
49 void LocalAllocator::FreeLastInNewSpace(HeapObject*
object,
int object_size) {
50 if (!new_space_lab_.TryFreeLast(
object, object_size)) {
52 heap_->CreateFillerObjectAt(object->address(), object_size,
53 ClearRecordedSlots::kNo);
57 void LocalAllocator::FreeLastInOldSpace(HeapObject*
object,
int object_size) {
58 if (!compaction_spaces_.Get(OLD_SPACE)->TryFreeLast(
object, object_size)) {
60 heap_->CreateFillerObjectAt(object->address(), object_size,
61 ClearRecordedSlots::kNo);
65 AllocationResult LocalAllocator::AllocateInLAB(
int object_size,
66 AllocationAlignment alignment) {
67 AllocationResult allocation;
68 if (!new_space_lab_.IsValid() && !NewLocalAllocationBuffer()) {
69 return AllocationResult::Retry(OLD_SPACE);
71 allocation = new_space_lab_.AllocateRawAligned(object_size, alignment);
72 if (allocation.IsRetry()) {
73 if (!NewLocalAllocationBuffer()) {
74 return AllocationResult::Retry(OLD_SPACE);
76 allocation = new_space_lab_.AllocateRawAligned(object_size, alignment);
77 CHECK(!allocation.IsRetry());
83 bool LocalAllocator::NewLocalAllocationBuffer() {
84 if (lab_allocation_will_fail_)
return false;
85 LocalAllocationBuffer saved_lab_ = new_space_lab_;
86 AllocationResult result =
87 new_space_->AllocateRawSynchronized(kLabSize, kWordAligned);
88 new_space_lab_ = LocalAllocationBuffer::FromResult(heap_, result, kLabSize);
89 if (new_space_lab_.IsValid()) {
90 new_space_lab_.TryMerge(&saved_lab_);
93 new_space_lab_ = saved_lab_;
94 lab_allocation_will_fail_ =
true;
98 AllocationResult LocalAllocator::AllocateInNewSpace(
99 int object_size, AllocationAlignment alignment) {
100 if (object_size > kMaxLabObjectSize) {
101 return new_space_->AllocateRawSynchronized(object_size, alignment);
103 return AllocateInLAB(object_size, alignment);
109 #endif // V8_HEAP_LOCAL_ALLOCATOR_INL_H_