| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 struct Event { | 101 struct Event { |
| 102 EventType type; | 102 EventType type; |
| 103 double time_ms; | 103 double time_ms; |
| 104 bool next_gc_likely_to_collect_more; | 104 bool next_gc_likely_to_collect_more; |
| 105 bool should_start_incremental_gc; | 105 bool should_start_incremental_gc; |
| 106 bool can_start_incremental_gc; | 106 bool can_start_incremental_gc; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 explicit MemoryReducer(Heap* heap) | 109 explicit MemoryReducer(Heap* heap) |
| 110 : heap_(heap), state_(kDone, 0, 0.0, 0.0) {} | 110 : heap_(heap), |
| 111 state_(kDone, 0, 0.0, 0.0), |
| 112 js_calls_counter_(0), |
| 113 js_calls_sample_time_ms_(0.0) {} |
| 111 // Callbacks. | 114 // Callbacks. |
| 112 void NotifyMarkCompact(const Event& event); | 115 void NotifyMarkCompact(const Event& event); |
| 113 void NotifyContextDisposed(const Event& event); | 116 void NotifyContextDisposed(const Event& event); |
| 114 void NotifyBackgroundIdleNotification(const Event& event); | 117 void NotifyBackgroundIdleNotification(const Event& event); |
| 115 // The step function that computes the next state from the current state and | 118 // The step function that computes the next state from the current state and |
| 116 // the incoming event. | 119 // the incoming event. |
| 117 static State Step(const State& state, const Event& event); | 120 static State Step(const State& state, const Event& event); |
| 118 // Posts a timer task that will call NotifyTimer after the given delay. | 121 // Posts a timer task that will call NotifyTimer after the given delay. |
| 119 void ScheduleTimer(double delay_ms); | 122 void ScheduleTimer(double time_ms, double delay_ms); |
| 120 void TearDown(); | 123 void TearDown(); |
| 121 static const int kLongDelayMs; | 124 static const int kLongDelayMs; |
| 122 static const int kShortDelayMs; | 125 static const int kShortDelayMs; |
| 123 static const int kWatchdogDelayMs; | 126 static const int kWatchdogDelayMs; |
| 124 static const int kMaxNumberOfGCs; | 127 static const int kMaxNumberOfGCs; |
| 125 | 128 |
| 126 Heap* heap() { return heap_; } | 129 Heap* heap() { return heap_; } |
| 127 | 130 |
| 128 bool ShouldGrowHeapSlowly() { | 131 bool ShouldGrowHeapSlowly() { |
| 129 return state_.action == kDone && state_.started_gcs > 0; | 132 return state_.action == kDone && state_.started_gcs > 0; |
| 130 } | 133 } |
| 131 | 134 |
| 132 private: | 135 private: |
| 133 class TimerTask : public v8::internal::CancelableTask { | 136 class TimerTask : public v8::internal::CancelableTask { |
| 134 public: | 137 public: |
| 135 explicit TimerTask(MemoryReducer* memory_reducer); | 138 explicit TimerTask(MemoryReducer* memory_reducer); |
| 136 | 139 |
| 137 private: | 140 private: |
| 138 // v8::internal::CancelableTask overrides. | 141 // v8::internal::CancelableTask overrides. |
| 139 void RunInternal() override; | 142 void RunInternal() override; |
| 140 MemoryReducer* memory_reducer_; | 143 MemoryReducer* memory_reducer_; |
| 141 DISALLOW_COPY_AND_ASSIGN(TimerTask); | 144 DISALLOW_COPY_AND_ASSIGN(TimerTask); |
| 142 }; | 145 }; |
| 143 | 146 |
| 144 void NotifyTimer(const Event& event); | 147 void NotifyTimer(const Event& event); |
| 145 | 148 |
| 146 static bool WatchdogGC(const State& state, const Event& event); | 149 static bool WatchdogGC(const State& state, const Event& event); |
| 147 | 150 |
| 151 // Returns the rate of JS calls initiated from the API. |
| 152 double SampleAndGetJsCallsPerMs(double time_ms); |
| 153 |
| 148 Heap* heap_; | 154 Heap* heap_; |
| 149 State state_; | 155 State state_; |
| 156 unsigned int js_calls_counter_; |
| 157 double js_calls_sample_time_ms_; |
| 158 |
| 159 // Used in cctest. |
| 160 friend class HeapTester; |
| 150 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); | 161 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); |
| 151 }; | 162 }; |
| 152 | 163 |
| 153 } // namespace internal | 164 } // namespace internal |
| 154 } // namespace v8 | 165 } // namespace v8 |
| 155 | 166 |
| 156 #endif // V8_HEAP_memory_reducer_H | 167 #endif // V8_HEAP_memory_reducer_H |
| OLD | NEW |