Reviewers: jochen,

Message:
PTAL

Description:
Disable the pending task if the memory reducer is teared down.

BUG=chromium:508584
LOG=NO

Please review this at https://codereview.chromium.org/1230163002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+24, -5 lines):
  M src/heap/heap.cc
  M src/heap/memory-reducer.h
  M src/heap/memory-reducer.cc


Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 4660a67dd2847e668ca305a780bc8e80a2482488..86b546940a40e13674804efa90e58d49ada01738 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -5886,6 +5886,8 @@ void Heap::TearDown() {
     PrintAlloctionsHash();
   }

+  memory_reducer_.TearDown();
+
   TearDownArrayBuffers();

   isolate_->global_handles()->TearDown();
Index: src/heap/memory-reducer.cc
diff --git a/src/heap/memory-reducer.cc b/src/heap/memory-reducer.cc
index aa3abd0f21919cb5459e2125244082caef80b8a0..f8f34d6320e171ced8654a2412966678688b1c97 100644
--- a/src/heap/memory-reducer.cc
+++ b/src/heap/memory-reducer.cc
@@ -18,6 +18,7 @@ const int MemoryReducer::kMaxNumberOfGCs = 3;


 void MemoryReducer::TimerTask::Run() {
+  if (heap_is_teared_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_NE(NULL, pending_task_);
   DCHECK_EQ(kTimer, event.type);
   DCHECK_EQ(kWait, state_.action);
+  pending_task_ = NULL;
   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_EQ(NULL, 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_ != NULL) {
+    pending_task_->NotifyHeapTearDown();
+    pending_task_ = NULL;
+  }
+  state_ = State(kDone, 0, 0);
 }

 }  // internal
Index: src/heap/memory-reducer.h
diff --git a/src/heap/memory-reducer.h b/src/heap/memory-reducer.h
index fc7b2eaee569b34add4501d2874fde953d5b3c6f..0a4e2bf1f328447bfd9669a4a24d90cc2b0fe1ac 100644
--- a/src/heap/memory-reducer.h
+++ b/src/heap/memory-reducer.h
@@ -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_(NULL) {}
   // 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_teared_down_(false) {}
     virtual ~TimerTask() {}
+    void NotifyHeapTearDown() { heap_is_teared_down_ = true; }

    private:
     // v8::Task overrides.
     void Run() override;
     MemoryReducer* memory_reducer_;
+    bool heap_is_teared_down_;
     DISALLOW_COPY_AND_ASSIGN(TimerTask);
   };
-
   Heap* heap_;
   State state_;
+  TimerTask* pending_task_;

   DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
 };


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to