5 #ifndef INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
6 #define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
11 #include "cppgc/heap-state.h"
12 #include "cppgc/internal/api-constants.h"
13 #include "cppgc/internal/atomic-entry-flag.h"
14 #include "cppgc/platform.h"
15 #include "cppgc/sentinel-pointer.h"
16 #include "cppgc/trace-trait.h"
19 #if defined(CPPGC_CAGED_HEAP)
20 #include "cppgc/internal/caged-heap-local-data.h"
29 #if defined(CPPGC_CAGED_HEAP)
32 class WriteBarrierTypeForNonCagedHeapPolicy;
44 HeapHandle*
heap =
nullptr;
48 #if defined(CPPGC_CAGED_HEAP)
67 template <
typename HeapHandleCallback>
69 HeapHandleCallback callback);
76 const Params& params,
const void* first_element, size_t element_size,
77 size_t number_of_elements, TraceCallback trace_callback);
80 #if defined(CPPGC_YOUNG_GENERATION)
81 static V8_INLINE
void GenerationalBarrier(
const Params& params,
83 static V8_INLINE
void GenerationalBarrierForSourceObject(
84 const Params& params,
const void* inner_pointer);
89 const Params& params,
const void* inner_pointer) {}
93 static void CheckParams(Type expected_type,
const Params& params);
100 class IncrementalOrConcurrentMarkingFlagUpdater;
106 WriteBarrier() =
delete;
108 #if defined(CPPGC_CAGED_HEAP)
109 using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
111 using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
114 static void DijkstraMarkingBarrierSlow(
const void* value);
115 static void DijkstraMarkingBarrierSlowWithSentinelCheck(
const void* value);
116 static void DijkstraMarkingBarrierRangeSlow(HeapHandle& heap_handle,
117 const void* first_element,
119 size_t number_of_elements,
120 TraceCallback trace_callback);
121 static void SteeleMarkingBarrierSlow(
const void* value);
122 static void SteeleMarkingBarrierSlowWithSentinelCheck(
const void* value);
124 #if defined(CPPGC_YOUNG_GENERATION)
125 static CagedHeapLocalData& GetLocalData(HeapHandle&);
126 static void GenerationalBarrierSlow(
const CagedHeapLocalData& local_data,
127 const AgeTable& age_table,
128 const void* slot, uintptr_t value_offset);
129 static void GenerationalBarrierForSourceObjectSlow(
130 const CagedHeapLocalData& local_data,
const void* object);
133 static AtomicEntryFlag incremental_or_concurrent_marking_flag_;
136 template <WriteBarrier::
Type type>
145 #if defined(CPPGC_CAGED_HEAP)
185 if (!
value)
return false;
212 #if !defined(CPPGC_YOUNG_GENERATION)
222 #if defined(CPPGC_YOUNG_GENERATION)
243 #if defined(CPPGC_YOUNG_GENERATION)
272 class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy
final {
274 template <WriteBarrier::
ValueMode value_mode,
typename HeapHandleCallback>
276 WriteBarrier::
Params& params,
277 HeapHandleCallback callback) {
278 return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
281 template <WriteBarrier::
ValueMode value_mode,
typename HeapHandleCallback>
283 WriteBarrier::
Params& params,
284 HeapHandleCallback callback) {
291 template <WriteBarrier::
ValueMode value_mode>
292 struct ValueModeDispatch;
295 static bool IsMarking(
const void*, HeapHandle**);
297 static bool IsMarking(HeapHandle&);
299 WriteBarrierTypeForNonCagedHeapPolicy() =
delete;
303 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
305 template <
typename HeapHandleCallback>
307 WriteBarrier::
Params& params,
308 HeapHandleCallback callback) {
316 if (IsMarking(object, ¶ms
.heap)) {
324 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
326 template <
typename HeapHandleCallback>
328 WriteBarrier::
Params& params,
329 HeapHandleCallback callback) {
331 HeapHandle& handle = callback();
332 if (IsMarking(handle)) {
333 params
.heap = &handle;
343 const void* slot,
const void* value, WriteBarrier::
Params& params) {
349 template <
typename HeapHandleCallback>
351 const void* slot, WriteBarrier::
Params& params,
352 HeapHandleCallback callback) {
354 slot,
nullptr, params, callback);
359 const void* value, WriteBarrier::
Params& params) {
366 const void* object) {
368 #if defined(CPPGC_CAGED_HEAP)
370 DijkstraMarkingBarrierSlow(object);
372 DijkstraMarkingBarrierSlowWithSentinelCheck(object);
378 const void* first_element,
380 size_t number_of_elements,
381 TraceCallback trace_callback) {
383 DijkstraMarkingBarrierRangeSlow(*params
.heap, first_element, element_size,
384 number_of_elements, trace_callback);
389 const void* object) {
391 #if defined(CPPGC_CAGED_HEAP)
393 SteeleMarkingBarrierSlow(object);
395 SteeleMarkingBarrierSlowWithSentinelCheck(object);
399 #if defined(CPPGC_YOUNG_GENERATION)