diff --git a/src/heap/new-spaces.cc b/src/heap/new-spaces.cc index e8bf8b7a51..df08a18ac6 100644 --- a/src/heap/new-spaces.cc +++ b/src/heap/new-spaces.cc @@ -476,7 +476,9 @@ NewSpace::NewSpace(Heap* heap, v8::PageAllocator* page_allocator, ResetLinearAllocationArea(); } -void NewSpace::TearDown() { +NewSpace::~NewSpace() { + // Tears down the space. Heap memory was not allocated by the space, so it + // is not deallocated here. allocation_info_->Reset(kNullAddress, kNullAddress); to_space_.TearDown(); diff --git a/src/heap/new-spaces.h b/src/heap/new-spaces.h index b31dfa28e4..60a10bae82 100644 --- a/src/heap/new-spaces.h +++ b/src/heap/new-spaces.h @@ -249,16 +249,12 @@ class V8_EXPORT_PRIVATE NewSpace size_t initial_semispace_capacity, size_t max_semispace_capacity, LinearAllocationArea* allocation_info); - ~NewSpace() override { TearDown(); } + ~NewSpace() override; inline bool ContainsSlow(Address a) const; inline bool Contains(Object o) const; inline bool Contains(HeapObject o) const; - // Tears down the space. Heap memory was not allocated by the space, so it - // is not deallocated here. - void TearDown(); - void ResetParkedAllocationBuffers(); // Flip the pair of spaces. diff --git a/test/cctest/heap/test-spaces.cc b/test/cctest/heap/test-spaces.cc index 4c01c990ef..37261c4cc0 100644 --- a/test/cctest/heap/test-spaces.cc +++ b/test/cctest/heap/test-spaces.cc @@ -27,6 +27,8 @@ #include +#include + #include "include/v8-initialization.h" #include "include/v8-platform.h" #include "src/base/bounded-page-allocator.h" @@ -275,18 +277,19 @@ TEST(NewSpace) { MemoryAllocator* memory_allocator = test_allocator_scope.allocator(); LinearAllocationArea allocation_info; - NewSpace new_space(heap, memory_allocator->data_page_allocator(), - CcTest::heap()->InitialSemiSpaceSize(), - CcTest::heap()->InitialSemiSpaceSize(), &allocation_info); - CHECK(new_space.MaximumCapacity()); + std::unique_ptr new_space = std::make_unique( + heap, memory_allocator->data_page_allocator(), + CcTest::heap()->InitialSemiSpaceSize(), + CcTest::heap()->InitialSemiSpaceSize(), &allocation_info); + CHECK(new_space->MaximumCapacity()); - while (new_space.Available() >= kMaxRegularHeapObjectSize) { - CHECK(new_space.Contains( - new_space.AllocateRaw(kMaxRegularHeapObjectSize, kTaggedAligned) + while (new_space->Available() >= kMaxRegularHeapObjectSize) { + CHECK(new_space->Contains( + new_space->AllocateRaw(kMaxRegularHeapObjectSize, kTaggedAligned) .ToObjectChecked())); } - new_space.TearDown(); + new_space.reset(); memory_allocator->unmapper()->EnsureUnmappingCompleted(); }