v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
concurrent-marking.h
Go to the documentation of this file.
1// Copyright 2017 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#ifndef V8_HEAP_CONCURRENT_MARKING_H_
6#define V8_HEAP_CONCURRENT_MARKING_H_
7
8#include <atomic>
9#include <memory>
10#include <optional>
11
12#include "include/v8-platform.h"
18#include "src/heap/slot-set.h"
19#include "src/heap/spaces.h"
21#include "src/init/v8.h"
24#include "src/utils/utils.h"
25
26namespace v8 {
27namespace internal {
28
29class Heap;
30class Isolate;
31class NonAtomicMarkingState;
32class MutablePageMetadata;
33class WeakObjects;
34
36 public:
37 ConcurrentMarking(Heap* heap, WeakObjects* weak_objects);
39
40 // Schedules asynchronous job to perform concurrent marking at |priority|.
41 // Objects in the heap should not be moved while these are active (can be
42 // stopped safely via Stop() or PauseScope).
43 void TryScheduleJob(GarbageCollector garbage_collector,
44 TaskPriority priority = TaskPriority::kUserVisible);
45
46 // Waits for scheduled job to complete.
47 void Join();
48
49 // Joins scheduled job for testing.
50 void JoinJobForTesting();
51
52 // Preempts ongoing job ASAP. Returns true if concurrent marking was in
53 // progress, false otherwise.
54 bool Pause();
55
56 // Schedules asynchronous job to perform concurrent marking at |priority| if
57 // not already running, otherwise adjusts the number of workers running job
58 // and the priority if different from the default kUserVisible.
59 void RescheduleJobIfNeeded(
60 GarbageCollector garbage_collector,
61 TaskPriority priority = TaskPriority::kUserVisible);
62 // Flushes native context sizes to the given table of the main thread.
63 void FlushNativeContexts(NativeContextStats* main_stats);
64 // Flushes memory chunk data.
65 void FlushMemoryChunkData();
66 // Flushes pretenuring feedback.
67 void FlushPretenuringFeedback();
68
69 // Checks if all threads are stopped.
70 bool IsStopped();
71
72 size_t TotalMarkedBytes();
73
74 void set_another_ephemeron_iteration(bool another_ephemeron_iteration) {
75 another_ephemeron_iteration_.store(another_ephemeron_iteration);
76 }
78 return another_ephemeron_iteration_.load();
79 }
80
82 DCHECK(garbage_collector_.has_value());
83 return garbage_collector_.value();
84 }
85
86 bool IsWorkLeft() const;
87
89 const size_t estimate =
90 estimate_concurrency_.exchange(0, std::memory_order_relaxed);
91 return estimate ? estimate : 1;
92 }
93
94 private:
95 struct TaskState;
96 class JobTaskMinor;
97 class JobTaskMajor;
98 class MinorMarkingState;
99
100 void RunMinor(JobDelegate* delegate);
101 template <YoungGenerationMarkingVisitationMode marking_mode>
102 size_t RunMinorImpl(JobDelegate* delegate, TaskState* task_state);
103 void RunMajor(JobDelegate* delegate,
104 base::EnumSet<CodeFlushMode> code_flush_mode,
105 unsigned mark_compact_epoch, bool should_keep_ages_unchanged);
106 size_t GetMajorMaxConcurrency(size_t worker_count);
107 size_t GetMinorMaxConcurrency(size_t worker_count);
108 void Resume();
109
110 std::unique_ptr<JobHandle> job_handle_;
111 Heap* const heap_;
112 std::optional<GarbageCollector> garbage_collector_;
115 std::vector<std::unique_ptr<TaskState>> task_state_;
116 std::atomic<size_t> total_marked_bytes_{0};
117 std::atomic<bool> another_ephemeron_iteration_{false};
118 std::optional<uint64_t> current_job_trace_id_;
119 std::unique_ptr<MinorMarkingState> minor_marking_state_;
120 std::atomic<size_t> estimate_concurrency_{0};
121
122 friend class Heap;
123};
124
125} // namespace internal
126} // namespace v8
127
128#endif // V8_HEAP_CONCURRENT_MARKING_H_
std::optional< GarbageCollector > garbage_collector_
std::optional< uint64_t > current_job_trace_id_
std::unique_ptr< JobHandle > job_handle_
std::unique_ptr< MinorMarkingState > minor_marking_state_
GarbageCollector garbage_collector() const
std::vector< std::unique_ptr< TaskState > > task_state_
size_t RunMinorImpl(JobDelegate *delegate, TaskState *task_state)
void set_another_ephemeron_iteration(bool another_ephemeron_iteration)
size_t priority
TaskPriority
Definition v8-platform.h:24
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460