diff --git a/src/heap/gc-idle-time-handler.cc b/src/heap/gc-idle-time-handler.cc index 92fb5530ef..bbc4c394af 100644 --- a/src/heap/gc-idle-time-handler.cc +++ b/src/heap/gc-idle-time-handler.cc @@ -27,7 +27,8 @@ void GCIdleTimeAction::Print() { PrintF("no action"); break; case DO_INCREMENTAL_MARKING: - PrintF("incremental marking with step %" V8_PTR_PREFIX "d", parameter); + PrintF("incremental marking with step %" V8_PTR_PREFIX "d / ms", + parameter); break; case DO_SCAVENGE: PrintF("scavenge"); @@ -250,7 +251,7 @@ GCIdleTimeAction GCIdleTimeHandler::Compute(double idle_time_in_ms, return GCIdleTimeAction::Nothing(); } size_t step_size = EstimateMarkingStepSize( - static_cast(idle_time_in_ms), + static_cast(kIncrementalMarkingStepTimeInMs), heap_state.incremental_marking_speed_in_bytes_per_ms); return GCIdleTimeAction::IncrementalMarking(step_size); } diff --git a/src/heap/gc-idle-time-handler.h b/src/heap/gc-idle-time-handler.h index 8dfe92d9f7..9b7f2b5997 100644 --- a/src/heap/gc-idle-time-handler.h +++ b/src/heap/gc-idle-time-handler.h @@ -125,6 +125,9 @@ class GCIdleTimeHandler { // If contexts are disposed at a higher rate a full gc is triggered. static const double kHighContextDisposalRate; + // Incremental marking step time. + static const size_t kIncrementalMarkingStepTimeInMs = 1; + class HeapState { public: void Print(); diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 8986087486..fa32764125 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -4489,12 +4489,18 @@ bool Heap::IdleNotification(double deadline_in_seconds) { if (incremental_marking()->IsStopped()) { incremental_marking()->Start(); } - incremental_marking()->Step(action.parameter, - IncrementalMarking::NO_GC_VIA_STACK_GUARD, - IncrementalMarking::FORCE_MARKING, - IncrementalMarking::DO_NOT_FORCE_COMPLETION); - double remaining_idle_time_in_ms = - deadline_in_ms - MonotonicallyIncreasingTimeInMs(); + double remaining_idle_time_in_ms = 0.0; + do { + incremental_marking()->Step( + action.parameter, IncrementalMarking::NO_GC_VIA_STACK_GUARD, + IncrementalMarking::FORCE_MARKING, + IncrementalMarking::DO_NOT_FORCE_COMPLETION); + remaining_idle_time_in_ms = + deadline_in_ms - MonotonicallyIncreasingTimeInMs(); + } while (remaining_idle_time_in_ms >= + 2.0 * GCIdleTimeHandler::kIncrementalMarkingStepTimeInMs && + !incremental_marking()->IsComplete() && + !mark_compact_collector_.marking_deque()->IsEmpty()); if (remaining_idle_time_in_ms > 0.0) { TryFinalizeIdleIncrementalMarking( remaining_idle_time_in_ms, heap_state.size_of_objects,