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 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 117 void ClearTask(v8::Task* task); |
118 static const int kLongDelayMs; | 118 static const int kLongDelayMs; |
119 static const int kShortDelayMs; | 119 static const int kShortDelayMs; |
120 static const int kMaxNumberOfGCs; | 120 static const int kMaxNumberOfGCs; |
121 | 121 |
122 Heap* heap() { return heap_; } | 122 Heap* heap() { return heap_; } |
123 | 123 |
124 private: | 124 private: |
125 class TimerTask : public v8::Task { | 125 class TimerTask : public v8::Task { |
126 public: | 126 public: |
127 explicit TimerTask(MemoryReducer* memory_reducer) | 127 explicit TimerTask(MemoryReducer* memory_reducer) |
128 : memory_reducer_(memory_reducer), heap_is_torn_down_(false) {} | 128 : memory_reducer_(memory_reducer), heap_is_torn_down_(false) {} |
129 virtual ~TimerTask() {} | 129 virtual ~TimerTask() { |
| 130 if (!heap_is_torn_down_) { |
| 131 memory_reducer_->ClearTask(this); |
| 132 } |
| 133 } |
130 void NotifyHeapTearDown() { heap_is_torn_down_ = true; } | 134 void NotifyHeapTearDown() { heap_is_torn_down_ = true; } |
131 | 135 |
132 private: | 136 private: |
133 // v8::Task overrides. | 137 // v8::Task overrides. |
134 void Run() override; | 138 void Run() override; |
135 MemoryReducer* memory_reducer_; | 139 MemoryReducer* memory_reducer_; |
136 bool heap_is_torn_down_; | 140 bool heap_is_torn_down_; |
137 DISALLOW_COPY_AND_ASSIGN(TimerTask); | 141 DISALLOW_COPY_AND_ASSIGN(TimerTask); |
138 }; | 142 }; |
139 Heap* heap_; | 143 Heap* heap_; |
140 State state_; | 144 State state_; |
141 TimerTask* pending_task_; | 145 TimerTask* pending_task_; |
142 | 146 |
143 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); | 147 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); |
144 }; | 148 }; |
145 | 149 |
146 } // namespace internal | 150 } // namespace internal |
147 } // namespace v8 | 151 } // namespace v8 |
148 | 152 |
149 #endif // V8_HEAP_memory_reducer_H | 153 #endif // V8_HEAP_memory_reducer_H |
OLD | NEW |