Index: src/heap/memory-reducer.cc |
diff --git a/src/heap/memory-reducer.cc b/src/heap/memory-reducer.cc |
index c89d1424e7c5e78e303ae64b7043669571bb4035..be4b43f535aa64fd5a24b34eba6f32087ff2f748 100644 |
--- a/src/heap/memory-reducer.cc |
+++ b/src/heap/memory-reducer.cc |
@@ -16,9 +16,12 @@ const int MemoryReducer::kLongDelayMs = 5000; |
const int MemoryReducer::kShortDelayMs = 500; |
const int MemoryReducer::kMaxNumberOfGCs = 3; |
+MemoryReducer::TimerTask::TimerTask(MemoryReducer* memory_reducer) |
+ : CancelableTask(memory_reducer->heap()->isolate()), |
+ memory_reducer_(memory_reducer) {} |
-void MemoryReducer::TimerTask::Run() { |
- if (heap_is_torn_down_) return; |
+ |
+void MemoryReducer::TimerTask::RunInternal() { |
Heap* heap = memory_reducer_->heap(); |
Event event; |
event.type = kTimer; |
@@ -32,10 +35,8 @@ void MemoryReducer::TimerTask::Run() { |
void MemoryReducer::NotifyTimer(const Event& event) { |
- DCHECK(nullptr != pending_task_); |
DCHECK_EQ(kTimer, event.type); |
DCHECK_EQ(kWait, state_.action); |
- pending_task_ = nullptr; |
state_ = Step(state_, event); |
if (state_.action == kRun) { |
DCHECK(heap()->incremental_marking()->IsStopped()); |
@@ -170,25 +171,13 @@ void MemoryReducer::ScheduleTimer(double delay_ms) { |
// Leave some room for precision error in task scheduler. |
const double kSlackMs = 100; |
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate()); |
- DCHECK(nullptr == pending_task_); |
- pending_task_ = new MemoryReducer::TimerTask(this); |
+ auto timer_task = new MemoryReducer::TimerTask(this); |
V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( |
- isolate, pending_task_, (delay_ms + kSlackMs) / 1000.0); |
-} |
- |
- |
-void MemoryReducer::ClearTask(v8::Task* task) { |
- if (pending_task_ == task) { |
- pending_task_ = nullptr; |
- } |
+ isolate, timer_task, (delay_ms + kSlackMs) / 1000.0); |
} |
void MemoryReducer::TearDown() { |
- if (pending_task_ != nullptr) { |
- pending_task_->NotifyHeapTearDown(); |
- pending_task_ = nullptr; |
- } |
state_ = State(kDone, 0, 0); |
} |