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