5 #ifndef INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
6 #define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
8 #include "cppgc/heap-state.h"
9 #include "cppgc/internal/api-constants.h"
10 #include "cppgc/internal/atomic-entry-flag.h"
11 #include "cppgc/sentinel-pointer.h"
12 #include "cppgc/trace-trait.h"
15 #if defined(CPPGC_CAGED_HEAP)
16 #include "cppgc/internal/caged-heap-local-data.h"
25 class WriteBarrierTypeForCagedHeapPolicy;
26 class WriteBarrierTypeForNonCagedHeapPolicy;
37 HeapHandle*
heap =
nullptr;
41 #if defined(CPPGC_CAGED_HEAP)
60 template <
typename HeapHandleCallback>
62 HeapHandleCallback callback);
64 template <
typename HeapHandleCallback>
66 const void* value,
Params& params, HeapHandleCallback callback);
71 const Params& params,
const void* first_element, size_t element_size,
72 size_t number_of_elements, TraceCallback trace_callback);
75 #if defined(CPPGC_YOUNG_GENERATION)
76 static V8_INLINE
void GenerationalBarrier(
const Params& params,
84 static void CheckParams(Type expected_type,
const Params& params);
91 class IncrementalOrConcurrentMarkingFlagUpdater;
97 WriteBarrier() =
delete;
99 #if defined(CPPGC_CAGED_HEAP)
100 using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
102 using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
105 static void DijkstraMarkingBarrierSlow(
const void* value);
106 static void DijkstraMarkingBarrierSlowWithSentinelCheck(
const void* value);
107 static void DijkstraMarkingBarrierRangeSlow(HeapHandle& heap_handle,
108 const void* first_element,
110 size_t number_of_elements,
111 TraceCallback trace_callback);
112 static void SteeleMarkingBarrierSlow(
const void* value);
113 static void SteeleMarkingBarrierSlowWithSentinelCheck(
const void* value);
115 #if defined(CPPGC_YOUNG_GENERATION)
116 static CagedHeapLocalData& GetLocalData(HeapHandle&);
117 static void GenerationalBarrierSlow(
const CagedHeapLocalData& local_data,
118 const AgeTable& ageTable,
119 const void* slot, uintptr_t value_offset);
122 static AtomicEntryFlag incremental_or_concurrent_marking_flag_;
125 template <WriteBarrier::
Type type>
134 #if defined(CPPGC_CAGED_HEAP)
195 #if defined(CPPGC_YOUNG_GENERATION)
216 #if defined(CPPGC_YOUNG_GENERATION)
245 class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy
final {
247 template <WriteBarrier::
ValueMode value_mode,
typename HeapHandleCallback>
249 WriteBarrier::
Params& params,
250 HeapHandleCallback callback) {
251 return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
254 template <
typename HeapHandleCallback>
256 const void* value, WriteBarrier::
Params& params,
257 HeapHandleCallback callback) {
264 template <WriteBarrier::
ValueMode value_mode>
265 struct ValueModeDispatch;
268 static bool IsMarking(
const void*, HeapHandle**);
270 static bool IsMarking(HeapHandle&);
272 WriteBarrierTypeForNonCagedHeapPolicy() =
delete;
276 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
278 template <
typename HeapHandleCallback>
280 WriteBarrier::
Params& params,
281 HeapHandleCallback callback) {
286 if (IsMarking(object, ¶ms
.heap)) {
294 struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
296 template <
typename HeapHandleCallback>
298 WriteBarrier::
Params& params,
299 HeapHandleCallback callback) {
301 HeapHandle& handle = callback();
302 if (IsMarking(handle)) {
303 params
.heap = &handle;
313 const void* slot,
const void* value, WriteBarrier::
Params& params) {
319 template <
typename HeapHandleCallback>
321 const void* slot, WriteBarrier::
Params& params,
322 HeapHandleCallback callback) {
324 slot,
nullptr, params, callback);
328 template <
typename HeapHandleCallback>
331 const void* value,
Params& params, HeapHandleCallback callback) {
332 return WriteBarrierTypePolicy::GetForExternallyReferenced(value, params,
338 const void* object) {
340 #if defined(CPPGC_CAGED_HEAP)
342 DijkstraMarkingBarrierSlow(object);
344 DijkstraMarkingBarrierSlowWithSentinelCheck(object);
350 const void* first_element,
352 size_t number_of_elements,
353 TraceCallback trace_callback) {
355 DijkstraMarkingBarrierRangeSlow(*params
.heap, first_element, element_size,
356 number_of_elements, trace_callback);
361 const void* object) {
363 #if defined(CPPGC_CAGED_HEAP)
365 SteeleMarkingBarrierSlow(object);
367 SteeleMarkingBarrierSlowWithSentinelCheck(object);
371 #if defined(CPPGC_YOUNG_GENERATION)