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

This reverts commit 6d342fa52c.

Reason for revert: Needed to land:
https://crrev.com/c/3892788

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: Ieeb29454e146ee763130c0031af3f7a48b4eec94
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3895811
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Owners-Override: Michael Achenbach <machenbach@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83192}
This commit is contained in:
Michael Achenbach 2022-09-14 13:50:24 +00:00 committed by V8 LUCI CQ
parent 7096496aca
commit b4cd59c383
3 changed files with 26 additions and 40 deletions

View File

@ -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].get());
return static_cast<PagedSpace*>(space_[idx]);
}
Space* Heap::space(int idx) { return space_[idx].get(); }
Space* Heap::space(int idx) { return space_[idx]; }
Address* Heap::NewSpaceAllocationTopAddress() {
return new_space_ ? new_space_->allocation_top_address() : nullptr;

View File

@ -5368,6 +5368,10 @@ 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;
@ -5386,7 +5390,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());
DCHECK_NULL(space_[RO_SPACE].get());
space_[RO_SPACE] = nullptr;
read_only_space_ = ro_heap->read_only_space();
heap_allocator_.SetReadOnlySpace(read_only_space_);
}
@ -5429,49 +5433,30 @@ 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] = std::make_unique<PagedNewSpace>(
this, initial_semispace_size_, max_semi_space_size_,
space_[NEW_SPACE] = new_space_ =
new PagedNewSpace(this, initial_semispace_size_, max_semi_space_size_,
new_allocation_info);
} else {
space_[NEW_SPACE] = std::make_unique<SemiSpaceNewSpace>(
this, initial_semispace_size_, max_semi_space_size_,
new_allocation_info);
space_[NEW_SPACE] = new_space_ =
new SemiSpaceNewSpace(this, initial_semispace_size_,
max_semi_space_size_, new_allocation_info);
}
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_[NEW_LO_SPACE] = new_lo_space_ =
new NewLargeObjectSpace(this, NewSpaceCapacity());
}
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());
space_[OLD_SPACE] = old_space_ = new OldSpace(this, old_allocation_info);
space_[CODE_SPACE] = code_space_ = new CodeSpace(this);
if (v8_flags.use_map_space) {
space_[MAP_SPACE] = std::make_unique<MapSpace>(this);
map_space_ = static_cast<MapSpace*>(space_[MAP_SPACE].get());
space_[MAP_SPACE] = map_space_ = new MapSpace(this);
}
if (v8_flags.shared_space && isolate()->is_shared_space_isolate()) {
space_[SHARED_SPACE] = std::make_unique<SharedSpace>(this);
shared_space_ = static_cast<SharedSpace*>(space_[SHARED_SPACE].get());
space_[SHARED_SPACE] = shared_space_ = new SharedSpace(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());
space_[LO_SPACE] = lo_space_ = new OldLargeObjectSpace(this);
space_[CODE_LO_SPACE] = code_lo_space_ = new CodeLargeObjectSpace(this);
if (v8_flags.shared_space && isolate()->is_shared_space_isolate()) {
space_[SHARED_LO_SPACE] = std::make_unique<SharedLargeObjectSpace>(this);
shared_lo_space_ =
static_cast<SharedLargeObjectSpace*>(space_[SHARED_LO_SPACE].get());
space_[SHARED_LO_SPACE] = shared_lo_space_ =
new SharedLargeObjectSpace(this);
}
for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount);
@ -5878,7 +5863,8 @@ 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++) {
space_[i].reset();
delete space_[i];
space_[i] = nullptr;
}
}

View File

@ -2206,7 +2206,7 @@ class Heap {
std::unique_ptr<ConcurrentAllocator> shared_map_allocator_;
// Map from the space id to the space.
std::unique_ptr<Space> space_[LAST_SPACE + 1];
Space* space_[LAST_SPACE + 1];
LocalHeap* main_thread_local_heap_ = nullptr;