libv8-node 15.14.0.1-aarch64-linux-musl → 18.8.0.0-aarch64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +1 -1
  3. data/ext/libv8-node/paths.rb +5 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/{out.gn → aarch64-linux-musl}/libv8/obj/libv8_monolith.a +0 -0
  6. data/vendor/v8/include/cppgc/allocation.h +184 -47
  7. data/vendor/v8/include/cppgc/common.h +9 -6
  8. data/vendor/v8/include/cppgc/cross-thread-persistent.h +465 -0
  9. data/vendor/v8/include/cppgc/custom-space.h +37 -2
  10. data/vendor/v8/include/cppgc/default-platform.h +40 -49
  11. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  12. data/vendor/v8/include/cppgc/explicit-management.h +100 -0
  13. data/vendor/v8/include/cppgc/garbage-collected.h +19 -29
  14. data/vendor/v8/include/cppgc/heap-consistency.h +266 -0
  15. data/vendor/v8/include/cppgc/heap-state.h +82 -0
  16. data/vendor/v8/include/cppgc/heap-statistics.h +120 -0
  17. data/vendor/v8/include/cppgc/heap.h +73 -6
  18. data/vendor/v8/include/cppgc/internal/api-constants.h +11 -3
  19. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +27 -15
  20. data/vendor/v8/include/cppgc/internal/compiler-specific.h +2 -2
  21. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +4 -1
  22. data/vendor/v8/include/cppgc/internal/gc-info.h +124 -13
  23. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  24. data/vendor/v8/include/cppgc/internal/name-trait.h +122 -0
  25. data/vendor/v8/include/cppgc/internal/persistent-node.h +116 -16
  26. data/vendor/v8/include/cppgc/internal/pointer-policies.h +84 -32
  27. data/vendor/v8/include/cppgc/internal/write-barrier.h +392 -35
  28. data/vendor/v8/include/cppgc/liveness-broker.h +11 -2
  29. data/vendor/v8/include/cppgc/macros.h +2 -0
  30. data/vendor/v8/include/cppgc/member.h +91 -26
  31. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  32. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  33. data/vendor/v8/include/cppgc/persistent.h +70 -41
  34. data/vendor/v8/include/cppgc/platform.h +52 -26
  35. data/vendor/v8/include/cppgc/prefinalizer.h +36 -13
  36. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  37. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  38. data/vendor/v8/include/cppgc/source-location.h +2 -1
  39. data/vendor/v8/include/cppgc/testing.h +106 -0
  40. data/vendor/v8/include/cppgc/trace-trait.h +8 -3
  41. data/vendor/v8/include/cppgc/type-traits.h +163 -32
  42. data/vendor/v8/include/cppgc/visitor.h +194 -28
  43. data/vendor/v8/include/libplatform/libplatform.h +11 -11
  44. data/vendor/v8/include/libplatform/v8-tracing.h +2 -1
  45. data/vendor/v8/include/v8-array-buffer.h +445 -0
  46. data/vendor/v8/include/v8-callbacks.h +397 -0
  47. data/vendor/v8/include/v8-container.h +129 -0
  48. data/vendor/v8/include/v8-context.h +407 -0
  49. data/vendor/v8/include/v8-cppgc.h +151 -159
  50. data/vendor/v8/include/v8-data.h +80 -0
  51. data/vendor/v8/include/v8-date.h +43 -0
  52. data/vendor/v8/include/v8-debug.h +168 -0
  53. data/vendor/v8/include/v8-embedder-heap.h +218 -0
  54. data/vendor/v8/include/v8-embedder-state-scope.h +51 -0
  55. data/vendor/v8/include/v8-exception.h +217 -0
  56. data/vendor/v8/include/v8-extension.h +62 -0
  57. data/vendor/v8/include/v8-external.h +37 -0
  58. data/vendor/v8/include/v8-fast-api-calls.h +703 -152
  59. data/vendor/v8/include/v8-forward.h +81 -0
  60. data/vendor/v8/include/v8-function-callback.h +475 -0
  61. data/vendor/v8/include/v8-function.h +125 -0
  62. data/vendor/v8/include/v8-initialization.h +315 -0
  63. data/vendor/v8/include/v8-inspector.h +76 -27
  64. data/vendor/v8/include/v8-internal.h +285 -51
  65. data/vendor/v8/include/v8-isolate.h +1709 -0
  66. data/vendor/v8/include/v8-json.h +47 -0
  67. data/vendor/v8/include/v8-local-handle.h +455 -0
  68. data/vendor/v8/include/v8-locker.h +149 -0
  69. data/vendor/v8/include/v8-maybe.h +137 -0
  70. data/vendor/v8/include/v8-memory-span.h +43 -0
  71. data/vendor/v8/include/v8-message.h +216 -0
  72. data/vendor/v8/include/v8-metrics.h +131 -9
  73. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  74. data/vendor/v8/include/v8-microtask.h +28 -0
  75. data/vendor/v8/include/v8-object.h +775 -0
  76. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  77. data/vendor/v8/include/v8-platform.h +433 -25
  78. data/vendor/v8/include/v8-primitive-object.h +118 -0
  79. data/vendor/v8/include/v8-primitive.h +866 -0
  80. data/vendor/v8/include/v8-profiler.h +149 -10
  81. data/vendor/v8/include/v8-promise.h +174 -0
  82. data/vendor/v8/include/v8-proxy.h +50 -0
  83. data/vendor/v8/include/v8-regexp.h +105 -0
  84. data/vendor/v8/include/v8-script.h +747 -0
  85. data/vendor/v8/include/v8-snapshot.h +196 -0
  86. data/vendor/v8/include/v8-statistics.h +217 -0
  87. data/vendor/v8/include/v8-template.h +1079 -0
  88. data/vendor/v8/include/v8-traced-handle.h +420 -0
  89. data/vendor/v8/include/v8-typed-array.h +282 -0
  90. data/vendor/v8/include/v8-unwinder-state.h +31 -0
  91. data/vendor/v8/include/v8-unwinder.h +132 -0
  92. data/vendor/v8/include/v8-util.h +8 -2
  93. data/vendor/v8/include/v8-value-serializer-version.h +1 -1
  94. data/vendor/v8/include/v8-value-serializer.h +279 -0
  95. data/vendor/v8/include/v8-value.h +526 -0
  96. data/vendor/v8/include/v8-version.h +4 -4
  97. data/vendor/v8/include/v8-wasm.h +257 -0
  98. data/vendor/v8/include/v8-weak-callback-info.h +87 -0
  99. data/vendor/v8/include/v8.h +41 -12051
  100. data/vendor/v8/include/v8config.h +142 -21
  101. metadata +64 -10
  102. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +0 -30
  103. data/vendor/v8/include/cppgc/internal/process-heap.h +0 -34
@@ -5,8 +5,15 @@
5
5
  #ifndef INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
6
6
  #define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
7
7
 
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+
11
+ #include "cppgc/heap-state.h"
8
12
  #include "cppgc/internal/api-constants.h"
9
- #include "cppgc/internal/process-heap.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"
10
17
  #include "v8config.h" // NOLINT(build/include_directory)
11
18
 
12
19
  #if defined(CPPGC_CAGED_HEAP)
@@ -14,64 +21,414 @@
14
21
  #endif
15
22
 
16
23
  namespace cppgc {
24
+
25
+ class HeapHandle;
26
+
17
27
  namespace internal {
18
28
 
29
+ #if defined(CPPGC_CAGED_HEAP)
30
+ class WriteBarrierTypeForCagedHeapPolicy;
31
+ #else // !CPPGC_CAGED_HEAP
32
+ class WriteBarrierTypeForNonCagedHeapPolicy;
33
+ #endif // !CPPGC_CAGED_HEAP
34
+
19
35
  class V8_EXPORT WriteBarrier final {
20
36
  public:
21
- static V8_INLINE void MarkingBarrier(const void* slot, const void* value) {
37
+ enum class Type : uint8_t {
38
+ kNone,
39
+ kMarking,
40
+ kGenerational,
41
+ };
42
+
43
+ struct Params {
44
+ HeapHandle* heap = nullptr;
45
+ #if V8_ENABLE_CHECKS
46
+ Type type = Type::kNone;
47
+ #endif // !V8_ENABLE_CHECKS
22
48
  #if defined(CPPGC_CAGED_HEAP)
23
- const uintptr_t start =
24
- reinterpret_cast<uintptr_t>(value) &
25
- ~(api_constants::kCagedHeapReservationAlignment - 1);
26
- const uintptr_t slot_offset = reinterpret_cast<uintptr_t>(slot) - start;
49
+ uintptr_t start = 0;
50
+ CagedHeapLocalData& caged_heap() const {
51
+ return *reinterpret_cast<CagedHeapLocalData*>(start);
52
+ }
53
+ uintptr_t slot_offset = 0;
54
+ uintptr_t value_offset = 0;
55
+ #endif // CPPGC_CAGED_HEAP
56
+ };
57
+
58
+ enum class ValueMode {
59
+ kValuePresent,
60
+ kNoValuePresent,
61
+ };
62
+
63
+ // Returns the required write barrier for a given `slot` and `value`.
64
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, const void* value,
65
+ Params& params);
66
+ // Returns the required write barrier for a given `slot`.
67
+ template <typename HeapHandleCallback>
68
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, Params& params,
69
+ HeapHandleCallback callback);
70
+ // Returns the required write barrier for a given `value`.
71
+ static V8_INLINE Type GetWriteBarrierType(const void* value, Params& params);
72
+
73
+ static V8_INLINE void DijkstraMarkingBarrier(const Params& params,
74
+ const void* object);
75
+ static V8_INLINE void DijkstraMarkingBarrierRange(
76
+ const Params& params, const void* first_element, size_t element_size,
77
+ size_t number_of_elements, TraceCallback trace_callback);
78
+ static V8_INLINE void SteeleMarkingBarrier(const Params& params,
79
+ const void* object);
80
+ #if defined(CPPGC_YOUNG_GENERATION)
81
+ static V8_INLINE void GenerationalBarrier(const Params& params,
82
+ const void* slot);
83
+ static V8_INLINE void GenerationalBarrierForSourceObject(
84
+ const Params& params, const void* inner_pointer);
85
+ #else // !CPPGC_YOUNG_GENERATION
86
+ static V8_INLINE void GenerationalBarrier(const Params& params,
87
+ const void* slot) {}
88
+ static V8_INLINE void GenerationalBarrierForSourceObject(
89
+ const Params& params, const void* inner_pointer) {}
90
+ #endif // CPPGC_YOUNG_GENERATION
91
+
92
+ #if V8_ENABLE_CHECKS
93
+ static void CheckParams(Type expected_type, const Params& params);
94
+ #else // !V8_ENABLE_CHECKS
95
+ static void CheckParams(Type expected_type, const Params& params) {}
96
+ #endif // !V8_ENABLE_CHECKS
97
+
98
+ // The IncrementalOrConcurrentUpdater class allows cppgc internal to update
99
+ // |incremental_or_concurrent_marking_flag_|.
100
+ class IncrementalOrConcurrentMarkingFlagUpdater;
101
+ static bool IsAnyIncrementalOrConcurrentMarking() {
102
+ return incremental_or_concurrent_marking_flag_.MightBeEntered();
103
+ }
104
+
105
+ private:
106
+ WriteBarrier() = delete;
107
+
108
+ #if defined(CPPGC_CAGED_HEAP)
109
+ using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
110
+ #else // !CPPGC_CAGED_HEAP
111
+ using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
112
+ #endif // !CPPGC_CAGED_HEAP
113
+
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,
118
+ size_t element_size,
119
+ size_t number_of_elements,
120
+ TraceCallback trace_callback);
121
+ static void SteeleMarkingBarrierSlow(const void* value);
122
+ static void SteeleMarkingBarrierSlowWithSentinelCheck(const void* value);
123
+
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);
131
+ #endif // CPPGC_YOUNG_GENERATION
132
+
133
+ static AtomicEntryFlag incremental_or_concurrent_marking_flag_;
134
+ };
135
+
136
+ template <WriteBarrier::Type type>
137
+ V8_INLINE WriteBarrier::Type SetAndReturnType(WriteBarrier::Params& params) {
138
+ if (type == WriteBarrier::Type::kNone) return WriteBarrier::Type::kNone;
139
+ #if V8_ENABLE_CHECKS
140
+ params.type = type;
141
+ #endif // !V8_ENABLE_CHECKS
142
+ return type;
143
+ }
144
+
145
+ #if defined(CPPGC_CAGED_HEAP)
146
+ class V8_EXPORT WriteBarrierTypeForCagedHeapPolicy final {
147
+ public:
148
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
149
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
150
+ WriteBarrier::Params& params,
151
+ HeapHandleCallback callback) {
152
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
153
+ }
154
+
155
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
156
+ static V8_INLINE WriteBarrier::Type Get(const void* value,
157
+ WriteBarrier::Params& params,
158
+ HeapHandleCallback callback) {
159
+ return GetNoSlot(value, params, callback);
160
+ }
161
+
162
+ private:
163
+ WriteBarrierTypeForCagedHeapPolicy() = delete;
164
+
165
+ template <typename HeapHandleCallback>
166
+ static V8_INLINE WriteBarrier::Type GetNoSlot(const void* value,
167
+ WriteBarrier::Params& params,
168
+ HeapHandleCallback) {
169
+ if (!TryGetCagedHeap(value, value, params)) {
170
+ return WriteBarrier::Type::kNone;
171
+ }
172
+ if (V8_UNLIKELY(params.caged_heap().is_incremental_marking_in_progress)) {
173
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
174
+ }
175
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
176
+ }
177
+
178
+ template <WriteBarrier::ValueMode value_mode>
179
+ struct ValueModeDispatch;
180
+
181
+ static V8_INLINE bool TryGetCagedHeap(const void* slot, const void* value,
182
+ WriteBarrier::Params& params) {
183
+ // TODO(chromium:1056170): Check if the null check can be folded in with
184
+ // the rest of the write barrier.
185
+ if (!value) return false;
186
+ params.start = reinterpret_cast<uintptr_t>(value) &
187
+ ~(api_constants::kCagedHeapReservationAlignment - 1);
188
+ const uintptr_t slot_offset =
189
+ reinterpret_cast<uintptr_t>(slot) - params.start;
27
190
  if (slot_offset > api_constants::kCagedHeapReservationSize) {
28
191
  // Check if slot is on stack or value is sentinel or nullptr. This relies
29
192
  // on the fact that kSentinelPointer is encoded as 0x1.
30
- return;
193
+ return false;
31
194
  }
195
+ return true;
196
+ }
32
197
 
33
- CagedHeapLocalData* local_data =
34
- reinterpret_cast<CagedHeapLocalData*>(start);
35
- if (V8_UNLIKELY(local_data->is_marking_in_progress)) {
36
- MarkingBarrierSlow(value);
37
- return;
198
+ // Returns whether marking is in progress. If marking is not in progress
199
+ // sets the start of the cage accordingly.
200
+ //
201
+ // TODO(chromium:1056170): Create fast path on API.
202
+ static bool IsMarking(const HeapHandle&, WriteBarrier::Params&);
203
+ };
204
+
205
+ template <>
206
+ struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
207
+ WriteBarrier::ValueMode::kValuePresent> {
208
+ template <typename HeapHandleCallback>
209
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
210
+ WriteBarrier::Params& params,
211
+ HeapHandleCallback) {
212
+ #if !defined(CPPGC_YOUNG_GENERATION)
213
+ if (V8_LIKELY(!WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
214
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
215
+ }
216
+ #endif // !CPPGC_YOUNG_GENERATION
217
+ bool within_cage = TryGetCagedHeap(slot, value, params);
218
+ if (!within_cage) {
219
+ return WriteBarrier::Type::kNone;
38
220
  }
221
+ if (V8_LIKELY(!params.caged_heap().is_incremental_marking_in_progress)) {
39
222
  #if defined(CPPGC_YOUNG_GENERATION)
40
- GenerationalBarrier(local_data, slot, slot_offset,
41
- reinterpret_cast<uintptr_t>(value) - start);
42
- #endif
43
- #else
44
- if (V8_LIKELY(!ProcessHeap::IsAnyIncrementalOrConcurrentMarking())) return;
223
+ params.heap = reinterpret_cast<HeapHandle*>(params.start);
224
+ params.slot_offset = reinterpret_cast<uintptr_t>(slot) - params.start;
225
+ params.value_offset = reinterpret_cast<uintptr_t>(value) - params.start;
226
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
227
+ #else // !CPPGC_YOUNG_GENERATION
228
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
229
+ #endif // !CPPGC_YOUNG_GENERATION
230
+ }
231
+ params.heap = reinterpret_cast<HeapHandle*>(params.start);
232
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
233
+ }
234
+ };
235
+
236
+ template <>
237
+ struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
238
+ WriteBarrier::ValueMode::kNoValuePresent> {
239
+ template <typename HeapHandleCallback>
240
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void*,
241
+ WriteBarrier::Params& params,
242
+ HeapHandleCallback callback) {
243
+ #if defined(CPPGC_YOUNG_GENERATION)
244
+ HeapHandle& handle = callback();
245
+ if (V8_LIKELY(!IsMarking(handle, params))) {
246
+ // params.start is populated by IsMarking().
247
+ params.heap = &handle;
248
+ params.slot_offset = reinterpret_cast<uintptr_t>(slot) - params.start;
249
+ // params.value_offset stays 0.
250
+ if (params.slot_offset > api_constants::kCagedHeapReservationSize) {
251
+ // Check if slot is on stack.
252
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
253
+ }
254
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
255
+ }
256
+ #else // !CPPGC_YOUNG_GENERATION
257
+ if (V8_LIKELY(!WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
258
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
259
+ }
260
+ HeapHandle& handle = callback();
261
+ if (V8_UNLIKELY(!subtle::HeapState::IsMarking(handle))) {
262
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
263
+ }
264
+ #endif // !CPPGC_YOUNG_GENERATION
265
+ params.heap = &handle;
266
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
267
+ }
268
+ };
45
269
 
46
- MarkingBarrierSlowWithSentinelCheck(value);
47
270
  #endif // CPPGC_CAGED_HEAP
271
+
272
+ class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy final {
273
+ public:
274
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
275
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
276
+ WriteBarrier::Params& params,
277
+ HeapHandleCallback callback) {
278
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
48
279
  }
49
280
 
50
- private:
51
- WriteBarrier() = delete;
281
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
282
+ static V8_INLINE WriteBarrier::Type Get(const void* value,
283
+ WriteBarrier::Params& params,
284
+ HeapHandleCallback callback) {
285
+ // The slot will never be used in `Get()` below.
286
+ return Get<WriteBarrier::ValueMode::kValuePresent>(nullptr, value, params,
287
+ callback);
288
+ }
52
289
 
53
- static void MarkingBarrierSlow(const void* value);
54
- static void MarkingBarrierSlowWithSentinelCheck(const void* value);
290
+ private:
291
+ template <WriteBarrier::ValueMode value_mode>
292
+ struct ValueModeDispatch;
55
293
 
56
- #if defined(CPPGC_YOUNG_GENERATION)
57
- static V8_INLINE void GenerationalBarrier(CagedHeapLocalData* local_data,
58
- const void* slot,
59
- uintptr_t slot_offset,
60
- uintptr_t value_offset) {
61
- const AgeTable& age_table = local_data->age_table;
294
+ // TODO(chromium:1056170): Create fast path on API.
295
+ static bool IsMarking(const void*, HeapHandle**);
296
+ // TODO(chromium:1056170): Create fast path on API.
297
+ static bool IsMarking(HeapHandle&);
62
298
 
63
- // Bail out if the slot is in young generation.
64
- if (V8_LIKELY(age_table[slot_offset] == AgeTable::Age::kYoung)) return;
299
+ WriteBarrierTypeForNonCagedHeapPolicy() = delete;
300
+ };
65
301
 
66
- GenerationalBarrierSlow(local_data, age_table, slot, value_offset);
302
+ template <>
303
+ struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
304
+ WriteBarrier::ValueMode::kValuePresent> {
305
+ template <typename HeapHandleCallback>
306
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void* object,
307
+ WriteBarrier::Params& params,
308
+ HeapHandleCallback callback) {
309
+ // The following check covers nullptr as well as sentinel pointer.
310
+ if (object <= static_cast<void*>(kSentinelPointer)) {
311
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
312
+ }
313
+ if (V8_LIKELY(!WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
314
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
315
+ }
316
+ if (IsMarking(object, &params.heap)) {
317
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
318
+ }
319
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
67
320
  }
321
+ };
68
322
 
69
- static void GenerationalBarrierSlow(CagedHeapLocalData* local_data,
70
- const AgeTable& ageTable,
71
- const void* slot, uintptr_t value_offset);
72
- #endif
323
+ template <>
324
+ struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
325
+ WriteBarrier::ValueMode::kNoValuePresent> {
326
+ template <typename HeapHandleCallback>
327
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void*,
328
+ WriteBarrier::Params& params,
329
+ HeapHandleCallback callback) {
330
+ if (V8_UNLIKELY(WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
331
+ HeapHandle& handle = callback();
332
+ if (IsMarking(handle)) {
333
+ params.heap = &handle;
334
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
335
+ }
336
+ }
337
+ return WriteBarrier::Type::kNone;
338
+ }
73
339
  };
74
340
 
341
+ // static
342
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
343
+ const void* slot, const void* value, WriteBarrier::Params& params) {
344
+ return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(slot, value,
345
+ params, []() {});
346
+ }
347
+
348
+ // static
349
+ template <typename HeapHandleCallback>
350
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
351
+ const void* slot, WriteBarrier::Params& params,
352
+ HeapHandleCallback callback) {
353
+ return WriteBarrierTypePolicy::Get<ValueMode::kNoValuePresent>(
354
+ slot, nullptr, params, callback);
355
+ }
356
+
357
+ // static
358
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
359
+ const void* value, WriteBarrier::Params& params) {
360
+ return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(value, params,
361
+ []() {});
362
+ }
363
+
364
+ // static
365
+ void WriteBarrier::DijkstraMarkingBarrier(const Params& params,
366
+ const void* object) {
367
+ CheckParams(Type::kMarking, params);
368
+ #if defined(CPPGC_CAGED_HEAP)
369
+ // Caged heap already filters out sentinels.
370
+ DijkstraMarkingBarrierSlow(object);
371
+ #else // !CPPGC_CAGED_HEAP
372
+ DijkstraMarkingBarrierSlowWithSentinelCheck(object);
373
+ #endif // !CPPGC_CAGED_HEAP
374
+ }
375
+
376
+ // static
377
+ void WriteBarrier::DijkstraMarkingBarrierRange(const Params& params,
378
+ const void* first_element,
379
+ size_t element_size,
380
+ size_t number_of_elements,
381
+ TraceCallback trace_callback) {
382
+ CheckParams(Type::kMarking, params);
383
+ DijkstraMarkingBarrierRangeSlow(*params.heap, first_element, element_size,
384
+ number_of_elements, trace_callback);
385
+ }
386
+
387
+ // static
388
+ void WriteBarrier::SteeleMarkingBarrier(const Params& params,
389
+ const void* object) {
390
+ CheckParams(Type::kMarking, params);
391
+ #if defined(CPPGC_CAGED_HEAP)
392
+ // Caged heap already filters out sentinels.
393
+ SteeleMarkingBarrierSlow(object);
394
+ #else // !CPPGC_CAGED_HEAP
395
+ SteeleMarkingBarrierSlowWithSentinelCheck(object);
396
+ #endif // !CPPGC_CAGED_HEAP
397
+ }
398
+
399
+ #if defined(CPPGC_YOUNG_GENERATION)
400
+ // static
401
+ void WriteBarrier::GenerationalBarrier(const Params& params, const void* slot) {
402
+ CheckParams(Type::kGenerational, params);
403
+
404
+ const CagedHeapLocalData& local_data = params.caged_heap();
405
+ const AgeTable& age_table = local_data.age_table;
406
+
407
+ // Bail out if the slot is in young generation.
408
+ if (V8_LIKELY(age_table.GetAge(params.slot_offset) == AgeTable::Age::kYoung))
409
+ return;
410
+
411
+ GenerationalBarrierSlow(local_data, age_table, slot, params.value_offset);
412
+ }
413
+
414
+ // static
415
+ void WriteBarrier::GenerationalBarrierForSourceObject(
416
+ const Params& params, const void* inner_pointer) {
417
+ CheckParams(Type::kGenerational, params);
418
+
419
+ const CagedHeapLocalData& local_data = params.caged_heap();
420
+ const AgeTable& age_table = local_data.age_table;
421
+
422
+ // Assume that if the first element is in young generation, the whole range is
423
+ // in young generation.
424
+ if (V8_LIKELY(age_table.GetAge(params.slot_offset) == AgeTable::Age::kYoung))
425
+ return;
426
+
427
+ GenerationalBarrierForSourceObjectSlow(local_data, inner_pointer);
428
+ }
429
+
430
+ #endif // !CPPGC_YOUNG_GENERATION
431
+
75
432
  } // namespace internal
76
433
  } // namespace cppgc
77
434
 
@@ -19,7 +19,7 @@ class LivenessBrokerFactory;
19
19
  /**
20
20
  * The broker is passed to weak callbacks to allow (temporarily) querying
21
21
  * the liveness state of an object. References to non-live objects must be
22
- * cleared when IsHeapObjectAlive() returns false.
22
+ * cleared when `IsHeapObjectAlive()` returns false.
23
23
  *
24
24
  * \code
25
25
  * class GCedWithCustomWeakCallback final
@@ -44,11 +44,20 @@ class V8_EXPORT LivenessBroker final {
44
44
  public:
45
45
  template <typename T>
46
46
  bool IsHeapObjectAlive(const T* object) const {
47
- return object &&
47
+ // nullptr objects are considered alive to allow weakness to be used from
48
+ // stack while running into a conservative GC. Treating nullptr as dead
49
+ // would mean that e.g. custom collectins could not be strongified on stack.
50
+ return !object ||
48
51
  IsHeapObjectAliveImpl(
49
52
  TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
50
53
  }
51
54
 
55
+ template <typename T>
56
+ bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
57
+ return (weak_member != kSentinelPointer) &&
58
+ IsHeapObjectAlive<T>(weak_member.Get());
59
+ }
60
+
52
61
  template <typename T>
53
62
  bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
54
63
  return (untraced_member != kSentinelPointer) &&
@@ -5,6 +5,8 @@
5
5
  #ifndef INCLUDE_CPPGC_MACROS_H_
6
6
  #define INCLUDE_CPPGC_MACROS_H_
7
7
 
8
+ #include <cstddef>
9
+
8
10
  #include "cppgc/internal/compiler-specific.h"
9
11
 
10
12
  namespace cppgc {