| 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 #ifndef V8_HEAP_memory_reducer_H | 5 #ifndef V8_HEAP_memory_reducer_H |
| 6 #define V8_HEAP_memory_reducer_H | 6 #define V8_HEAP_memory_reducer_H |
| 7 | 7 |
| 8 #include "include/v8-platform.h" | 8 #include "include/v8-platform.h" |
| 9 #include "src/base/macros.h" | 9 #include "src/base/macros.h" |
| 10 #include "src/cancelable-task.h" | 10 #include "src/cancelable-task.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // | 79 // |
| 80 // now_ms is the current time, | 80 // now_ms is the current time, |
| 81 // t' is t if the current event is not a GC event and is now_ms otherwise, | 81 // t' is t if the current event is not a GC event and is now_ms otherwise, |
| 82 // long_delay_ms, short_delay_ms, and watchdog_delay_ms are constants. | 82 // long_delay_ms, short_delay_ms, and watchdog_delay_ms are constants. |
| 83 class V8_EXPORT_PRIVATE MemoryReducer { | 83 class V8_EXPORT_PRIVATE MemoryReducer { |
| 84 public: | 84 public: |
| 85 enum Action { kDone, kWait, kRun }; | 85 enum Action { kDone, kWait, kRun }; |
| 86 | 86 |
| 87 struct State { | 87 struct State { |
| 88 State(Action action, int started_gcs, double next_gc_start_ms, | 88 State(Action action, int started_gcs, double next_gc_start_ms, |
| 89 double last_gc_time_ms, size_t committed_memory_at_last_run) | 89 double last_gc_time_ms) |
| 90 : action(action), | 90 : action(action), |
| 91 started_gcs(started_gcs), | 91 started_gcs(started_gcs), |
| 92 next_gc_start_ms(next_gc_start_ms), | 92 next_gc_start_ms(next_gc_start_ms), |
| 93 last_gc_time_ms(last_gc_time_ms), | 93 last_gc_time_ms(last_gc_time_ms) {} |
| 94 committed_memory_at_last_run(committed_memory_at_last_run) {} | |
| 95 Action action; | 94 Action action; |
| 96 int started_gcs; | 95 int started_gcs; |
| 97 double next_gc_start_ms; | 96 double next_gc_start_ms; |
| 98 double last_gc_time_ms; | 97 double last_gc_time_ms; |
| 99 size_t committed_memory_at_last_run; | |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 enum EventType { kTimer, kMarkCompact, kPossibleGarbage }; | 100 enum EventType { kTimer, kMarkCompact, kPossibleGarbage }; |
| 103 | 101 |
| 104 struct Event { | 102 struct Event { |
| 105 EventType type; | 103 EventType type; |
| 106 double time_ms; | 104 double time_ms; |
| 107 size_t committed_memory; | |
| 108 bool next_gc_likely_to_collect_more; | 105 bool next_gc_likely_to_collect_more; |
| 109 bool should_start_incremental_gc; | 106 bool should_start_incremental_gc; |
| 110 bool can_start_incremental_gc; | 107 bool can_start_incremental_gc; |
| 111 }; | 108 }; |
| 112 | 109 |
| 113 explicit MemoryReducer(Heap* heap) | 110 explicit MemoryReducer(Heap* heap) |
| 114 : heap_(heap), | 111 : heap_(heap), |
| 115 state_(kDone, 0, 0.0, 0.0, 0), | 112 state_(kDone, 0, 0.0, 0.0), |
| 116 js_calls_counter_(0), | 113 js_calls_counter_(0), |
| 117 js_calls_sample_time_ms_(0.0) {} | 114 js_calls_sample_time_ms_(0.0) {} |
| 118 // Callbacks. | 115 // Callbacks. |
| 119 void NotifyMarkCompact(const Event& event); | 116 void NotifyMarkCompact(const Event& event); |
| 120 void NotifyPossibleGarbage(const Event& event); | 117 void NotifyPossibleGarbage(const Event& event); |
| 121 void NotifyBackgroundIdleNotification(const Event& event); | 118 void NotifyBackgroundIdleNotification(const Event& event); |
| 122 // The step function that computes the next state from the current state and | 119 // The step function that computes the next state from the current state and |
| 123 // the incoming event. | 120 // the incoming event. |
| 124 static State Step(const State& state, const Event& event); | 121 static State Step(const State& state, const Event& event); |
| 125 // Posts a timer task that will call NotifyTimer after the given delay. | 122 // Posts a timer task that will call NotifyTimer after the given delay. |
| 126 void ScheduleTimer(double time_ms, double delay_ms); | 123 void ScheduleTimer(double time_ms, double delay_ms); |
| 127 void TearDown(); | 124 void TearDown(); |
| 128 static const int kLongDelayMs; | 125 static const int kLongDelayMs; |
| 129 static const int kShortDelayMs; | 126 static const int kShortDelayMs; |
| 130 static const int kWatchdogDelayMs; | 127 static const int kWatchdogDelayMs; |
| 131 static const int kMaxNumberOfGCs; | 128 static const int kMaxNumberOfGCs; |
| 132 // The committed memory has to increase by at least this factor since the | |
| 133 // last run in order to trigger a new run after mark-compact. | |
| 134 static const double kCommittedMemoryFactor; | |
| 135 // The committed memory has to increase by at least this amount since the | |
| 136 // last run in order to trigger a new run after mark-compact. | |
| 137 static const size_t kCommittedMemoryDelta; | |
| 138 | 129 |
| 139 Heap* heap() { return heap_; } | 130 Heap* heap() { return heap_; } |
| 140 | 131 |
| 141 bool ShouldGrowHeapSlowly() { | 132 bool ShouldGrowHeapSlowly() { |
| 142 return state_.action == kDone && state_.started_gcs > 0; | 133 return state_.action == kDone && state_.started_gcs > 0; |
| 143 } | 134 } |
| 144 | 135 |
| 145 private: | 136 private: |
| 146 class TimerTask : public v8::internal::CancelableTask { | 137 class TimerTask : public v8::internal::CancelableTask { |
| 147 public: | 138 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 168 | 159 |
| 169 // Used in cctest. | 160 // Used in cctest. |
| 170 friend class HeapTester; | 161 friend class HeapTester; |
| 171 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); | 162 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); |
| 172 }; | 163 }; |
| 173 | 164 |
| 174 } // namespace internal | 165 } // namespace internal |
| 175 } // namespace v8 | 166 } // namespace v8 |
| 176 | 167 |
| 177 #endif // V8_HEAP_memory_reducer_H | 168 #endif // V8_HEAP_memory_reducer_H |
| OLD | NEW |