diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 296f2ad632..1b133d62f8 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -989,7 +989,14 @@ StepResult IncrementalMarking::AdvanceWithDeadline( void IncrementalMarking::FinalizeSweeping() { DCHECK(state_ == SWEEPING); - if (ContinueConcurrentSweeping()) return; + if (ContinueConcurrentSweeping()) { + if (FLAG_stress_incremental_marking) { + // To start concurrent marking a bit earlier, support concurrent sweepers + // from main thread by sweeping some pages. + SupportConcurrentSweeping(); + } + return; + } SafepointScope scope(heap()); collector_->EnsureSweepingCompleted(); @@ -1006,6 +1013,10 @@ bool IncrementalMarking::ContinueConcurrentSweeping() { collector_->sweeper()->AreSweeperTasksRunning(); } +void IncrementalMarking::SupportConcurrentSweeping() { + collector_->sweeper()->SupportConcurrentSweeping(); +} + size_t IncrementalMarking::StepSizeToKeepUpWithAllocations() { // Update bytes_allocated_ based on the allocation counter. size_t current_counter = heap_->OldGenerationAllocationCounter(); diff --git a/src/heap/incremental-marking.h b/src/heap/incremental-marking.h index 101240e945..c507c022a7 100644 --- a/src/heap/incremental-marking.h +++ b/src/heap/incremental-marking.h @@ -170,6 +170,7 @@ class V8_EXPORT_PRIVATE IncrementalMarking final { void FinalizeSweeping(); bool ContinueConcurrentSweeping(); + void SupportConcurrentSweeping(); StepResult Step(double max_step_size_in_ms, CompletionAction action, StepOrigin step_origin); diff --git a/src/heap/sweeper.cc b/src/heap/sweeper.cc index 40d9d01c5d..db5e347b0f 100644 --- a/src/heap/sweeper.cc +++ b/src/heap/sweeper.cc @@ -246,6 +246,13 @@ void Sweeper::EnsureCompleted() { sweeping_in_progress_ = false; } +void Sweeper::SupportConcurrentSweeping() { + ForAllSweepingSpaces([this](AllocationSpace space) { + const int kMaxPagesToSweepPerSpace = 1; + ParallelSweepSpace(space, 0, kMaxPagesToSweepPerSpace); + }); +} + bool Sweeper::AreSweeperTasksRunning() { return num_sweeping_tasks_ != 0; } V8_INLINE size_t Sweeper::FreeAndProcessFreedMemory( diff --git a/src/heap/sweeper.h b/src/heap/sweeper.h index 3bc199a92d..13428ec31c 100644 --- a/src/heap/sweeper.h +++ b/src/heap/sweeper.h @@ -108,6 +108,9 @@ class Sweeper { void EnsureCompleted(); bool AreSweeperTasksRunning(); + // Support concurrent sweepers from main thread + void SupportConcurrentSweeping(); + Page* GetSweptPageSafe(PagedSpace* space); void AddPageForIterability(Page* page);