5 #include "src/heap/incremental-marking-job.h" 7 #include "src/base/platform/time.h" 8 #include "src/heap/embedder-tracing.h" 9 #include "src/heap/heap-inl.h" 10 #include "src/heap/heap.h" 11 #include "src/heap/incremental-marking.h" 12 #include "src/isolate.h" 14 #include "src/vm-state-inl.h" 21 static void Step(
Heap* heap,
22 EmbedderHeapTracer::EmbedderStackState stack_state);
25 EmbedderHeapTracer::EmbedderStackState stack_state)
29 stack_state_(stack_state) {}
32 void RunInternal()
override;
34 Isolate* isolate()
const {
return isolate_; }
39 const EmbedderHeapTracer::EmbedderStackState stack_state_;
42 void IncrementalMarkingJob::Start(
Heap* heap) {
43 DCHECK(!heap->incremental_marking()->IsStopped());
47 void IncrementalMarkingJob::ScheduleTask(
Heap* heap) {
48 if (!task_pending_ && !heap->IsTearingDown()) {
49 v8::Isolate* isolate =
reinterpret_cast<v8::Isolate*
>(heap->isolate());
52 V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
53 if (taskrunner->NonNestableTasksEnabled()) {
54 taskrunner->PostNonNestableTask(base::make_unique<Task>(
55 heap->isolate(),
this,
56 EmbedderHeapTracer::EmbedderStackState::kEmpty));
58 taskrunner->PostTask(base::make_unique<Task>(
59 heap->isolate(),
this,
60 EmbedderHeapTracer::EmbedderStackState::kUnknown));
65 void IncrementalMarkingJob::Task::Step(
66 Heap* heap, EmbedderHeapTracer::EmbedderStackState stack_state) {
67 const int kIncrementalMarkingDelayMs = 1;
69 heap->MonotonicallyIncreasingTimeInMs() + kIncrementalMarkingDelayMs;
70 heap->incremental_marking()->AdvanceIncrementalMarking(
71 deadline, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
72 i::StepOrigin::kTask);
74 EmbedderStackStateScope scope(heap->local_embedder_heap_tracer(),
76 heap->FinalizeIncrementalMarkingIfComplete(
77 GarbageCollectionReason::kFinalizeMarkingViaTask);
81 void IncrementalMarkingJob::Task::RunInternal() {
82 VMState<GC> state(isolate());
83 TRACE_EVENT_CALL_STATS_SCOPED(isolate(),
"v8",
"V8.Task");
85 Heap* heap = isolate()->heap();
86 IncrementalMarking* incremental_marking = heap->incremental_marking();
87 if (incremental_marking->IsStopped()) {
88 if (heap->IncrementalMarkingLimitReached() !=
89 Heap::IncrementalMarkingLimit::kNoLimit) {
90 heap->StartIncrementalMarking(heap->GCFlagsForIncrementalMarking(),
91 GarbageCollectionReason::kIdleTask,
92 kGCCallbackScheduleIdleGarbageCollection);
98 job_->task_pending_ =
false;
100 if (!incremental_marking->IsStopped()) {
101 Step(heap, stack_state_);
102 if (!incremental_marking->IsStopped()) {
103 job_->ScheduleTask(heap);