Commit defa678e authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

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: 's avatarOmer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83279}
parent f81d0ca6
......@@ -52,6 +52,7 @@ namespace internal {
V(MarkVisitCrossThreadPersistents) \
V(MarkVisitStack) \
V(MarkVisitRememberedSets) \
V(SweepFinishIfOutOfWork) \
V(SweepInvokePreFinalizers) \
V(SweepIdleStep) \
V(SweepInTask) \
......
......@@ -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,7 +893,19 @@ 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();
NotifyDone();
}
}
}
......
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