Reland "cppgc: Be more conservative in Seeper::FinishIfOutOfWork"

This is a reland of commit defa678e8b

Original change's description:
> cppgc: Be more conservative in Seeper::FinishIfOutOfWork
>
> Finalizing sweeping can be beneficial to truly end a GC cylce. We
> should only finalize in `FinishIfOutOfWork()` though if that would not
> introduce any jank. Limit the amount of executing finalizers in that
> scenario.
>
> Bug: v8:13294
> Change-Id: I0237f6b6017d444c457923d83e85147c58586445
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3902222
> Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
> Reviewed-by: Omer Katz <omerkatz@chromium.org>
> Reviewed-by: Anton Bikineev <bikineev@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#83279}

Bug: v8:13294
Change-Id: I426a54785d1a0f569c2200156dcf41a5d5c7876f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3902583
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83316}
This commit is contained in:
Michael Lippautz 2022-09-19 11:30:41 +02:00 committed by V8 LUCI CQ
parent 354f4f0858
commit 19f6eda366
2 changed files with 18 additions and 3 deletions

View File

@ -52,6 +52,7 @@ namespace internal {
V(MarkVisitCrossThreadPersistents) \
V(MarkVisitStack) \
V(MarkVisitRememberedSets) \
V(SweepFinishIfOutOfWork) \
V(SweepInvokePreFinalizers) \
V(SweepIdleStep) \
V(SweepInTask) \

View File

@ -400,7 +400,7 @@ class SweepFinalizer final {
bool FinalizeSpaceWithDeadline(SpaceState* space_state,
double deadline_in_seconds) {
DCHECK(platform_);
static constexpr size_t kDeadlineCheckInterval = 8;
static constexpr size_t kDeadlineCheckInterval = 4;
size_t page_count = 1;
while (auto page_state = space_state->swept_unfinalized_pages.Pop()) {
@ -543,7 +543,7 @@ class MutatorThreadSweeper final : private HeapVisitor<MutatorThreadSweeper> {
private:
bool SweepSpaceWithDeadline(SpaceState* state, double deadline_in_seconds) {
static constexpr size_t kDeadlineCheckInterval = 8;
static constexpr size_t kDeadlineCheckInterval = 4;
size_t page_count = 1;
while (auto page = state->unswept_pages.Pop()) {
Traverse(**page);
@ -884,6 +884,8 @@ class Sweeper::SweeperImpl final {
if (is_in_progress_ && !is_sweeping_on_mutator_thread_ &&
concurrent_sweeper_handle_ && concurrent_sweeper_handle_->IsValid() &&
!concurrent_sweeper_handle_->IsActive()) {
StatsCollector::EnabledScope stats_scope(
stats_collector_, StatsCollector::kSweepFinishIfOutOfWork);
// At this point we know that the concurrent sweeping task has run
// out-of-work: all pages are swept. The main thread still needs to finish
// sweeping though.
@ -891,9 +893,21 @@ class Sweeper::SweeperImpl final {
[](const SpaceState& state) {
return state.unswept_pages.IsEmpty();
}));
FinishIfRunning();
// There may be unfinalized pages left. Since it's hard to estimate
// the actual amount of sweeping necessary, we sweep with a small
// deadline to see if sweeping can be fully finished.
MutatorThreadSweeper sweeper(heap_.heap(), &space_states_, platform_,
config_.free_memory_handling);
const double deadline =
platform_->MonotonicallyIncreasingTime() +
v8::base::TimeDelta::FromMilliseconds(2).InSecondsF();
if (sweeper.SweepWithDeadline(deadline)) {
FinalizeSweep();
}
}
NotifyDoneIfNeeded();
}
void Finish() {
DCHECK(is_in_progress_);