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 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 void MemoryReducer::NotifyTimer(const Event& event) { | 38 void MemoryReducer::NotifyTimer(const Event& event) { |
39 DCHECK_EQ(kTimer, event.type); | 39 DCHECK_EQ(kTimer, event.type); |
40 DCHECK_EQ(kWait, state_.action); | 40 DCHECK_EQ(kWait, state_.action); |
41 state_ = Step(state_, event); | 41 state_ = Step(state_, event); |
42 if (state_.action == kRun) { | 42 if (state_.action == kRun) { |
43 DCHECK(heap()->incremental_marking()->IsStopped()); | 43 DCHECK(heap()->incremental_marking()->IsStopped()); |
44 DCHECK(FLAG_incremental_marking); | 44 DCHECK(FLAG_incremental_marking); |
45 heap()->StartIdleIncrementalMarking(); | |
46 if (FLAG_trace_gc_verbose) { | 45 if (FLAG_trace_gc_verbose) { |
47 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", | 46 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", |
48 state_.started_gcs); | 47 state_.started_gcs); |
49 } | 48 } |
| 49 if (heap()->ShouldOptimizeForMemoryUsage()) { |
| 50 // Do full GC if memory usage has higher priority than latency. This is |
| 51 // important for background tabs that do not send idle notifications. |
| 52 heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask, |
| 53 "memory reducer"); |
| 54 } else { |
| 55 heap()->StartIdleIncrementalMarking(); |
| 56 } |
50 } else if (state_.action == kWait) { | 57 } else if (state_.action == kWait) { |
| 58 if (!heap()->incremental_marking()->IsStopped() && |
| 59 heap()->ShouldOptimizeForMemoryUsage()) { |
| 60 // Make progress with pending incremental marking if memory usage has |
| 61 // higher priority than latency. This is important for background tabs |
| 62 // that do not send idle notifications. |
| 63 const int kIncrementalMarkingDelayMs = 500; |
| 64 double deadline = heap()->MonotonicallyIncreasingTimeInMs() + |
| 65 kIncrementalMarkingDelayMs; |
| 66 heap()->AdvanceIncrementalMarking( |
| 67 0, deadline, i::IncrementalMarking::StepActions( |
| 68 i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, |
| 69 i::IncrementalMarking::FORCE_MARKING, |
| 70 i::IncrementalMarking::FORCE_COMPLETION)); |
| 71 heap()->FinalizeIncrementalMarkingIfComplete( |
| 72 "Memory reducer: finalize incremental marking"); |
| 73 } |
51 // Re-schedule the timer. | 74 // Re-schedule the timer. |
52 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); | 75 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); |
53 if (FLAG_trace_gc_verbose) { | 76 if (FLAG_trace_gc_verbose) { |
54 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", | 77 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", |
55 state_.next_gc_start_ms - event.time_ms); | 78 state_.next_gc_start_ms - event.time_ms); |
56 } | 79 } |
57 } | 80 } |
58 } | 81 } |
59 | 82 |
60 | 83 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 auto timer_task = new MemoryReducer::TimerTask(this); | 216 auto timer_task = new MemoryReducer::TimerTask(this); |
194 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( | 217 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( |
195 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); | 218 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); |
196 } | 219 } |
197 | 220 |
198 | 221 |
199 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } | 222 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } |
200 | 223 |
201 } // internal | 224 } // internal |
202 } // v8 | 225 } // v8 |
OLD | NEW |