| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_HEAP_INCREMENTAL_MARKING_JOB_H_ | 5 #ifndef V8_HEAP_INCREMENTAL_MARKING_JOB_H_ |
| 6 #define V8_HEAP_INCREMENTAL_MARKING_JOB_H_ | 6 #define V8_HEAP_INCREMENTAL_MARKING_JOB_H_ |
| 7 | 7 |
| 8 #include "src/cancelable-task.h" | 8 #include "src/cancelable-task.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 class Heap; | 13 class Heap; |
| 14 class Isolate; | 14 class Isolate; |
| 15 | 15 |
| 16 // The incremental marking job uses platform tasks to perform incremental | 16 // The incremental marking job uses platform tasks to perform incremental |
| 17 // marking steps. The job posts an idle and a delayed task with a large delay. | 17 // marking steps. The job posts a foreground task that makes a small (~1ms) |
| 18 // The delayed task performs steps only if the idle task is not making progress. | 18 // step and posts another task until the marking is completed. |
| 19 // We expect this to be a rare event since incremental marking should finish | |
| 20 // quickly with the help of the mutator and the idle task. | |
| 21 // The delayed task guarantees that we eventually finish incremental marking | |
| 22 // even if the mutator becomes idle and the platform stops running idle tasks, | |
| 23 // which can happen for background tabs in Chrome. | |
| 24 class IncrementalMarkingJob { | 19 class IncrementalMarkingJob { |
| 25 public: | 20 public: |
| 26 class IdleTask : public CancelableIdleTask { | 21 class Task : public CancelableTask { |
| 27 public: | 22 public: |
| 28 explicit IdleTask(Isolate* isolate, IncrementalMarkingJob* job) | 23 explicit Task(Isolate* isolate, IncrementalMarkingJob* job) |
| 29 : CancelableIdleTask(isolate), job_(job) {} | |
| 30 enum Progress { kDone, kMoreWork }; | |
| 31 static Progress Step(Heap* heap, double deadline_in_ms); | |
| 32 // CancelableIdleTask overrides. | |
| 33 void RunInternal(double deadline_in_seconds) override; | |
| 34 | |
| 35 private: | |
| 36 IncrementalMarkingJob* job_; | |
| 37 }; | |
| 38 | |
| 39 class DelayedTask : public CancelableTask { | |
| 40 public: | |
| 41 explicit DelayedTask(Isolate* isolate, IncrementalMarkingJob* job) | |
| 42 : CancelableTask(isolate), job_(job) {} | 24 : CancelableTask(isolate), job_(job) {} |
| 43 static void Step(Heap* heap); | 25 static void Step(Heap* heap); |
| 44 // CancelableTask overrides. | 26 // CancelableTask overrides. |
| 45 void RunInternal() override; | 27 void RunInternal() override; |
| 46 | 28 |
| 47 private: | 29 private: |
| 48 IncrementalMarkingJob* job_; | 30 IncrementalMarkingJob* job_; |
| 49 }; | 31 }; |
| 50 | 32 |
| 51 // Delay of the delayed task. | 33 IncrementalMarkingJob() : task_pending_(false) {} |
| 52 static const double kLongDelayInSeconds; | |
| 53 static const double kShortDelayInSeconds; | |
| 54 | 34 |
| 55 IncrementalMarkingJob() | 35 bool TaskPending() { return task_pending_; } |
| 56 : idle_task_pending_(false), | |
| 57 delayed_task_pending_(false), | |
| 58 made_progress_since_last_delayed_task_(false) {} | |
| 59 | |
| 60 bool ShouldForceMarkingStep() { | |
| 61 return !made_progress_since_last_delayed_task_; | |
| 62 } | |
| 63 | |
| 64 bool IdleTaskPending() { return idle_task_pending_; } | |
| 65 | 36 |
| 66 void Start(Heap* heap); | 37 void Start(Heap* heap); |
| 67 | 38 |
| 68 void NotifyIdleTask(); | 39 void NotifyTask(); |
| 69 void NotifyDelayedTask(); | 40 |
| 70 void NotifyIdleTaskProgress(); | 41 void ScheduleTask(Heap* heap); |
| 71 void ScheduleIdleTask(Heap* heap); | |
| 72 void ScheduleDelayedTask(Heap* heap); | |
| 73 | 42 |
| 74 private: | 43 private: |
| 75 bool idle_task_pending_; | 44 bool task_pending_; |
| 76 bool delayed_task_pending_; | |
| 77 bool made_progress_since_last_delayed_task_; | |
| 78 }; | 45 }; |
| 79 } // namespace internal | 46 } // namespace internal |
| 80 } // namespace v8 | 47 } // namespace v8 |
| 81 | 48 |
| 82 #endif // V8_HEAP_INCREMENTAL_MARKING_JOB_H_ | 49 #endif // V8_HEAP_INCREMENTAL_MARKING_JOB_H_ |
| OLD | NEW |