Commit 511400ca authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Reland "[heap] Perform more embedder tracing in incremental marking step"

This is a reland of 49de5875

Original change's description:
> [heap] Perform more embedder tracing in incremental marking step
> 
> This should fix GC latency regressions introduced in 4c6598.
> 
> Bug: chromium:926189, chromium:930844, chromium:930693,chromium:931629
> Change-Id: I81c91829badbeea82d6e44670d07794632869424
> Reviewed-on: https://chromium-review.googlesource.com/c/1477216
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#59668}

Bug: chromium:926189, chromium:930844, chromium:930693, chromium:931629
Change-Id: Ifa77647668bb052bb102b643182baf406cb9e059
Reviewed-on: https://chromium-review.googlesource.com/c/1477279Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59757}
parent 6f8bd2eb
......@@ -119,7 +119,7 @@ void IncrementalMarkingJob::Task::RunInternal() {
if (!incremental_marking->IsStopped()) {
StepResult step_result = Step(heap, stack_state_);
if (!incremental_marking->IsStopped()) {
job_->ScheduleTask(heap, step_result == StepResult::kDone
job_->ScheduleTask(heap, step_result == StepResult::kNoImmediateWork
? TaskType::kDelayed
: TaskType::kNormal);
}
......
......@@ -792,7 +792,7 @@ intptr_t IncrementalMarking::ProcessMarkingWorklist(
}
StepResult IncrementalMarking::EmbedderStep(double duration_ms) {
if (!ShouldDoEmbedderStep()) return StepResult::kDone;
if (!ShouldDoEmbedderStep()) return StepResult::kNoImmediateWork;
constexpr size_t kObjectsToProcessBeforeInterrupt = 500;
......@@ -819,7 +819,8 @@ StepResult IncrementalMarking::EmbedderStep(double duration_ms) {
} while (!empty_worklist &&
(heap_->MonotonicallyIncreasingTimeInMs() < deadline));
heap_->local_embedder_heap_tracer()->SetEmbedderWorklistEmpty(empty_worklist);
return empty_worklist ? StepResult::kDone : StepResult::kMoreWorkRemaining;
return empty_worklist ? StepResult::kNoImmediateWork
: StepResult::kMoreWorkRemaining;
}
void IncrementalMarking::Hurry() {
......@@ -975,9 +976,13 @@ void IncrementalMarking::ScheduleBytesToMarkBasedOnTime(double time_ms) {
namespace {
StepResult CombineStepResults(StepResult a, StepResult b) {
if (a == StepResult::kDone && b == StepResult::kDone)
return StepResult::kDone;
return StepResult::kMoreWorkRemaining;
if (a == StepResult::kMoreWorkRemaining ||
b == StepResult::kMoreWorkRemaining)
return StepResult::kMoreWorkRemaining;
if (a == StepResult::kWaitingForFinalization ||
b == StepResult::kWaitingForFinalization)
return StepResult::kWaitingForFinalization;
return StepResult::kNoImmediateWork;
}
} // anonymous namespace
......@@ -996,14 +1001,16 @@ StepResult IncrementalMarking::AdvanceWithDeadline(
double remaining_time_in_ms = 0.0;
StepResult result;
do {
StepResult embedder_result = EmbedderStep(kStepSizeInMs / 2);
StepResult v8_result =
V8Step(kStepSizeInMs / 2, completion_action, step_origin);
remaining_time_in_ms =
deadline_in_ms - heap()->MonotonicallyIncreasingTimeInMs();
StepResult embedder_result =
EmbedderStep(Min(kStepSizeInMs, remaining_time_in_ms));
result = CombineStepResults(v8_result, embedder_result);
remaining_time_in_ms =
deadline_in_ms - heap()->MonotonicallyIncreasingTimeInMs();
} while (remaining_time_in_ms > kStepSizeInMs && !IsComplete() &&
!marking_worklist()->IsEmpty() &&
} while (remaining_time_in_ms >= kStepSizeInMs &&
result == StepResult::kMoreWorkRemaining);
return result;
}
......@@ -1167,7 +1174,7 @@ StepResult IncrementalMarking::V8Step(double max_step_size_in_ms,
heap()->tracer()->IncrementalMarkingSpeedInBytesPerMillisecond());
bytes_to_process = Min(ComputeStepSizeInBytes(step_origin), max_step_size);
if (bytes_to_process == 0) {
result = StepResult::kDone;
result = StepResult::kNoImmediateWork;
}
bytes_processed =
......@@ -1176,15 +1183,17 @@ StepResult IncrementalMarking::V8Step(double max_step_size_in_ms,
bytes_marked_ += bytes_processed;
if (marking_worklist()->IsEmpty()) {
result = StepResult::kNoImmediateWork;
if (heap_->local_embedder_heap_tracer()
->ShouldFinalizeIncrementalMarking()) {
if (!finalize_marking_completed_) {
FinalizeMarking(action);
FastForwardSchedule();
result = StepResult::kMoreWorkRemaining;
result = StepResult::kWaitingForFinalization;
incremental_marking_job()->Start(heap_);
} else {
MarkingComplete(action);
result = StepResult::kWaitingForFinalization;
}
} else {
heap_->local_embedder_heap_tracer()->NotifyV8MarkingWorklistWasEmpty();
......
......@@ -20,7 +20,11 @@ class Object;
class PagedSpace;
enum class StepOrigin { kV8, kTask };
enum class StepResult { kDone, kMoreWorkRemaining };
enum class StepResult {
kNoImmediateWork,
kMoreWorkRemaining,
kWaitingForFinalization
};
class V8_EXPORT_PRIVATE IncrementalMarking {
public:
......
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