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);
71 template <
typename HeapHandleCallback>
73 const void* value,
Params& params, HeapHandleCallback callback);
78 const Params& params,
const void* first_element, size_t element_size,
79 size_t number_of_elements, TraceCallback trace_callback);
82 #if defined(CPPGC_YOUNG_GENERATION)
83 static V8_INLINE
void GenerationalBarrier(
const Params& params,
91 static void CheckParams(Type expected_type,
const Params& params);
98 class IncrementalOrConcurrentMarkingFlagUpdater;
104 WriteBarrier() =
delete;
106 #if defined(CPPGC_CAGED_HEAP)
107 using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
109 using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
112 static void DijkstraMarkingBarrierSlow(
const void* value);
113 static void DijkstraMarkingBarrierSlowWithSentinelCheck(
const void* value);
114 static void DijkstraMarkingBarrierRangeSlow(HeapHandle& heap_handle,
115 const void* first_element,
117 size_t number_of_elements,
118 TraceCallback trace_callback);
119 static void SteeleMarkingBarrierSlow(
const void* value);
120 static void SteeleMarkingBarrierSlowWithSentinelCheck(
const void* value);
122 #if defined(CPPGC_YOUNG_GENERATION)
123 static CagedHeapLocalData& GetLocalData(HeapHandle&);
124 static void GenerationalBarrierSlow(
const CagedHeapLocalData& local_data,
125 const AgeTable& ageTable,
126 const void* slot, uintptr_t value_offset);
129 static AtomicEntryFlag incremental_or_concurrent_marking_flag_;
132 template <WriteBarrier::
Type type>
141 #if defined(CPPGC_CAGED_HEAP)
180 if (!
value)
return false;
213 #if defined(CPPGC_YOUNG_GENERATION)
234 #if defined(CPPGC_YOUNG_GENERATION)
263 class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy
final {
265 template <WriteBarrier::
ValueMode value_mode,
typename HeapHandleCallback>
267 WriteBarrier::
Params& params,
268 HeapHandleCallback callback) {
269 return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
272 template <
typename HeapHandleCallback>
274 const void* value, WriteBarrier::
Params& params,
275 HeapHandleCallback callback) {
282 template <WriteBarrier::
ValueMode value_mode>
283 struct ValueModeDispatch;
286 static bool IsMarking(
const void*, HeapHandle**);
288 static bool IsMarking(HeapHandle&);
290 WriteBarrierTypeForNonCagedHeapPolicy() =
delete;
294 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
296 template <
typename HeapHandleCallback>
298 WriteBarrier::
Params& params,
299 HeapHandleCallback callback) {
304 if (IsMarking(object, ¶ms
.heap)) {
312 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
314 template <
typename HeapHandleCallback>
316 WriteBarrier::
Params& params,
317 HeapHandleCallback callback) {
319 HeapHandle& handle = callback();
320 if (IsMarking(handle)) {
321 params
.heap = &handle;
331 const void* slot,
const void* value, WriteBarrier::
Params& params) {
337 template <
typename HeapHandleCallback>
339 const void* slot, WriteBarrier::
Params& params,
340 HeapHandleCallback callback) {
342 slot,
nullptr, params, callback);
346 template <
typename HeapHandleCallback>
349 const void* value,
Params& params, HeapHandleCallback callback) {
350 return WriteBarrierTypePolicy::GetForExternallyReferenced(value, params,
356 const void* object) {
358 #if defined(CPPGC_CAGED_HEAP)
360 DijkstraMarkingBarrierSlow(object);
362 DijkstraMarkingBarrierSlowWithSentinelCheck(object);
368 const void* first_element,
370 size_t number_of_elements,
371 TraceCallback trace_callback) {
373 DijkstraMarkingBarrierRangeSlow(*params
.heap, first_element, element_size,
374 number_of_elements, trace_callback);
379 const void* object) {
381 #if defined(CPPGC_CAGED_HEAP)
383 SteeleMarkingBarrierSlow(object);
385 SteeleMarkingBarrierSlowWithSentinelCheck(object);
389 #if defined(CPPGC_YOUNG_GENERATION)