diff options
Diffstat (limited to 'deps/v8/src/heap/memory-reducer.cc')
-rw-r--r-- | deps/v8/src/heap/memory-reducer.cc | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/deps/v8/src/heap/memory-reducer.cc b/deps/v8/src/heap/memory-reducer.cc index 25378b5911..45d6bd3d7f 100644 --- a/deps/v8/src/heap/memory-reducer.cc +++ b/deps/v8/src/heap/memory-reducer.cc @@ -5,7 +5,8 @@ #include "src/heap/memory-reducer.h" #include "src/flags.h" -#include "src/heap/heap.h" +#include "src/heap/gc-tracer.h" +#include "src/heap/heap-inl.h" #include "src/utils.h" #include "src/v8.h" @@ -45,12 +46,35 @@ void MemoryReducer::NotifyTimer(const Event& event) { if (state_.action == kRun) { DCHECK(heap()->incremental_marking()->IsStopped()); DCHECK(FLAG_incremental_marking); - heap()->StartIdleIncrementalMarking(); if (FLAG_trace_gc_verbose) { PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", state_.started_gcs); } + if (heap()->ShouldOptimizeForMemoryUsage()) { + // Do full GC if memory usage has higher priority than latency. This is + // important for background tabs that do not send idle notifications. + heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask, + "memory reducer"); + } else { + heap()->StartIdleIncrementalMarking(); + } } else if (state_.action == kWait) { + if (!heap()->incremental_marking()->IsStopped() && + heap()->ShouldOptimizeForMemoryUsage()) { + // Make progress with pending incremental marking if memory usage has + // higher priority than latency. This is important for background tabs + // that do not send idle notifications. + const int kIncrementalMarkingDelayMs = 500; + double deadline = heap()->MonotonicallyIncreasingTimeInMs() + + kIncrementalMarkingDelayMs; + heap()->incremental_marking()->AdvanceIncrementalMarking( + 0, deadline, i::IncrementalMarking::StepActions( + i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, + i::IncrementalMarking::FORCE_MARKING, + i::IncrementalMarking::FORCE_COMPLETION)); + heap()->FinalizeIncrementalMarkingIfComplete( + "Memory reducer: finalize incremental marking"); + } // Re-schedule the timer. ScheduleTimer(state_.next_gc_start_ms - event.time_ms); if (FLAG_trace_gc_verbose) { |