Commit 6adf7e82 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Fix PrepareForSweepVisitor

The visitor was removing pages while at the same time iterating them on
NormalPagedSpace.

Removing all pages at once is safe and should also be faster.

Bug: chromium:1056170
Change-Id: I56eedf6f09498f126cb09238e01962b48e75b657
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2190427Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67687}
parent f640aea2
...@@ -26,6 +26,12 @@ void BaseSpace::RemovePage(BasePage* page) { ...@@ -26,6 +26,12 @@ void BaseSpace::RemovePage(BasePage* page) {
pages_.erase(it); pages_.erase(it);
} }
BaseSpace::Pages BaseSpace::RemoveAllPages() {
Pages pages = std::move(pages_);
pages_.clear();
return pages;
}
NormalPageSpace::NormalPageSpace(RawHeap* heap, size_t index) NormalPageSpace::NormalPageSpace(RawHeap* heap, size_t index)
: BaseSpace(heap, index, PageType::kNormal) {} : BaseSpace(heap, index, PageType::kNormal) {}
......
...@@ -44,6 +44,7 @@ class V8_EXPORT_PRIVATE BaseSpace { ...@@ -44,6 +44,7 @@ class V8_EXPORT_PRIVATE BaseSpace {
// Page manipulation functions. // Page manipulation functions.
void AddPage(BasePage*); void AddPage(BasePage*);
void RemovePage(BasePage*); void RemovePage(BasePage*);
Pages RemoveAllPages();
protected: protected:
enum class PageType { kNormal, kLarge }; enum class PageType { kNormal, kLarge };
......
...@@ -37,7 +37,7 @@ void* ObjectAllocator::AllocateObject(size_t size, GCInfoIndex gcinfo, ...@@ -37,7 +37,7 @@ void* ObjectAllocator::AllocateObject(size_t size, GCInfoIndex gcinfo,
} }
// static // static
inline RawHeap::RegularSpaceType ObjectAllocator::GetInitialSpaceIndexForSize( RawHeap::RegularSpaceType ObjectAllocator::GetInitialSpaceIndexForSize(
size_t size) { size_t size) {
if (size < 64) { if (size < 64) {
if (size < 32) return RawHeap::RegularSpaceType::kNormal1; if (size < 32) return RawHeap::RegularSpaceType::kNormal1;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "src/heap/cppgc/free-list.h" #include "src/heap/cppgc/free-list.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap-object-header-inl.h" #include "src/heap/cppgc/heap-object-header-inl.h"
#include "src/heap/cppgc/heap-object-header.h" #include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/heap-page.h" #include "src/heap/cppgc/heap-page.h"
...@@ -80,26 +81,17 @@ class PrepareForSweepVisitor final ...@@ -80,26 +81,17 @@ class PrepareForSweepVisitor final
bool VisitNormalPageSpace(NormalPageSpace* space) { bool VisitNormalPageSpace(NormalPageSpace* space) {
space->ResetLinearAllocationBuffer(); space->ResetLinearAllocationBuffer();
space->free_list().Clear(); space->free_list().Clear();
return false; (*states_)[space->index()].unswept_pages = space->RemoveAllPages();
}
bool VisitNormalPage(NormalPage* page) {
MovePageToSweeper(page);
return true; return true;
} }
bool VisitLargePage(LargePage* page) { bool VisitLargePageSpace(LargePageSpace* space) {
MovePageToSweeper(page); (*states_)[space->index()].unswept_pages = space->RemoveAllPages();
return true; return true;
} }
private: private:
void MovePageToSweeper(BasePage* page) {
BaseSpace* space = page->space();
space->RemovePage(page);
(*states_)[space->index()].unswept_pages.push_back(page);
}
SpaceStates* states_; SpaceStates* states_;
}; };
......
...@@ -156,6 +156,18 @@ TEST_F(SweeperTest, SweepObjectsOnAllArenas) { ...@@ -156,6 +156,18 @@ TEST_F(SweeperTest, SweepObjectsOnAllArenas) {
EXPECT_EQ(5u, g_destructor_callcount); EXPECT_EQ(5u, g_destructor_callcount);
} }
TEST_F(SweeperTest, SweepMultiplePagesInSingleSpace) {
MakeGarbageCollected<GCed<2 * kLargeObjectSizeThreshold>>(GetHeap());
MakeGarbageCollected<GCed<2 * kLargeObjectSizeThreshold>>(GetHeap());
MakeGarbageCollected<GCed<2 * kLargeObjectSizeThreshold>>(GetHeap());
EXPECT_EQ(0u, g_destructor_callcount);
Sweep();
EXPECT_EQ(3u, g_destructor_callcount);
}
TEST_F(SweeperTest, CoalesceFreeListEntries) { TEST_F(SweeperTest, CoalesceFreeListEntries) {
constexpr size_t kObjectSize = 32; constexpr size_t kObjectSize = 32;
using Type = GCed<kObjectSize>; using Type = GCed<kObjectSize>;
......
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