| 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 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 | 14 |
| 14 class Heap; | 15 class Heap; |
| 15 | 16 |
| 16 | 17 |
| 17 // The goal of the MemoryReducer class is to detect transition of the mutator | 18 // The goal of the MemoryReducer class is to detect transition of the mutator |
| 18 // from high allocation phase to low allocation phase and to collect potential | 19 // from high allocation phase to low allocation phase and to collect potential |
| 19 // garbage created in the high allocation phase. | 20 // garbage created in the high allocation phase. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 struct Event { | 97 struct Event { |
| 97 EventType type; | 98 EventType type; |
| 98 double time_ms; | 99 double time_ms; |
| 99 bool low_allocation_rate; | 100 bool low_allocation_rate; |
| 100 bool next_gc_likely_to_collect_more; | 101 bool next_gc_likely_to_collect_more; |
| 101 bool can_start_incremental_gc; | 102 bool can_start_incremental_gc; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 explicit MemoryReducer(Heap* heap) | 105 explicit MemoryReducer(Heap* heap) : heap_(heap), state_(kDone, 0, 0.0) {} |
| 105 : heap_(heap), state_(kDone, 0, 0.0), pending_task_(nullptr) {} | |
| 106 // Callbacks. | 106 // Callbacks. |
| 107 void NotifyTimer(const Event& event); | 107 void NotifyTimer(const Event& event); |
| 108 void NotifyMarkCompact(const Event& event); | 108 void NotifyMarkCompact(const Event& event); |
| 109 void NotifyContextDisposed(const Event& event); | 109 void NotifyContextDisposed(const Event& event); |
| 110 void NotifyBackgroundIdleNotification(const Event& event); | 110 void NotifyBackgroundIdleNotification(const Event& event); |
| 111 // The step function that computes the next state from the current state and | 111 // The step function that computes the next state from the current state and |
| 112 // the incoming event. | 112 // the incoming event. |
| 113 static State Step(const State& state, const Event& event); | 113 static State Step(const State& state, const Event& event); |
| 114 // Posts a timer task that will call NotifyTimer after the given delay. | 114 // Posts a timer task that will call NotifyTimer after the given delay. |
| 115 void ScheduleTimer(double delay_ms); | 115 void ScheduleTimer(double delay_ms); |
| 116 void TearDown(); | 116 void TearDown(); |
| 117 void ClearTask(v8::Task* task); | |
| 118 static const int kLongDelayMs; | 117 static const int kLongDelayMs; |
| 119 static const int kShortDelayMs; | 118 static const int kShortDelayMs; |
| 120 static const int kMaxNumberOfGCs; | 119 static const int kMaxNumberOfGCs; |
| 121 | 120 |
| 122 Heap* heap() { return heap_; } | 121 Heap* heap() { return heap_; } |
| 123 | 122 |
| 124 private: | 123 private: |
| 125 class TimerTask : public v8::Task { | 124 class TimerTask : public v8::internal::CancelableTask { |
| 126 public: | 125 public: |
| 127 explicit TimerTask(MemoryReducer* memory_reducer) | 126 explicit TimerTask(MemoryReducer* memory_reducer); |
| 128 : memory_reducer_(memory_reducer), heap_is_torn_down_(false) {} | |
| 129 virtual ~TimerTask() { | |
| 130 if (!heap_is_torn_down_) { | |
| 131 memory_reducer_->ClearTask(this); | |
| 132 } | |
| 133 } | |
| 134 void NotifyHeapTearDown() { heap_is_torn_down_ = true; } | |
| 135 | 127 |
| 136 private: | 128 private: |
| 137 // v8::Task overrides. | 129 // v8::internal::CancelableTask overrides. |
| 138 void Run() override; | 130 void RunInternal() override; |
| 139 MemoryReducer* memory_reducer_; | 131 MemoryReducer* memory_reducer_; |
| 140 bool heap_is_torn_down_; | |
| 141 DISALLOW_COPY_AND_ASSIGN(TimerTask); | 132 DISALLOW_COPY_AND_ASSIGN(TimerTask); |
| 142 }; | 133 }; |
| 143 Heap* heap_; | 134 Heap* heap_; |
| 144 State state_; | 135 State state_; |
| 145 TimerTask* pending_task_; | |
| 146 | 136 |
| 147 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); | 137 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); |
| 148 }; | 138 }; |
| 149 | 139 |
| 150 } // namespace internal | 140 } // namespace internal |
| 151 } // namespace v8 | 141 } // namespace v8 |
| 152 | 142 |
| 153 #endif // V8_HEAP_memory_reducer_H | 143 #endif // V8_HEAP_memory_reducer_H |
| OLD | NEW |