Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/heap/incremental-marking-job.h"
6 :
7 : #include "src/base/platform/time.h"
8 : #include "src/heap/heap-inl.h"
9 : #include "src/heap/heap.h"
10 : #include "src/heap/incremental-marking.h"
11 : #include "src/isolate.h"
12 : #include "src/v8.h"
13 : #include "src/vm-state-inl.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 :
18 19399 : void IncrementalMarkingJob::Start(Heap* heap) {
19 : DCHECK(!heap->incremental_marking()->IsStopped());
20 19399 : ScheduleTask(heap);
21 19399 : }
22 :
23 61511 : void IncrementalMarkingJob::ScheduleTask(Heap* heap) {
24 61511 : if (!task_pending_) {
25 : v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap->isolate());
26 50268 : task_pending_ = true;
27 50268 : auto task = new Task(heap->isolate(), this);
28 50268 : V8::GetCurrentPlatform()->CallOnForegroundThread(isolate, task);
29 : }
30 61511 : }
31 :
32 98784 : void IncrementalMarkingJob::Task::Step(Heap* heap) {
33 : const int kIncrementalMarkingDelayMs = 1;
34 : double deadline =
35 49392 : heap->MonotonicallyIncreasingTimeInMs() + kIncrementalMarkingDelayMs;
36 : heap->incremental_marking()->AdvanceIncrementalMarking(
37 : deadline, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
38 49392 : i::StepOrigin::kTask);
39 : heap->FinalizeIncrementalMarkingIfComplete(
40 49392 : GarbageCollectionReason::kFinalizeMarkingViaTask);
41 49392 : }
42 :
43 99454 : void IncrementalMarkingJob::Task::RunInternal() {
44 : VMState<GC> state(isolate());
45 149181 : TRACE_EVENT_CALL_STATS_SCOPED(isolate(), "v8", "V8.Task");
46 :
47 49727 : Heap* heap = isolate()->heap();
48 : IncrementalMarking* incremental_marking = heap->incremental_marking();
49 49727 : if (incremental_marking->IsStopped()) {
50 738 : if (heap->IncrementalMarkingLimitReached() !=
51 : Heap::IncrementalMarkingLimit::kNoLimit) {
52 : heap->StartIncrementalMarking(Heap::kNoGCFlags,
53 : GarbageCollectionReason::kIdleTask,
54 403 : kGCCallbackScheduleIdleGarbageCollection);
55 : }
56 : }
57 :
58 : // Clear this flag after StartIncrementalMarking call to avoid
59 : // scheduling a new task when startining incremental marking.
60 49727 : job_->task_pending_ = false;
61 :
62 49727 : if (!incremental_marking->IsStopped()) {
63 49392 : Step(heap);
64 49392 : if (!incremental_marking->IsStopped()) {
65 34811 : job_->ScheduleTask(heap);
66 : }
67 : }
68 49727 : }
69 :
70 : } // namespace internal
71 : } // namespace v8
|