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() {
PrintAlloctionsHash();
}
memory_reducer_.TearDown();
TearDownArrayBuffers();
isolate_->global_handles()->TearDown();
......
......@@ -18,6 +18,7 @@ const int MemoryReducer::kMaxNumberOfGCs = 3;
void MemoryReducer::TimerTask::Run() {
if (heap_is_torn_down_) return;
Heap* heap = memory_reducer_->heap();
Event event;
event.type = kTimer;
......@@ -31,8 +32,10 @@ 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());
......@@ -167,9 +170,19 @@ 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);
V8::GetCurrentPlatform()->CallDelayedOnForegroundThread(
isolate, new MemoryReducer::TimerTask(this),
(delay_ms + kSlackMs) / 1000.0);
isolate, pending_task_, (delay_ms + kSlackMs) / 1000.0);
}
void MemoryReducer::TearDown() {
if (pending_task_ != nullptr) {
pending_task_->NotifyHeapTearDown();
pending_task_ = nullptr;
}
state_ = State(kDone, 0, 0);
}
} // internal
......
......@@ -101,7 +101,8 @@ class MemoryReducer {
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.
void NotifyTimer(const Event& event);
void NotifyMarkCompact(const Event& event);
......@@ -112,6 +113,7 @@ class MemoryReducer {
static State Step(const State& state, const Event& event);
// Posts a timer task that will call NotifyTimer after the given delay.
void ScheduleTimer(double delay_ms);
void TearDown();
static const int kLongDelayMs;
static const int kShortDelayMs;
......@@ -123,18 +125,20 @@ class MemoryReducer {
class TimerTask : public v8::Task {
public:
explicit TimerTask(MemoryReducer* memory_reducer)
: memory_reducer_(memory_reducer) {}
: memory_reducer_(memory_reducer), heap_is_torn_down_(false) {}
virtual ~TimerTask() {}
void NotifyHeapTearDown() { heap_is_torn_down_ = true; }
private:
// v8::Task overrides.
void Run() override;
MemoryReducer* memory_reducer_;
bool heap_is_torn_down_;
DISALLOW_COPY_AND_ASSIGN(TimerTask);
};
Heap* heap_;
State state_;
TimerTask* pending_task_;
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