| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/heap/memory-reducer.h" | 5 #include "src/heap/memory-reducer.h" |
| 6 | 6 |
| 7 #include "src/flags.h" | 7 #include "src/flags.h" |
| 8 #include "src/heap/heap.h" | 8 #include "src/heap/heap.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 #include "src/v8.h" | 10 #include "src/v8.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 void MemoryReducer::NotifyTimer(const Event& event) { | 41 void MemoryReducer::NotifyTimer(const Event& event) { |
| 42 DCHECK_EQ(kTimer, event.type); | 42 DCHECK_EQ(kTimer, event.type); |
| 43 DCHECK_EQ(kWait, state_.action); | 43 DCHECK_EQ(kWait, state_.action); |
| 44 state_ = Step(state_, event); | 44 state_ = Step(state_, event); |
| 45 if (state_.action == kRun) { | 45 if (state_.action == kRun) { |
| 46 DCHECK(heap()->incremental_marking()->IsStopped()); | 46 DCHECK(heap()->incremental_marking()->IsStopped()); |
| 47 DCHECK(FLAG_incremental_marking); | 47 DCHECK(FLAG_incremental_marking); |
| 48 heap()->StartIdleIncrementalMarking(); |
| 48 if (FLAG_trace_gc_verbose) { | 49 if (FLAG_trace_gc_verbose) { |
| 49 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", | 50 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", |
| 50 state_.started_gcs); | 51 state_.started_gcs); |
| 51 } | 52 } |
| 52 if (heap()->ShouldOptimizeForMemoryUsage()) { | |
| 53 // Do full GC if memory usage has higher priority than latency. This is | |
| 54 // important for background tabs that do not send idle notifications. | |
| 55 heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask, | |
| 56 "memory reducer"); | |
| 57 } else { | |
| 58 heap()->StartIdleIncrementalMarking(); | |
| 59 } | |
| 60 } else if (state_.action == kWait) { | 53 } else if (state_.action == kWait) { |
| 61 if (!heap()->incremental_marking()->IsStopped() && | |
| 62 heap()->ShouldOptimizeForMemoryUsage()) { | |
| 63 // Make progress with pending incremental marking if memory usage has | |
| 64 // higher priority than latency. This is important for background tabs | |
| 65 // that do not send idle notifications. | |
| 66 const int kIncrementalMarkingDelayMs = 500; | |
| 67 double deadline = heap()->MonotonicallyIncreasingTimeInMs() + | |
| 68 kIncrementalMarkingDelayMs; | |
| 69 heap()->AdvanceIncrementalMarking( | |
| 70 0, deadline, i::IncrementalMarking::StepActions( | |
| 71 i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, | |
| 72 i::IncrementalMarking::FORCE_MARKING, | |
| 73 i::IncrementalMarking::FORCE_COMPLETION)); | |
| 74 heap()->FinalizeIncrementalMarkingIfComplete( | |
| 75 "Memory reducer: finalize incremental marking"); | |
| 76 } | |
| 77 // Re-schedule the timer. | 54 // Re-schedule the timer. |
| 78 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); | 55 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); |
| 79 if (FLAG_trace_gc_verbose) { | 56 if (FLAG_trace_gc_verbose) { |
| 80 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", | 57 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", |
| 81 state_.next_gc_start_ms - event.time_ms); | 58 state_.next_gc_start_ms - event.time_ms); |
| 82 } | 59 } |
| 83 } | 60 } |
| 84 } | 61 } |
| 85 | 62 |
| 86 | 63 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 auto timer_task = new MemoryReducer::TimerTask(this); | 196 auto timer_task = new MemoryReducer::TimerTask(this); |
| 220 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( | 197 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( |
| 221 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); | 198 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); |
| 222 } | 199 } |
| 223 | 200 |
| 224 | 201 |
| 225 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } | 202 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } |
| 226 | 203 |
| 227 } // internal | 204 } // internal |
| 228 } // v8 | 205 } // v8 |
| OLD | NEW |