Commit 93c7ffa3 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Refactor Sweeper initialization.

Sweeper cannot assume that platform never changes, so that we can
support using testing-specific platforms.
Instead, the sweeper gets the current platform from HeapBase on sweeping
start. The platform is set to nullptr whenever sweeping is not active.

Bug: chromium:1056170
Change-Id: I749e1dbfa204635fbb446a8c383aaa2548a717be
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2767139Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73486}
parent b49d7721
...@@ -77,7 +77,7 @@ HeapBase::HeapBase( ...@@ -77,7 +77,7 @@ HeapBase::HeapBase(
compactor_(raw_heap_), compactor_(raw_heap_),
object_allocator_(&raw_heap_, page_backend_.get(), object_allocator_(&raw_heap_, page_backend_.get(),
stats_collector_.get()), stats_collector_.get()),
sweeper_(&raw_heap_, platform_.get(), stats_collector_.get()), sweeper_(*this),
stack_support_(stack_support) { stack_support_(stack_support) {
stats_collector_->RegisterObserver( stats_collector_->RegisterObserver(
&allocation_observer_for_PROCESS_HEAP_STATISTICS_); &allocation_observer_for_PROCESS_HEAP_STATISTICS_);
......
...@@ -531,25 +531,24 @@ class PrepareForSweepVisitor final ...@@ -531,25 +531,24 @@ class PrepareForSweepVisitor final
class Sweeper::SweeperImpl final { class Sweeper::SweeperImpl final {
public: public:
SweeperImpl(RawHeap* heap, cppgc::Platform* platform, SweeperImpl(RawHeap& heap, StatsCollector* stats_collector)
StatsCollector* stats_collector)
: heap_(heap), : heap_(heap),
stats_collector_(stats_collector), stats_collector_(stats_collector),
space_states_(heap->size()), space_states_(heap.size()) {}
platform_(platform) {}
~SweeperImpl() { CancelSweepers(); } ~SweeperImpl() { CancelSweepers(); }
void Start(SweepingConfig config) { void Start(SweepingConfig config, cppgc::Platform* platform) {
StatsCollector::EnabledScope stats_scope(heap_->heap()->stats_collector(), StatsCollector::EnabledScope stats_scope(stats_collector_,
StatsCollector::kAtomicSweep); StatsCollector::kAtomicSweep);
is_in_progress_ = true; is_in_progress_ = true;
platform_ = platform;
#if DEBUG #if DEBUG
// Verify bitmap for all spaces regardless of |compactable_space_handling|. // Verify bitmap for all spaces regardless of |compactable_space_handling|.
ObjectStartBitmapVerifier().Verify(heap_); ObjectStartBitmapVerifier().Verify(&heap_);
#endif #endif
PrepareForSweepVisitor(&space_states_, config.compactable_space_handling) PrepareForSweepVisitor(&space_states_, config.compactable_space_handling)
.Traverse(heap_); .Traverse(&heap_);
if (config.sweeping_type == SweepingConfig::SweepingType::kAtomic) { if (config.sweeping_type == SweepingConfig::SweepingType::kAtomic) {
Finish(); Finish();
...@@ -568,10 +567,10 @@ class Sweeper::SweeperImpl final { ...@@ -568,10 +567,10 @@ class Sweeper::SweeperImpl final {
// allocate new memory. // allocate new memory.
if (is_sweeping_on_mutator_thread_) return false; if (is_sweeping_on_mutator_thread_) return false;
StatsCollector::EnabledScope stats_scope(heap_->heap()->stats_collector(), StatsCollector::EnabledScope stats_scope(stats_collector_,
StatsCollector::kIncrementalSweep); StatsCollector::kIncrementalSweep);
StatsCollector::EnabledScope inner_scope( StatsCollector::EnabledScope inner_scope(
heap_->heap()->stats_collector(), StatsCollector::kSweepOnAllocation); stats_collector_, StatsCollector::kSweepOnAllocation);
MutatorThreadSweepingScope sweeping_in_progresss(*this); MutatorThreadSweepingScope sweeping_in_progresss(*this);
SpaceState& space_state = space_states_[space->index()]; SpaceState& space_state = space_states_[space->index()];
...@@ -607,8 +606,8 @@ class Sweeper::SweeperImpl final { ...@@ -607,8 +606,8 @@ class Sweeper::SweeperImpl final {
{ {
StatsCollector::EnabledScope stats_scope( StatsCollector::EnabledScope stats_scope(
heap_->heap()->stats_collector(), StatsCollector::kIncrementalSweep); stats_collector_, StatsCollector::kIncrementalSweep);
StatsCollector::EnabledScope inner_scope(heap_->heap()->stats_collector(), StatsCollector::EnabledScope inner_scope(stats_collector_,
StatsCollector::kSweepFinalize); StatsCollector::kSweepFinalize);
if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsValid() && if (concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsValid() &&
concurrent_sweeper_handle_->UpdatePriorityEnabled()) { concurrent_sweeper_handle_->UpdatePriorityEnabled()) {
...@@ -639,6 +638,7 @@ class Sweeper::SweeperImpl final { ...@@ -639,6 +638,7 @@ class Sweeper::SweeperImpl final {
void FinalizeSweep() { void FinalizeSweep() {
// Synchronize with the concurrent sweeper and call remaining finalizers. // Synchronize with the concurrent sweeper and call remaining finalizers.
SynchronizeAndFinalizeConcurrentSweeping(); SynchronizeAndFinalizeConcurrentSweeping();
platform_ = nullptr;
is_in_progress_ = false; is_in_progress_ = false;
notify_done_pending_ = true; notify_done_pending_ = true;
} }
...@@ -708,15 +708,14 @@ class Sweeper::SweeperImpl final { ...@@ -708,15 +708,14 @@ class Sweeper::SweeperImpl final {
bool sweep_complete; bool sweep_complete;
{ {
StatsCollector::EnabledScope stats_scope( StatsCollector::EnabledScope stats_scope(
sweeper_->heap_->heap()->stats_collector(), sweeper_->stats_collector_, StatsCollector::kIncrementalSweep);
StatsCollector::kIncrementalSweep);
MutatorThreadSweeper sweeper(&sweeper_->space_states_, MutatorThreadSweeper sweeper(&sweeper_->space_states_,
sweeper_->platform_); sweeper_->platform_);
{ {
StatsCollector::EnabledScope stats_scope( StatsCollector::EnabledScope stats_scope(
sweeper_->heap_->heap()->stats_collector(), sweeper_->stats_collector_, StatsCollector::kSweepIdleStep,
StatsCollector::kSweepIdleStep, "idleDeltaInSeconds", "idleDeltaInSeconds",
(deadline_in_seconds - (deadline_in_seconds -
sweeper_->platform_->MonotonicallyIncreasingTime())); sweeper_->platform_->MonotonicallyIncreasingTime()));
...@@ -752,7 +751,7 @@ class Sweeper::SweeperImpl final { ...@@ -752,7 +751,7 @@ class Sweeper::SweeperImpl final {
concurrent_sweeper_handle_ = platform_->PostJob( concurrent_sweeper_handle_ = platform_->PostJob(
cppgc::TaskPriority::kUserVisible, cppgc::TaskPriority::kUserVisible,
std::make_unique<ConcurrentSweepTask>(*heap_->heap(), &space_states_)); std::make_unique<ConcurrentSweepTask>(*heap_.heap(), &space_states_));
} }
void CancelSweepers() { void CancelSweepers() {
...@@ -768,8 +767,8 @@ class Sweeper::SweeperImpl final { ...@@ -768,8 +767,8 @@ class Sweeper::SweeperImpl final {
finalizer.FinalizeHeap(&space_states_); finalizer.FinalizeHeap(&space_states_);
} }
RawHeap* heap_; RawHeap& heap_;
StatsCollector* stats_collector_; StatsCollector* const stats_collector_;
SpaceStates space_states_; SpaceStates space_states_;
cppgc::Platform* platform_; cppgc::Platform* platform_;
IncrementalSweepTask::Handle incremental_sweeper_handle_; IncrementalSweepTask::Handle incremental_sweeper_handle_;
...@@ -782,13 +781,16 @@ class Sweeper::SweeperImpl final { ...@@ -782,13 +781,16 @@ class Sweeper::SweeperImpl final {
bool is_sweeping_on_mutator_thread_ = false; bool is_sweeping_on_mutator_thread_ = false;
}; };
Sweeper::Sweeper(RawHeap* heap, cppgc::Platform* platform, Sweeper::Sweeper(HeapBase& heap)
StatsCollector* stats_collector) : heap_(heap),
: impl_(std::make_unique<SweeperImpl>(heap, platform, stats_collector)) {} impl_(std::make_unique<SweeperImpl>(heap.raw_heap(),
heap.stats_collector())) {}
Sweeper::~Sweeper() = default; Sweeper::~Sweeper() = default;
void Sweeper::Start(SweepingConfig config) { impl_->Start(config); } void Sweeper::Start(SweepingConfig config) {
impl_->Start(config, heap_.platform());
}
void Sweeper::FinishIfRunning() { impl_->FinishIfRunning(); } void Sweeper::FinishIfRunning() { impl_->FinishIfRunning(); }
void Sweeper::WaitForConcurrentSweepingForTesting() { void Sweeper::WaitForConcurrentSweepingForTesting() {
impl_->WaitForConcurrentSweepingForTesting(); impl_->WaitForConcurrentSweepingForTesting();
......
...@@ -16,8 +16,7 @@ class Platform; ...@@ -16,8 +16,7 @@ class Platform;
namespace internal { namespace internal {
class StatsCollector; class HeapBase;
class RawHeap;
class ConcurrentSweeperTest; class ConcurrentSweeperTest;
class NormalPageSpace; class NormalPageSpace;
...@@ -32,7 +31,7 @@ class V8_EXPORT_PRIVATE Sweeper final { ...@@ -32,7 +31,7 @@ class V8_EXPORT_PRIVATE Sweeper final {
CompactableSpaceHandling::kSweep; CompactableSpaceHandling::kSweep;
}; };
Sweeper(RawHeap*, cppgc::Platform*, StatsCollector*); explicit Sweeper(HeapBase&);
~Sweeper(); ~Sweeper();
Sweeper(const Sweeper&) = delete; Sweeper(const Sweeper&) = delete;
...@@ -54,6 +53,8 @@ class V8_EXPORT_PRIVATE Sweeper final { ...@@ -54,6 +53,8 @@ class V8_EXPORT_PRIVATE Sweeper final {
void WaitForConcurrentSweepingForTesting(); void WaitForConcurrentSweepingForTesting();
class SweeperImpl; class SweeperImpl;
HeapBase& heap_;
std::unique_ptr<SweeperImpl> impl_; std::unique_ptr<SweeperImpl> impl_;
friend class ConcurrentSweeperTest; friend class ConcurrentSweeperTest;
......
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