Commit f6960c0a authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Move semantics for LocalAllocationBuffer

Implement move semantics for the LocalAllocationBuffer as noted in
the comments. Also moved Close() invocation out of the assignment
operator and renamed it to CloseWithFiller().

Bug: v8:10315
Change-Id: Idc36fb7923e1f8857c05ec5d5110fa16087b07e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2170087Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67428}
parent 1fb1db17
......@@ -10,6 +10,7 @@
#include "src/heap/heap.h"
#include "src/heap/spaces-inl.h"
#include "src/heap/spaces.h"
#include "src/objects/heap-object.h"
namespace v8 {
......@@ -54,21 +55,20 @@ AllocationResult ConcurrentAllocator::AllocateInLab(
}
bool ConcurrentAllocator::EnsureLab(AllocationOrigin origin) {
LocalAllocationBuffer saved_lab = lab_;
auto result = space_->SlowGetLinearAllocationAreaBackground(
kLabSize, kMaxLabSize, kWordAligned, origin);
if (!result) return false;
HeapObject object = HeapObject::FromAddress(result->first);
LocalAllocationBuffer saved_lab = std::move(lab_);
lab_ = LocalAllocationBuffer::FromResult(
local_heap_->heap(), AllocationResult(object), result->second);
if (lab_.IsValid()) {
lab_.TryMerge(&saved_lab);
return true;
DCHECK(lab_.IsValid());
if (!lab_.TryMerge(&saved_lab)) {
saved_lab.CloseWithFiller();
}
lab_ = saved_lab;
return false;
return true;
}
} // namespace internal
......
......@@ -83,17 +83,19 @@ AllocationResult EvacuationAllocator::AllocateInLAB(
bool EvacuationAllocator::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_;
if (result.IsRetry()) {
lab_allocation_will_fail_ = true;
return false;
}
LocalAllocationBuffer saved_lab = std::move(new_space_lab_);
new_space_lab_ = LocalAllocationBuffer::FromResult(heap_, result, kLabSize);
DCHECK(new_space_lab_.IsValid());
if (!new_space_lab_.TryMerge(&saved_lab)) {
saved_lab.CloseWithFiller();
}
return true;
}
AllocationResult EvacuationAllocator::AllocateInNewSpace(
......
......@@ -33,7 +33,7 @@ class EvacuationAllocator {
heap_->code_space()->MergeLocalSpace(compaction_spaces_.Get(CODE_SPACE));
// Give back remaining LAB space if this EvacuationAllocator's new space LAB
// sits right next to new space allocation top.
const LinearAllocationArea info = new_space_lab_.Close();
const LinearAllocationArea info = new_space_lab_.CloseWithFiller();
const Address top = new_space_->top();
if (info.limit() != kNullAddress && info.limit() == top) {
DCHECK_NE(info.top(), kNullAddress);
......
......@@ -2510,7 +2510,7 @@ bool SemiSpace::EnsureCurrentCapacity() {
return true;
}
LinearAllocationArea LocalAllocationBuffer::Close() {
LinearAllocationArea LocalAllocationBuffer::CloseWithFiller() {
if (IsValid()) {
heap_->CreateFillerObjectAt(
allocation_info_.top(),
......@@ -2535,22 +2535,17 @@ LocalAllocationBuffer::LocalAllocationBuffer(
}
}
LocalAllocationBuffer::LocalAllocationBuffer(const LocalAllocationBuffer& other)
LocalAllocationBuffer::LocalAllocationBuffer(LocalAllocationBuffer&& other)
V8_NOEXCEPT {
*this = other;
*this = std::move(other);
}
LocalAllocationBuffer& LocalAllocationBuffer::operator=(
const LocalAllocationBuffer& other) V8_NOEXCEPT {
Close();
LocalAllocationBuffer&& other) V8_NOEXCEPT {
heap_ = other.heap_;
allocation_info_ = other.allocation_info_;
// This is needed since we (a) cannot yet use move-semantics, and (b) want
// to make the use of the class easy by it as value and (c) implicitly call
// {Close} upon copy.
const_cast<LocalAllocationBuffer&>(other).allocation_info_.Reset(
kNullAddress, kNullAddress);
other.allocation_info_.Reset(kNullAddress, kNullAddress);
return *this;
}
......
......@@ -2186,13 +2186,15 @@ class LocalAllocationBuffer {
AllocationResult result,
intptr_t size);
~LocalAllocationBuffer() { Close(); }
~LocalAllocationBuffer() { CloseWithFiller(); }
// Convert to C++11 move-semantics once allowed by the style guide.
V8_EXPORT_PRIVATE LocalAllocationBuffer(const LocalAllocationBuffer& other)
LocalAllocationBuffer(const LocalAllocationBuffer& other) = delete;
V8_EXPORT_PRIVATE LocalAllocationBuffer(LocalAllocationBuffer&& other)
V8_NOEXCEPT;
LocalAllocationBuffer& operator=(const LocalAllocationBuffer& other) = delete;
V8_EXPORT_PRIVATE LocalAllocationBuffer& operator=(
const LocalAllocationBuffer& other) V8_NOEXCEPT;
LocalAllocationBuffer&& other) V8_NOEXCEPT;
V8_WARN_UNUSED_RESULT inline AllocationResult AllocateRawAligned(
int size_in_bytes, AllocationAlignment alignment);
......@@ -2206,7 +2208,7 @@ class LocalAllocationBuffer {
inline bool TryFreeLast(HeapObject object, int object_size);
// Close a LAB, effectively invalidating it. Returns the unused area.
V8_EXPORT_PRIVATE LinearAllocationArea Close();
V8_EXPORT_PRIVATE LinearAllocationArea CloseWithFiller();
private:
V8_EXPORT_PRIVATE LocalAllocationBuffer(
......
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