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 @@ ...@@ -10,6 +10,7 @@
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/heap/spaces-inl.h" #include "src/heap/spaces-inl.h"
#include "src/heap/spaces.h"
#include "src/objects/heap-object.h" #include "src/objects/heap-object.h"
namespace v8 { namespace v8 {
...@@ -54,21 +55,20 @@ AllocationResult ConcurrentAllocator::AllocateInLab( ...@@ -54,21 +55,20 @@ AllocationResult ConcurrentAllocator::AllocateInLab(
} }
bool ConcurrentAllocator::EnsureLab(AllocationOrigin origin) { bool ConcurrentAllocator::EnsureLab(AllocationOrigin origin) {
LocalAllocationBuffer saved_lab = lab_;
auto result = space_->SlowGetLinearAllocationAreaBackground( auto result = space_->SlowGetLinearAllocationAreaBackground(
kLabSize, kMaxLabSize, kWordAligned, origin); kLabSize, kMaxLabSize, kWordAligned, origin);
if (!result) return false; if (!result) return false;
HeapObject object = HeapObject::FromAddress(result->first); HeapObject object = HeapObject::FromAddress(result->first);
LocalAllocationBuffer saved_lab = std::move(lab_);
lab_ = LocalAllocationBuffer::FromResult( lab_ = LocalAllocationBuffer::FromResult(
local_heap_->heap(), AllocationResult(object), result->second); local_heap_->heap(), AllocationResult(object), result->second);
if (lab_.IsValid()) { DCHECK(lab_.IsValid());
lab_.TryMerge(&saved_lab); if (!lab_.TryMerge(&saved_lab)) {
return true; saved_lab.CloseWithFiller();
} }
lab_ = saved_lab; return true;
return false;
} }
} // namespace internal } // namespace internal
......
...@@ -83,17 +83,19 @@ AllocationResult EvacuationAllocator::AllocateInLAB( ...@@ -83,17 +83,19 @@ AllocationResult EvacuationAllocator::AllocateInLAB(
bool EvacuationAllocator::NewLocalAllocationBuffer() { bool EvacuationAllocator::NewLocalAllocationBuffer() {
if (lab_allocation_will_fail_) return false; if (lab_allocation_will_fail_) return false;
LocalAllocationBuffer saved_lab_ = new_space_lab_;
AllocationResult result = AllocationResult result =
new_space_->AllocateRawSynchronized(kLabSize, kWordAligned); new_space_->AllocateRawSynchronized(kLabSize, kWordAligned);
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); new_space_lab_ = LocalAllocationBuffer::FromResult(heap_, result, kLabSize);
if (new_space_lab_.IsValid()) { DCHECK(new_space_lab_.IsValid());
new_space_lab_.TryMerge(&saved_lab_); if (!new_space_lab_.TryMerge(&saved_lab)) {
return true; saved_lab.CloseWithFiller();
} }
new_space_lab_ = saved_lab_; return true;
lab_allocation_will_fail_ = true;
return false;
} }
AllocationResult EvacuationAllocator::AllocateInNewSpace( AllocationResult EvacuationAllocator::AllocateInNewSpace(
......
...@@ -33,7 +33,7 @@ class EvacuationAllocator { ...@@ -33,7 +33,7 @@ class EvacuationAllocator {
heap_->code_space()->MergeLocalSpace(compaction_spaces_.Get(CODE_SPACE)); heap_->code_space()->MergeLocalSpace(compaction_spaces_.Get(CODE_SPACE));
// Give back remaining LAB space if this EvacuationAllocator's new space LAB // Give back remaining LAB space if this EvacuationAllocator's new space LAB
// sits right next to new space allocation top. // 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(); const Address top = new_space_->top();
if (info.limit() != kNullAddress && info.limit() == top) { if (info.limit() != kNullAddress && info.limit() == top) {
DCHECK_NE(info.top(), kNullAddress); DCHECK_NE(info.top(), kNullAddress);
......
...@@ -2510,7 +2510,7 @@ bool SemiSpace::EnsureCurrentCapacity() { ...@@ -2510,7 +2510,7 @@ bool SemiSpace::EnsureCurrentCapacity() {
return true; return true;
} }
LinearAllocationArea LocalAllocationBuffer::Close() { LinearAllocationArea LocalAllocationBuffer::CloseWithFiller() {
if (IsValid()) { if (IsValid()) {
heap_->CreateFillerObjectAt( heap_->CreateFillerObjectAt(
allocation_info_.top(), allocation_info_.top(),
...@@ -2535,22 +2535,17 @@ LocalAllocationBuffer::LocalAllocationBuffer( ...@@ -2535,22 +2535,17 @@ LocalAllocationBuffer::LocalAllocationBuffer(
} }
} }
LocalAllocationBuffer::LocalAllocationBuffer(const LocalAllocationBuffer& other) LocalAllocationBuffer::LocalAllocationBuffer(LocalAllocationBuffer&& other)
V8_NOEXCEPT { V8_NOEXCEPT {
*this = other; *this = std::move(other);
} }
LocalAllocationBuffer& LocalAllocationBuffer::operator=( LocalAllocationBuffer& LocalAllocationBuffer::operator=(
const LocalAllocationBuffer& other) V8_NOEXCEPT { LocalAllocationBuffer&& other) V8_NOEXCEPT {
Close();
heap_ = other.heap_; heap_ = other.heap_;
allocation_info_ = other.allocation_info_; allocation_info_ = other.allocation_info_;
// This is needed since we (a) cannot yet use move-semantics, and (b) want other.allocation_info_.Reset(kNullAddress, kNullAddress);
// 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);
return *this; return *this;
} }
......
...@@ -2186,13 +2186,15 @@ class LocalAllocationBuffer { ...@@ -2186,13 +2186,15 @@ class LocalAllocationBuffer {
AllocationResult result, AllocationResult result,
intptr_t size); intptr_t size);
~LocalAllocationBuffer() { Close(); } ~LocalAllocationBuffer() { CloseWithFiller(); }
// Convert to C++11 move-semantics once allowed by the style guide. LocalAllocationBuffer(const LocalAllocationBuffer& other) = delete;
V8_EXPORT_PRIVATE LocalAllocationBuffer(const LocalAllocationBuffer& other) V8_EXPORT_PRIVATE LocalAllocationBuffer(LocalAllocationBuffer&& other)
V8_NOEXCEPT; V8_NOEXCEPT;
LocalAllocationBuffer& operator=(const LocalAllocationBuffer& other) = delete;
V8_EXPORT_PRIVATE LocalAllocationBuffer& operator=( V8_EXPORT_PRIVATE LocalAllocationBuffer& operator=(
const LocalAllocationBuffer& other) V8_NOEXCEPT; LocalAllocationBuffer&& other) V8_NOEXCEPT;
V8_WARN_UNUSED_RESULT inline AllocationResult AllocateRawAligned( V8_WARN_UNUSED_RESULT inline AllocationResult AllocateRawAligned(
int size_in_bytes, AllocationAlignment alignment); int size_in_bytes, AllocationAlignment alignment);
...@@ -2206,7 +2208,7 @@ class LocalAllocationBuffer { ...@@ -2206,7 +2208,7 @@ class LocalAllocationBuffer {
inline bool TryFreeLast(HeapObject object, int object_size); inline bool TryFreeLast(HeapObject object, int object_size);
// Close a LAB, effectively invalidating it. Returns the unused area. // Close a LAB, effectively invalidating it. Returns the unused area.
V8_EXPORT_PRIVATE LinearAllocationArea Close(); V8_EXPORT_PRIVATE LinearAllocationArea CloseWithFiller();
private: private:
V8_EXPORT_PRIVATE LocalAllocationBuffer( 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