Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: src/heap/memory-reducer.cc

Issue 1246603002: Don't run the second pass of the pending phantom callbacks if the heap has been torn down. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/memory-reducer.h ('k') | src/isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/heap/memory-reducer.h" 5 #include "src/heap/memory-reducer.h"
6 6
7 #include "src/flags.h" 7 #include "src/flags.h"
8 #include "src/heap/heap.h" 8 #include "src/heap/heap.h"
9 #include "src/utils.h" 9 #include "src/utils.h"
10 #include "src/v8.h" 10 #include "src/v8.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 const int MemoryReducer::kLongDelayMs = 5000; 15 const int MemoryReducer::kLongDelayMs = 5000;
16 const int MemoryReducer::kShortDelayMs = 500; 16 const int MemoryReducer::kShortDelayMs = 500;
17 const int MemoryReducer::kMaxNumberOfGCs = 3; 17 const int MemoryReducer::kMaxNumberOfGCs = 3;
18 18
19 MemoryReducer::TimerTask::TimerTask(MemoryReducer* memory_reducer)
20 : CancelableTask(memory_reducer->heap()->isolate()),
21 memory_reducer_(memory_reducer) {}
19 22
20 void MemoryReducer::TimerTask::Run() { 23
21 if (heap_is_torn_down_) return; 24 void MemoryReducer::TimerTask::RunInternal() {
22 Heap* heap = memory_reducer_->heap(); 25 Heap* heap = memory_reducer_->heap();
23 Event event; 26 Event event;
24 event.type = kTimer; 27 event.type = kTimer;
25 event.time_ms = heap->MonotonicallyIncreasingTimeInMs(); 28 event.time_ms = heap->MonotonicallyIncreasingTimeInMs();
26 event.low_allocation_rate = heap->HasLowAllocationRate(); 29 event.low_allocation_rate = heap->HasLowAllocationRate();
27 event.can_start_incremental_gc = 30 event.can_start_incremental_gc =
28 heap->incremental_marking()->IsStopped() && 31 heap->incremental_marking()->IsStopped() &&
29 heap->incremental_marking()->CanBeActivated(); 32 heap->incremental_marking()->CanBeActivated();
30 memory_reducer_->NotifyTimer(event); 33 memory_reducer_->NotifyTimer(event);
31 } 34 }
32 35
33 36
34 void MemoryReducer::NotifyTimer(const Event& event) { 37 void MemoryReducer::NotifyTimer(const Event& event) {
35 DCHECK(nullptr != pending_task_);
36 DCHECK_EQ(kTimer, event.type); 38 DCHECK_EQ(kTimer, event.type);
37 DCHECK_EQ(kWait, state_.action); 39 DCHECK_EQ(kWait, state_.action);
38 pending_task_ = nullptr;
39 state_ = Step(state_, event); 40 state_ = Step(state_, event);
40 if (state_.action == kRun) { 41 if (state_.action == kRun) {
41 DCHECK(heap()->incremental_marking()->IsStopped()); 42 DCHECK(heap()->incremental_marking()->IsStopped());
42 DCHECK(FLAG_incremental_marking); 43 DCHECK(FLAG_incremental_marking);
43 heap()->StartIdleIncrementalMarking(); 44 heap()->StartIdleIncrementalMarking();
44 if (FLAG_trace_gc_verbose) { 45 if (FLAG_trace_gc_verbose) {
45 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n", 46 PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n",
46 state_.started_gcs); 47 state_.started_gcs);
47 } 48 }
48 } else if (state_.action == kWait) { 49 } else if (state_.action == kWait) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 UNREACHABLE(); 164 UNREACHABLE();
164 return State(kDone, 0, 0); // Make the compiler happy. 165 return State(kDone, 0, 0); // Make the compiler happy.
165 } 166 }
166 167
167 168
168 void MemoryReducer::ScheduleTimer(double delay_ms) { 169 void MemoryReducer::ScheduleTimer(double delay_ms) {
169 DCHECK(delay_ms > 0); 170 DCHECK(delay_ms > 0);
170 // Leave some room for precision error in task scheduler. 171 // Leave some room for precision error in task scheduler.
171 const double kSlackMs = 100; 172 const double kSlackMs = 100;
172 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate()); 173 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate());
173 DCHECK(nullptr == pending_task_); 174 auto timer_task = new MemoryReducer::TimerTask(this);
174 pending_task_ = new MemoryReducer::TimerTask(this);
175 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread( 175 V8::GetCurrentPlatform()->CallDelayedOnForegroundThread(
176 isolate, pending_task_, (delay_ms + kSlackMs) / 1000.0); 176 isolate, timer_task, (delay_ms + kSlackMs) / 1000.0);
177 }
178
179
180 void MemoryReducer::ClearTask(v8::Task* task) {
181 if (pending_task_ == task) {
182 pending_task_ = nullptr;
183 }
184 } 177 }
185 178
186 179
187 void MemoryReducer::TearDown() { 180 void MemoryReducer::TearDown() {
188 if (pending_task_ != nullptr) {
189 pending_task_->NotifyHeapTearDown();
190 pending_task_ = nullptr;
191 }
192 state_ = State(kDone, 0, 0); 181 state_ = State(kDone, 0, 0);
193 } 182 }
194 183
195 } // internal 184 } // internal
196 } // v8 185 } // v8
OLDNEW
« no previous file with comments | « src/heap/memory-reducer.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698