| 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/gc-tracer.h" | 8 #include "src/heap/gc-tracer.h" |
| 9 #include "src/heap/heap-inl.h" | 9 #include "src/heap/heap-inl.h" |
| 10 #include "src/utils.h" | 10 #include "src/utils.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 DCHECK_EQ(kTimer, event.type); | 43 DCHECK_EQ(kTimer, event.type); |
| 44 DCHECK_EQ(kWait, state_.action); | 44 DCHECK_EQ(kWait, state_.action); |
| 45 state_ = Step(state_, event); | 45 state_ = Step(state_, event); |
| 46 if (state_.action == kRun) { | 46 if (state_.action == kRun) { |
| 47 DCHECK(heap()->incremental_marking()->IsStopped()); | 47 DCHECK(heap()->incremental_marking()->IsStopped()); |
| 48 DCHECK(FLAG_incremental_marking); | 48 DCHECK(FLAG_incremental_marking); |
| 49 if (FLAG_trace_gc_verbose) { | 49 if (FLAG_trace_gc_verbose) { |
| 50 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", | 50 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", |
| 51 state_.started_gcs); | 51 state_.started_gcs); |
| 52 } | 52 } |
| 53 if (heap()->ShouldOptimizeForMemoryUsage()) { | 53 heap()->StartIdleIncrementalMarking(); |
| 54 // Do full GC if memory usage has higher priority than latency. This is | |
| 55 // important for background tabs that do not send idle notifications. | |
| 56 heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask, | |
| 57 "memory reducer"); | |
| 58 } else { | |
| 59 heap()->StartIdleIncrementalMarking(); | |
| 60 } | |
| 61 } else if (state_.action == kWait) { | 54 } else if (state_.action == kWait) { |
| 62 if (!heap()->incremental_marking()->IsStopped() && | 55 if (!heap()->incremental_marking()->IsStopped() && |
| 63 heap()->ShouldOptimizeForMemoryUsage()) { | 56 heap()->ShouldOptimizeForMemoryUsage()) { |
| 64 // Make progress with pending incremental marking if memory usage has | 57 // Make progress with pending incremental marking if memory usage has |
| 65 // higher priority than latency. This is important for background tabs | 58 // higher priority than latency. This is important for background tabs |
| 66 // that do not send idle notifications. | 59 // that do not send idle notifications. |
| 67 const int kIncrementalMarkingDelayMs = 500; | 60 const int kIncrementalMarkingDelayMs = 500; |
| 68 double deadline = heap()->MonotonicallyIncreasingTimeInMs() + | 61 double deadline = heap()->MonotonicallyIncreasingTimeInMs() + |
| 69 kIncrementalMarkingDelayMs; | 62 kIncrementalMarkingDelayMs; |
| 70 heap()->incremental_marking()->AdvanceIncrementalMarking( | 63 heap()->incremental_marking()->AdvanceIncrementalMarking( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 auto timer_task = new MemoryReducer::TimerTask(this); | 213 auto timer_task = new MemoryReducer::TimerTask(this); |
| 221 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( | 214 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( |
| 222 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); | 215 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); |
| 223 } | 216 } |
| 224 | 217 |
| 225 | 218 |
| 226 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } | 219 void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0); } |
| 227 | 220 |
| 228 } // namespace internal | 221 } // namespace internal |
| 229 } // namespace v8 | 222 } // namespace v8 |
| OLD | NEW |