Commit a5616e5d authored by ulan's avatar ulan Committed by Commit bot

Disable the pending task if the memory reducer is torn down.

BUG=chromium:508584
LOG=NO

Review URL: https://codereview.chromium.org/1230163002

Cr-Commit-Position: refs/heads/master@{#29565}
parent 331b87e2
...@@ -5886,6 +5886,8 @@ void Heap::TearDown() { ...@@ -5886,6 +5886,8 @@ void Heap::TearDown() {
PrintAlloctionsHash(); PrintAlloctionsHash();
} }
memory_reducer_.TearDown();
TearDownArrayBuffers(); TearDownArrayBuffers();
isolate_->global_handles()->TearDown(); isolate_->global_handles()->TearDown();
......
...@@ -18,6 +18,7 @@ const int MemoryReducer::kMaxNumberOfGCs = 3; ...@@ -18,6 +18,7 @@ const int MemoryReducer::kMaxNumberOfGCs = 3;
void MemoryReducer::TimerTask::Run() { void MemoryReducer::TimerTask::Run() {
if (heap_is_torn_down_) return;
Heap* heap = memory_reducer_->heap(); Heap* heap = memory_reducer_->heap();
Event event; Event event;
event.type = kTimer; event.type = kTimer;
...@@ -31,8 +32,10 @@ void MemoryReducer::TimerTask::Run() { ...@@ -31,8 +32,10 @@ void MemoryReducer::TimerTask::Run() {
void MemoryReducer::NotifyTimer(const Event& event) { void MemoryReducer::NotifyTimer(const Event& event) {
DCHECK(nullptr != pending_task_);
DCHECK_EQ(kTimer, event.type); DCHECK_EQ(kTimer, event.type);
DCHECK_EQ(kWait, state_.action); DCHECK_EQ(kWait, state_.action);
pending_task_ = nullptr;
state_ = Step(state_, event); state_ = Step(state_, event);
if (state_.action == kRun) { if (state_.action == kRun) {
DCHECK(heap()->incremental_marking()->IsStopped()); DCHECK(heap()->incremental_marking()->IsStopped());
...@@ -167,9 +170,19 @@ void MemoryReducer::ScheduleTimer(double delay_ms) { ...@@ -167,9 +170,19 @@ void MemoryReducer::ScheduleTimer(double delay_ms) {
// Leave some room for precision error in task scheduler. // Leave some room for precision error in task scheduler.
const double kSlackMs = 100; const double kSlackMs = 100;
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate()); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate());
DCHECK(nullptr == pending_task_);
pending_task_ = new MemoryReducer::TimerTask(this);
V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( V8::GetCurrentPlatform()->CallDelayedOnForegroundThread(
isolate, new MemoryReducer::TimerTask(this), isolate, pending_task_, (delay_ms + kSlackMs) / 1000.0);
(delay_ms + kSlackMs) / 1000.0); }
void MemoryReducer::TearDown() {
if (pending_task_ != nullptr) {
pending_task_->NotifyHeapTearDown();
pending_task_ = nullptr;
}
state_ = State(kDone, 0, 0);
} }
} // internal } // internal
......
...@@ -101,7 +101,8 @@ class MemoryReducer { ...@@ -101,7 +101,8 @@ class MemoryReducer {
bool can_start_incremental_gc; bool can_start_incremental_gc;
}; };
explicit MemoryReducer(Heap* heap) : heap_(heap), state_(kDone, 0, 0.0) {} explicit MemoryReducer(Heap* heap)
: heap_(heap), state_(kDone, 0, 0.0), pending_task_(nullptr) {}
// Callbacks. // Callbacks.
void NotifyTimer(const Event& event); void NotifyTimer(const Event& event);
void NotifyMarkCompact(const Event& event); void NotifyMarkCompact(const Event& event);
...@@ -112,6 +113,7 @@ class MemoryReducer { ...@@ -112,6 +113,7 @@ class MemoryReducer {
static State Step(const State& state, const Event& event); static State Step(const State& state, const Event& event);
// Posts a timer task that will call NotifyTimer after the given delay. // Posts a timer task that will call NotifyTimer after the given delay.
void ScheduleTimer(double delay_ms); void ScheduleTimer(double delay_ms);
void TearDown();
static const int kLongDelayMs; static const int kLongDelayMs;
static const int kShortDelayMs; static const int kShortDelayMs;
...@@ -123,18 +125,20 @@ class MemoryReducer { ...@@ -123,18 +125,20 @@ class MemoryReducer {
class TimerTask : public v8::Task { class TimerTask : public v8::Task {
public: public:
explicit TimerTask(MemoryReducer* memory_reducer) explicit TimerTask(MemoryReducer* memory_reducer)
: memory_reducer_(memory_reducer) {} : memory_reducer_(memory_reducer), heap_is_torn_down_(false) {}
virtual ~TimerTask() {} virtual ~TimerTask() {}
void NotifyHeapTearDown() { heap_is_torn_down_ = true; }
private: private:
// v8::Task overrides. // v8::Task overrides.
void Run() override; void Run() override;
MemoryReducer* memory_reducer_; MemoryReducer* memory_reducer_;
bool heap_is_torn_down_;
DISALLOW_COPY_AND_ASSIGN(TimerTask); DISALLOW_COPY_AND_ASSIGN(TimerTask);
}; };
Heap* heap_; Heap* heap_;
State state_; State state_;
TimerTask* pending_task_;
DISALLOW_COPY_AND_ASSIGN(MemoryReducer); DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment