Commit 54d07546 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] Unify LAB usage between Scavenger and MC

Scavenger and full MC now rely on the same allocation behavior for their
evacuation.

Bug: 
Change-Id: Iddb0affe171187308e5b77ab0d3cfa75211bd8b8
Reviewed-on: https://chromium-review.googlesource.com/575983Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46781}
parent 58ad0bbe
...@@ -20,11 +20,14 @@ class LocalAllocator { ...@@ -20,11 +20,14 @@ class LocalAllocator {
: heap_(heap), : heap_(heap),
new_space_(heap->new_space()), new_space_(heap->new_space()),
compaction_spaces_(heap), compaction_spaces_(heap),
new_space_lab_(LocalAllocationBuffer::InvalidBuffer()) {} new_space_lab_(LocalAllocationBuffer::InvalidBuffer()),
lab_allocation_will_fail_(false) {}
// Needs to be called from the main thread to finalize this LocalAllocator. // Needs to be called from the main thread to finalize this LocalAllocator.
void Finalize() { void Finalize() {
heap_->old_space()->MergeCompactionSpace(compaction_spaces_.Get(OLD_SPACE)); heap_->old_space()->MergeCompactionSpace(compaction_spaces_.Get(OLD_SPACE));
heap_->code_space()->MergeCompactionSpace(
compaction_spaces_.Get(CODE_SPACE));
// Give back remaining LAB space if this LocalAllocator's new space LAB // Give back remaining LAB space if this LocalAllocator's new space LAB
// sits right next to new space allocation top. // sits right next to new space allocation top.
const AllocationInfo info = new_space_lab_.Close(); const AllocationInfo info = new_space_lab_.Close();
...@@ -35,16 +38,18 @@ class LocalAllocator { ...@@ -35,16 +38,18 @@ class LocalAllocator {
} }
} }
template <AllocationSpace space> AllocationResult Allocate(AllocationSpace space, int object_size,
AllocationResult Allocate(int object_size, AllocationAlignment alignment) { AllocationAlignment alignment) {
switch (space) { switch (space) {
case NEW_SPACE: case NEW_SPACE:
return AllocateInNewSpace(object_size, alignment); return AllocateInNewSpace(object_size, alignment);
case OLD_SPACE: case OLD_SPACE:
return compaction_spaces_.Get(OLD_SPACE)->AllocateRaw(object_size, return compaction_spaces_.Get(OLD_SPACE)->AllocateRaw(object_size,
alignment); alignment);
case CODE_SPACE:
return compaction_spaces_.Get(CODE_SPACE)
->AllocateRaw(object_size, alignment);
default: default:
// Only new and old space supported.
UNREACHABLE(); UNREACHABLE();
break; break;
} }
...@@ -60,6 +65,7 @@ class LocalAllocator { ...@@ -60,6 +65,7 @@ class LocalAllocator {
} }
inline bool NewLocalAllocationBuffer() { inline bool NewLocalAllocationBuffer() {
if (lab_allocation_will_fail_) return false;
LocalAllocationBuffer saved_lab_ = new_space_lab_; LocalAllocationBuffer saved_lab_ = new_space_lab_;
AllocationResult result = AllocationResult result =
new_space_->AllocateRawSynchronized(kLabSize, kWordAligned); new_space_->AllocateRawSynchronized(kLabSize, kWordAligned);
...@@ -68,6 +74,8 @@ class LocalAllocator { ...@@ -68,6 +74,8 @@ class LocalAllocator {
new_space_lab_.TryMerge(&saved_lab_); new_space_lab_.TryMerge(&saved_lab_);
return true; return true;
} }
new_space_lab_ = saved_lab_;
lab_allocation_will_fail_ = true;
return false; return false;
} }
...@@ -93,6 +101,7 @@ class LocalAllocator { ...@@ -93,6 +101,7 @@ class LocalAllocator {
NewSpace* const new_space_; NewSpace* const new_space_;
CompactionSpaceCollection compaction_spaces_; CompactionSpaceCollection compaction_spaces_;
LocalAllocationBuffer new_space_lab_; LocalAllocationBuffer new_space_lab_;
bool lab_allocation_will_fail_;
}; };
} // namespace internal } // namespace internal
......
This diff is collapsed.
...@@ -60,7 +60,7 @@ bool Scavenger::SemiSpaceCopyObject(Map* map, HeapObject** slot, ...@@ -60,7 +60,7 @@ bool Scavenger::SemiSpaceCopyObject(Map* map, HeapObject** slot,
DCHECK(heap()->AllowedToBeMigrated(object, NEW_SPACE)); DCHECK(heap()->AllowedToBeMigrated(object, NEW_SPACE));
AllocationAlignment alignment = object->RequiredAlignment(); AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = AllocationResult allocation =
allocator_.Allocate<NEW_SPACE>(object_size, alignment); allocator_.Allocate(NEW_SPACE, object_size, alignment);
HeapObject* target = nullptr; HeapObject* target = nullptr;
if (allocation.To(&target)) { if (allocation.To(&target)) {
...@@ -80,7 +80,7 @@ bool Scavenger::PromoteObject(Map* map, HeapObject** slot, HeapObject* object, ...@@ -80,7 +80,7 @@ bool Scavenger::PromoteObject(Map* map, HeapObject** slot, HeapObject* object,
int object_size) { int object_size) {
AllocationAlignment alignment = object->RequiredAlignment(); AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = AllocationResult allocation =
allocator_.Allocate<OLD_SPACE>(object_size, alignment); allocator_.Allocate(OLD_SPACE, object_size, alignment);
HeapObject* target = nullptr; HeapObject* target = nullptr;
if (allocation.To(&target)) { if (allocation.To(&target)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment