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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 void MemoryReducer::NotifyTimer(const Event& event) { | 38 void MemoryReducer::NotifyTimer(const Event& event) { |
39 DCHECK(nullptr != pending_task_); | 39 DCHECK(nullptr != pending_task_); |
40 DCHECK_EQ(kTimer, event.type); | 40 DCHECK_EQ(kTimer, event.type); |
41 DCHECK_EQ(kWait, state_.action); | 41 DCHECK_EQ(kWait, state_.action); |
42 pending_task_ = nullptr; | 42 pending_task_ = nullptr; |
43 state_ = Step(state_, event); | 43 state_ = Step(state_, event); |
44 if (state_.action == kRun) { | 44 if (state_.action == kRun) { |
45 DCHECK(heap()->incremental_marking()->IsStopped()); | 45 DCHECK(heap()->incremental_marking()->IsStopped()); |
46 DCHECK(FLAG_incremental_marking); | 46 DCHECK(FLAG_incremental_marking); |
| 47 heap()->StartIdleIncrementalMarking(); |
47 if (FLAG_trace_gc_verbose) { | 48 if (FLAG_trace_gc_verbose) { |
48 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", | 49 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", |
49 state_.started_gcs); | 50 state_.started_gcs); |
50 } | 51 } |
51 if (heap()->ShouldOptimizeForMemoryUsage()) { | |
52 // Do full GC if memory usage has higher priority than latency. This is | |
53 // important for background tabs that do not send idle notifications. | |
54 heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask, | |
55 "memory reducer"); | |
56 } else { | |
57 heap()->StartIdleIncrementalMarking(); | |
58 } | |
59 } else if (state_.action == kWait) { | 52 } else if (state_.action == kWait) { |
60 if (!heap()->incremental_marking()->IsStopped() && | |
61 heap()->ShouldOptimizeForMemoryUsage()) { | |
62 // Make progress with pending incremental marking if memory usage has | |
63 // higher priority than latency. This is important for background tabs | |
64 // that do not send idle notifications. | |
65 const int kIncrementalMarkingDelayMs = 500; | |
66 double deadline = heap()->MonotonicallyIncreasingTimeInMs() + | |
67 kIncrementalMarkingDelayMs; | |
68 heap()->AdvanceIncrementalMarking( | |
69 0, deadline, i::IncrementalMarking::StepActions( | |
70 i::IncrementalMarking::NO_GC_VIA_STACK_GUARD, | |
71 i::IncrementalMarking::FORCE_MARKING, | |
72 i::IncrementalMarking::FORCE_COMPLETION)); | |
73 heap()->FinalizeIncrementalMarkingIfComplete( | |
74 "Memory reducer: finalize incremental marking"); | |
75 } | |
76 // Re-schedule the timer. | 53 // Re-schedule the timer. |
77 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); | 54 ScheduleTimer(state_.next_gc_start_ms - event.time_ms); |
78 if (FLAG_trace_gc_verbose) { | 55 if (FLAG_trace_gc_verbose) { |
79 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", | 56 PrintIsolate(heap()->isolate(), "Memory reducer: waiting for %.f ms\n", |
80 state_.next_gc_start_ms - event.time_ms); | 57 state_.next_gc_start_ms - event.time_ms); |
81 } | 58 } |
82 } | 59 } |
83 } | 60 } |
84 | 61 |
85 | 62 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void MemoryReducer::TearDown() { | 209 void MemoryReducer::TearDown() { |
233 if (pending_task_ != nullptr) { | 210 if (pending_task_ != nullptr) { |
234 pending_task_->NotifyHeapTearDown(); | 211 pending_task_->NotifyHeapTearDown(); |
235 pending_task_ = nullptr; | 212 pending_task_ = nullptr; |
236 } | 213 } |
237 state_ = State(kDone, 0, 0, 0.0); | 214 state_ = State(kDone, 0, 0, 0.0); |
238 } | 215 } |
239 | 216 |
240 } // internal | 217 } // internal |
241 } // v8 | 218 } // v8 |
OLD | NEW |