47 kReduceMemory = 1 << 1,
57 static constexpr int kMaxBatchedEvents = 16;
61 void AddMainThreadEvent(
const GCCycle& cppgc_event)
final;
62 void AddMainThreadEvent(
const MainThreadIncrementalMark& cppgc_event)
final;
63 void AddMainThreadEvent(
64 const MainThreadIncrementalSweep& cppgc_event)
final;
66 void FlushBatchedIncrementalEvents();
70 bool FullGCMetricsReportPending()
const;
71 bool YoungGCMetricsReportPending()
const;
73 const std::optional<cppgc::internal::MetricRecorder::GCCycle>
74 ExtractLastFullGcEvent();
75 const std::optional<cppgc::internal::MetricRecorder::GCCycle>
76 ExtractLastYoungGcEvent();
79 ExtractLastIncrementalMarkEvent();
81 void ClearCachedEvents();
94 std::optional<cppgc::internal::MetricRecorder::GCCycle>
96 std::optional<cppgc::internal::MetricRecorder::MainThreadIncrementalMark>
100 static void InitializeOncePerProcess();
110 const std::vector<std::unique_ptr<cppgc::CustomSpaceBase>>&,
120 void AttachIsolate(
Isolate* isolate);
121 void StartDetachingIsolate();
122 void DetachIsolate();
126 void CollectCustomSpaceStatisticsAtLastGC(
127 std::vector<cppgc::CustomSpaceIndex>,
128 std::unique_ptr<CustomSpaceStatisticsReceiver>);
130 void FinishSweepingIfRunning();
131 void FinishAtomicSweepingIfRunning();
132 void FinishSweepingIfOutOfWork();
134 void InitializeMarking(
136 std::shared_ptr<::heap::base::IncrementalMarkingSchedule>
schedule = {},
137 GarbageCollectionFlags = GarbageCollectionFlagValues::kNoFlags);
140 size_t marked_bytes_limit);
141 bool IsMarkingDone()
const;
142 size_t last_bytes_marked()
const;
143 void ProcessCrossThreadWeakness();
144 void FinishMarkingAndProcessWeakness();
145 void CompactAndSweep();
147 void EnterProcessGlobalAtomicPause();
148 bool FinishConcurrentMarkingIfNeeded();
154 void ReEnableConcurrentMarking();
156 void WriteBarrier(
void*);
158 bool ShouldFinalizeIncrementalMarking()
const;
161 void AllocatedObjectSizeIncreased(
size_t)
final;
162 void AllocatedObjectSizeDecreased(
size_t)
final;
165 MetricRecorderAdapter* GetMetricRecorder()
const;
170 return used_size_.load(std::memory_order_relaxed);
180 void CollectGarbage(
cppgc::internal::GCConfig) override;
182 std::optional<
cppgc::EmbedderStackState> overridden_stack_state()
184 void set_override_stack_state(
cppgc::EmbedderStackState state) override;
185 void clear_overridden_stack_state() override;
187 void StartIncrementalGarbageCollection(
cppgc::internal::GCConfig) override;
188 size_t epoch() const override;
189#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
190 std::optional<int> UpdateAllocationTimeout() final;
193 V8_INLINE void RememberCrossHeapReferenceIfNeeded(
195 template <
typename F>
196 inline void VisitCrossHeapRememberedSetIfNeeded(
F f);
197 void ResetCrossHeapRememberedSet();
200 void EnableDetachedGarbageCollectionsForTesting();
201 void CollectGarbageForTesting(CollectionType,
StackState);
202 void UpdateGCCapabilitiesFromFlagsForTesting();
204 bool CurrentThreadIsHeapThread() const final;
207 void UpdateGCCapabilitiesFromFlags();
209 void FinalizeIncrementalGarbageCollectionIfNeeded(
214 marking_done_ =
true;
217 void ReportBufferedAllocationSizeIfPossible();
219 void StartIncrementalGarbageCollectionForTesting() final;
220 void FinalizeIncrementalGarbageCollectionForTesting(
221 cppgc::EmbedderStackState) final;
223 MarkingType SelectMarkingType() const;
224 SweepingType SelectSweepingType() const;
228 bool IsGCForbidden()
const override;
229 bool IsGCAllowed()
const override;
230 bool IsDetachedGCAllowed()
const;
236 bool marking_done_ =
true;
244 std::unique_ptr<cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver>
250 int64_t buffered_allocated_bytes_ = 0;
252 bool in_detached_testing_mode_ =
false;
253 bool force_incremental_marking_for_testing_ =
false;
254 bool is_in_v8_marking_step_ =
false;
257 std::atomic<size_t> used_size_{0};
260 size_t allocated_size_ = 0;
263 size_t allocated_size_limit_for_check_ = 0;
266 std::unique_ptr<v8::internal::EmbedderStackStateScope>
268#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
270 std::optional<v8::base::RandomNumberGenerator> allocation_timeout_rng_;
273 bool already_terminated_ =
false;
274 bool is_detached_ =
true;