Commit cf60ee8e authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

Reland "[heap] Use std::unique_ptr for space_ array"

This is a reland of commit 6d342fa5

Original change's description:
> [heap] Use std::unique_ptr for space_ array
>
> Document ownership with using std::unique_ptr<Space> for the space_
> array.
>
> Bug: v8:13267
> Change-Id: I12861d97cd52d2a8cf9ceb43a2f90008be87b2a3
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3890913
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#83187}

Bug: v8:13267
Change-Id: Idb25a656c4ba571d23132aa5e07cb13957c90f0b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3899121Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83259}
parent f321ada7
......@@ -172,10 +172,10 @@ void Heap::SetPendingOptimizeForTestBytecode(Object hash_table) {
PagedSpace* Heap::paged_space(int idx) {
DCHECK(idx == OLD_SPACE || idx == CODE_SPACE || idx == MAP_SPACE);
return static_cast<PagedSpace*>(space_[idx]);
return static_cast<PagedSpace*>(space_[idx].get());
}
Space* Heap::space(int idx) { return space_[idx]; }
Space* Heap::space(int idx) { return space_[idx].get(); }
Address* Heap::NewSpaceAllocationTopAddress() {
return new_space_ ? new_space_->allocation_top_address() : nullptr;
......
......@@ -5378,10 +5378,6 @@ void Heap::SetUp(LocalHeap* main_thread_local_heap) {
concurrent_marking_.reset(new ConcurrentMarking(this, nullptr));
}
for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
space_[i] = nullptr;
}
// Set up layout tracing callback.
if (V8_UNLIKELY(v8_flags.trace_gc_heap_layout)) {
v8::GCType gc_type = kGCTypeMarkSweepCompact;
......@@ -5400,7 +5396,7 @@ void Heap::SetUpFromReadOnlyHeap(ReadOnlyHeap* ro_heap) {
DCHECK_NOT_NULL(ro_heap);
DCHECK_IMPLIES(read_only_space_ != nullptr,
read_only_space_ == ro_heap->read_only_space());
space_[RO_SPACE] = nullptr;
DCHECK_NULL(space_[RO_SPACE].get());
read_only_space_ = ro_heap->read_only_space();
heap_allocator_.SetReadOnlySpace(read_only_space_);
}
......@@ -5443,30 +5439,49 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
const bool has_young_gen = !v8_flags.single_generation && !IsShared();
if (has_young_gen) {
if (v8_flags.minor_mc) {
space_[NEW_SPACE] = new_space_ =
new PagedNewSpace(this, initial_semispace_size_, max_semi_space_size_,
new_allocation_info);
space_[NEW_SPACE] = std::make_unique<PagedNewSpace>(
this, initial_semispace_size_, max_semi_space_size_,
new_allocation_info);
} else {
space_[NEW_SPACE] = new_space_ =
new SemiSpaceNewSpace(this, initial_semispace_size_,
max_semi_space_size_, new_allocation_info);
space_[NEW_SPACE] = std::make_unique<SemiSpaceNewSpace>(
this, initial_semispace_size_, max_semi_space_size_,
new_allocation_info);
}
space_[NEW_LO_SPACE] = new_lo_space_ =
new NewLargeObjectSpace(this, NewSpaceCapacity());
new_space_ = static_cast<NewSpace*>(space_[NEW_SPACE].get());
space_[NEW_LO_SPACE] =
std::make_unique<NewLargeObjectSpace>(this, NewSpaceCapacity());
new_lo_space_ =
static_cast<NewLargeObjectSpace*>(space_[NEW_LO_SPACE].get());
}
space_[OLD_SPACE] = old_space_ = new OldSpace(this, old_allocation_info);
space_[CODE_SPACE] = code_space_ = new CodeSpace(this);
space_[OLD_SPACE] = std::make_unique<OldSpace>(this, old_allocation_info);
old_space_ = static_cast<OldSpace*>(space_[OLD_SPACE].get());
space_[CODE_SPACE] = std::make_unique<CodeSpace>(this);
code_space_ = static_cast<CodeSpace*>(space_[CODE_SPACE].get());
if (v8_flags.use_map_space) {
space_[MAP_SPACE] = map_space_ = new MapSpace(this);
space_[MAP_SPACE] = std::make_unique<MapSpace>(this);
map_space_ = static_cast<MapSpace*>(space_[MAP_SPACE].get());
}
if (v8_flags.shared_space && isolate()->is_shared_space_isolate()) {
space_[SHARED_SPACE] = shared_space_ = new SharedSpace(this);
space_[SHARED_SPACE] = std::make_unique<SharedSpace>(this);
shared_space_ = static_cast<SharedSpace*>(space_[SHARED_SPACE].get());
}
space_[LO_SPACE] = lo_space_ = new OldLargeObjectSpace(this);
space_[CODE_LO_SPACE] = code_lo_space_ = new CodeLargeObjectSpace(this);
space_[LO_SPACE] = std::make_unique<OldLargeObjectSpace>(this);
lo_space_ = static_cast<OldLargeObjectSpace*>(space_[LO_SPACE].get());
space_[CODE_LO_SPACE] = std::make_unique<CodeLargeObjectSpace>(this);
code_lo_space_ =
static_cast<CodeLargeObjectSpace*>(space_[CODE_LO_SPACE].get());
if (v8_flags.shared_space && isolate()->is_shared_space_isolate()) {
space_[SHARED_LO_SPACE] = shared_lo_space_ =
new SharedLargeObjectSpace(this);
space_[SHARED_LO_SPACE] = std::make_unique<SharedLargeObjectSpace>(this);
shared_lo_space_ =
static_cast<SharedLargeObjectSpace*>(space_[SHARED_LO_SPACE].get());
}
for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount);
......@@ -5873,8 +5888,7 @@ void Heap::TearDown() {
"Deletion of CODE_SPACE and CODE_LO_SPACE requires write access to "
"Code page headers");
for (int i = FIRST_MUTABLE_SPACE; i <= LAST_MUTABLE_SPACE; i++) {
delete space_[i];
space_[i] = nullptr;
space_[i].reset();
}
}
......
......@@ -2210,7 +2210,7 @@ class Heap {
std::unique_ptr<ConcurrentAllocator> shared_map_allocator_;
// Map from the space id to the space.
Space* space_[LAST_SPACE + 1];
std::unique_ptr<Space> space_[LAST_SPACE + 1];
LocalHeap* main_thread_local_heap_ = nullptr;
......
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