@babylonjs/v8-android-jit-nointl-nosnapshot 11.110.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/include/APIDesign.md +72 -0
  2. package/dist/include/DEPS +10 -0
  3. package/dist/include/DIR_METADATA +11 -0
  4. package/dist/include/OWNERS +23 -0
  5. package/dist/include/cppgc/DEPS +8 -0
  6. package/dist/include/cppgc/OWNERS +2 -0
  7. package/dist/include/cppgc/README.md +135 -0
  8. package/dist/include/cppgc/allocation.h +310 -0
  9. package/dist/include/cppgc/common.h +28 -0
  10. package/dist/include/cppgc/cross-thread-persistent.h +464 -0
  11. package/dist/include/cppgc/custom-space.h +97 -0
  12. package/dist/include/cppgc/default-platform.h +67 -0
  13. package/dist/include/cppgc/ephemeron-pair.h +30 -0
  14. package/dist/include/cppgc/explicit-management.h +100 -0
  15. package/dist/include/cppgc/garbage-collected.h +106 -0
  16. package/dist/include/cppgc/heap-consistency.h +309 -0
  17. package/dist/include/cppgc/heap-handle.h +48 -0
  18. package/dist/include/cppgc/heap-state.h +82 -0
  19. package/dist/include/cppgc/heap-statistics.h +120 -0
  20. package/dist/include/cppgc/heap.h +202 -0
  21. package/dist/include/cppgc/internal/api-constants.h +65 -0
  22. package/dist/include/cppgc/internal/atomic-entry-flag.h +48 -0
  23. package/dist/include/cppgc/internal/base-page-handle.h +45 -0
  24. package/dist/include/cppgc/internal/caged-heap-local-data.h +111 -0
  25. package/dist/include/cppgc/internal/caged-heap.h +61 -0
  26. package/dist/include/cppgc/internal/compiler-specific.h +38 -0
  27. package/dist/include/cppgc/internal/finalizer-trait.h +93 -0
  28. package/dist/include/cppgc/internal/gc-info.h +155 -0
  29. package/dist/include/cppgc/internal/logging.h +50 -0
  30. package/dist/include/cppgc/internal/member-storage.h +236 -0
  31. package/dist/include/cppgc/internal/name-trait.h +137 -0
  32. package/dist/include/cppgc/internal/persistent-node.h +214 -0
  33. package/dist/include/cppgc/internal/pointer-policies.h +207 -0
  34. package/dist/include/cppgc/internal/write-barrier.h +477 -0
  35. package/dist/include/cppgc/liveness-broker.h +78 -0
  36. package/dist/include/cppgc/macros.h +26 -0
  37. package/dist/include/cppgc/member.h +566 -0
  38. package/dist/include/cppgc/name-provider.h +65 -0
  39. package/dist/include/cppgc/object-size-trait.h +58 -0
  40. package/dist/include/cppgc/persistent.h +366 -0
  41. package/dist/include/cppgc/platform.h +158 -0
  42. package/dist/include/cppgc/prefinalizer.h +75 -0
  43. package/dist/include/cppgc/process-heap-statistics.h +36 -0
  44. package/dist/include/cppgc/sentinel-pointer.h +32 -0
  45. package/dist/include/cppgc/source-location.h +92 -0
  46. package/dist/include/cppgc/testing.h +106 -0
  47. package/dist/include/cppgc/trace-trait.h +120 -0
  48. package/dist/include/cppgc/type-traits.h +249 -0
  49. package/dist/include/cppgc/visitor.h +411 -0
  50. package/dist/include/js_protocol-1.2.json +997 -0
  51. package/dist/include/js_protocol-1.3.json +1159 -0
  52. package/dist/include/js_protocol.pdl +1766 -0
  53. package/dist/include/libplatform/DEPS +9 -0
  54. package/dist/include/libplatform/libplatform-export.h +29 -0
  55. package/dist/include/libplatform/libplatform.h +106 -0
  56. package/dist/include/libplatform/v8-tracing.h +333 -0
  57. package/dist/include/v8-array-buffer.h +512 -0
  58. package/dist/include/v8-callbacks.h +412 -0
  59. package/dist/include/v8-container.h +129 -0
  60. package/dist/include/v8-context.h +415 -0
  61. package/dist/include/v8-cppgc.h +231 -0
  62. package/dist/include/v8-data.h +80 -0
  63. package/dist/include/v8-date.h +48 -0
  64. package/dist/include/v8-debug.h +168 -0
  65. package/dist/include/v8-embedder-heap.h +223 -0
  66. package/dist/include/v8-embedder-state-scope.h +51 -0
  67. package/dist/include/v8-exception.h +217 -0
  68. package/dist/include/v8-extension.h +62 -0
  69. package/dist/include/v8-external.h +37 -0
  70. package/dist/include/v8-fast-api-calls.h +957 -0
  71. package/dist/include/v8-forward.h +81 -0
  72. package/dist/include/v8-function-callback.h +475 -0
  73. package/dist/include/v8-function.h +133 -0
  74. package/dist/include/v8-initialization.h +289 -0
  75. package/dist/include/v8-inspector-protocol.h +13 -0
  76. package/dist/include/v8-inspector.h +397 -0
  77. package/dist/include/v8-internal.h +851 -0
  78. package/dist/include/v8-isolate.h +1695 -0
  79. package/dist/include/v8-json.h +47 -0
  80. package/dist/include/v8-local-handle.h +455 -0
  81. package/dist/include/v8-locker.h +138 -0
  82. package/dist/include/v8-maybe.h +160 -0
  83. package/dist/include/v8-memory-span.h +43 -0
  84. package/dist/include/v8-message.h +214 -0
  85. package/dist/include/v8-metrics.h +311 -0
  86. package/dist/include/v8-microtask-queue.h +157 -0
  87. package/dist/include/v8-microtask.h +28 -0
  88. package/dist/include/v8-object.h +768 -0
  89. package/dist/include/v8-persistent-handle.h +588 -0
  90. package/dist/include/v8-platform.h +1130 -0
  91. package/dist/include/v8-primitive-object.h +118 -0
  92. package/dist/include/v8-primitive.h +866 -0
  93. package/dist/include/v8-profiler.h +1277 -0
  94. package/dist/include/v8-promise.h +174 -0
  95. package/dist/include/v8-proxy.h +50 -0
  96. package/dist/include/v8-regexp.h +106 -0
  97. package/dist/include/v8-script.h +803 -0
  98. package/dist/include/v8-snapshot.h +196 -0
  99. package/dist/include/v8-statistics.h +217 -0
  100. package/dist/include/v8-template.h +1018 -0
  101. package/dist/include/v8-traced-handle.h +420 -0
  102. package/dist/include/v8-typed-array.h +282 -0
  103. package/dist/include/v8-unwinder-state.h +31 -0
  104. package/dist/include/v8-unwinder.h +132 -0
  105. package/dist/include/v8-util.h +656 -0
  106. package/dist/include/v8-value-serializer-version.h +24 -0
  107. package/dist/include/v8-value-serializer.h +302 -0
  108. package/dist/include/v8-value.h +531 -0
  109. package/dist/include/v8-version-string.h +38 -0
  110. package/dist/include/v8-version.h +20 -0
  111. package/dist/include/v8-wasm-trap-handler-posix.h +31 -0
  112. package/dist/include/v8-wasm-trap-handler-win.h +28 -0
  113. package/dist/include/v8-wasm.h +200 -0
  114. package/dist/include/v8-weak-callback-info.h +80 -0
  115. package/dist/include/v8.h +88 -0
  116. package/dist/include/v8config.h +904 -0
  117. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar +0 -0
  118. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.md5 +1 -0
  119. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.sha1 +1 -0
  120. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom +10 -0
  121. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.md5 +1 -0
  122. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.sha1 +1 -0
  123. package/dist/org/chromium/v8-android/maven-metadata.xml +12 -0
  124. package/dist/org/chromium/v8-android/maven-metadata.xml.md5 +1 -0
  125. package/dist/org/chromium/v8-android/maven-metadata.xml.sha1 +1 -0
  126. package/package.json +24 -0
@@ -0,0 +1,477 @@
1
+ // Copyright 2020 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
7
+
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+
11
+ #include "cppgc/heap-handle.h"
12
+ #include "cppgc/heap-state.h"
13
+ #include "cppgc/internal/api-constants.h"
14
+ #include "cppgc/internal/atomic-entry-flag.h"
15
+ #include "cppgc/internal/base-page-handle.h"
16
+ #include "cppgc/internal/member-storage.h"
17
+ #include "cppgc/platform.h"
18
+ #include "cppgc/sentinel-pointer.h"
19
+ #include "cppgc/trace-trait.h"
20
+ #include "v8config.h" // NOLINT(build/include_directory)
21
+
22
+ #if defined(CPPGC_CAGED_HEAP)
23
+ #include "cppgc/internal/caged-heap-local-data.h"
24
+ #include "cppgc/internal/caged-heap.h"
25
+ #endif
26
+
27
+ namespace cppgc {
28
+
29
+ class HeapHandle;
30
+
31
+ namespace internal {
32
+
33
+ #if defined(CPPGC_CAGED_HEAP)
34
+ class WriteBarrierTypeForCagedHeapPolicy;
35
+ #else // !CPPGC_CAGED_HEAP
36
+ class WriteBarrierTypeForNonCagedHeapPolicy;
37
+ #endif // !CPPGC_CAGED_HEAP
38
+
39
+ class V8_EXPORT WriteBarrier final {
40
+ public:
41
+ enum class Type : uint8_t {
42
+ kNone,
43
+ kMarking,
44
+ kGenerational,
45
+ };
46
+
47
+ enum class GenerationalBarrierType : uint8_t {
48
+ kPreciseSlot,
49
+ kPreciseUncompressedSlot,
50
+ kImpreciseSlot,
51
+ };
52
+
53
+ struct Params {
54
+ HeapHandle* heap = nullptr;
55
+ #if V8_ENABLE_CHECKS
56
+ Type type = Type::kNone;
57
+ #endif // !V8_ENABLE_CHECKS
58
+ #if defined(CPPGC_CAGED_HEAP)
59
+ uintptr_t slot_offset = 0;
60
+ uintptr_t value_offset = 0;
61
+ #endif // CPPGC_CAGED_HEAP
62
+ };
63
+
64
+ enum class ValueMode {
65
+ kValuePresent,
66
+ kNoValuePresent,
67
+ };
68
+
69
+ // Returns the required write barrier for a given `slot` and `value`.
70
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, const void* value,
71
+ Params& params);
72
+ // Returns the required write barrier for a given `slot` and `value`.
73
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, MemberStorage,
74
+ Params& params);
75
+ // Returns the required write barrier for a given `slot`.
76
+ template <typename HeapHandleCallback>
77
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, Params& params,
78
+ HeapHandleCallback callback);
79
+ // Returns the required write barrier for a given `value`.
80
+ static V8_INLINE Type GetWriteBarrierType(const void* value, Params& params);
81
+
82
+ static V8_INLINE void DijkstraMarkingBarrier(const Params& params,
83
+ const void* object);
84
+ static V8_INLINE void DijkstraMarkingBarrierRange(
85
+ const Params& params, const void* first_element, size_t element_size,
86
+ size_t number_of_elements, TraceCallback trace_callback);
87
+ static V8_INLINE void SteeleMarkingBarrier(const Params& params,
88
+ const void* object);
89
+ #if defined(CPPGC_YOUNG_GENERATION)
90
+ template <GenerationalBarrierType>
91
+ static V8_INLINE void GenerationalBarrier(const Params& params,
92
+ const void* slot);
93
+ #else // !CPPGC_YOUNG_GENERATION
94
+ template <GenerationalBarrierType>
95
+ static V8_INLINE void GenerationalBarrier(const Params& params,
96
+ const void* slot){}
97
+ #endif // CPPGC_YOUNG_GENERATION
98
+
99
+ #if V8_ENABLE_CHECKS
100
+ static void CheckParams(Type expected_type, const Params& params);
101
+ #else // !V8_ENABLE_CHECKS
102
+ static void CheckParams(Type expected_type, const Params& params) {}
103
+ #endif // !V8_ENABLE_CHECKS
104
+
105
+ // The FlagUpdater class allows cppgc internal to update
106
+ // |write_barrier_enabled_|.
107
+ class FlagUpdater;
108
+ static bool IsEnabled() { return write_barrier_enabled_.MightBeEntered(); }
109
+
110
+ private:
111
+ WriteBarrier() = delete;
112
+
113
+ #if defined(CPPGC_CAGED_HEAP)
114
+ using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
115
+ #else // !CPPGC_CAGED_HEAP
116
+ using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
117
+ #endif // !CPPGC_CAGED_HEAP
118
+
119
+ static void DijkstraMarkingBarrierSlow(const void* value);
120
+ static void DijkstraMarkingBarrierSlowWithSentinelCheck(const void* value);
121
+ static void DijkstraMarkingBarrierRangeSlow(HeapHandle& heap_handle,
122
+ const void* first_element,
123
+ size_t element_size,
124
+ size_t number_of_elements,
125
+ TraceCallback trace_callback);
126
+ static void SteeleMarkingBarrierSlow(const void* value);
127
+ static void SteeleMarkingBarrierSlowWithSentinelCheck(const void* value);
128
+
129
+ #if defined(CPPGC_YOUNG_GENERATION)
130
+ static CagedHeapLocalData& GetLocalData(HeapHandle&);
131
+ static void GenerationalBarrierSlow(const CagedHeapLocalData& local_data,
132
+ const AgeTable& age_table,
133
+ const void* slot, uintptr_t value_offset,
134
+ HeapHandle* heap_handle);
135
+ static void GenerationalBarrierForUncompressedSlotSlow(
136
+ const CagedHeapLocalData& local_data, const AgeTable& age_table,
137
+ const void* slot, uintptr_t value_offset, HeapHandle* heap_handle);
138
+ static void GenerationalBarrierForSourceObjectSlow(
139
+ const CagedHeapLocalData& local_data, const void* object,
140
+ HeapHandle* heap_handle);
141
+ #endif // CPPGC_YOUNG_GENERATION
142
+
143
+ static AtomicEntryFlag write_barrier_enabled_;
144
+ };
145
+
146
+ template <WriteBarrier::Type type>
147
+ V8_INLINE WriteBarrier::Type SetAndReturnType(WriteBarrier::Params& params) {
148
+ if constexpr (type == WriteBarrier::Type::kNone)
149
+ return WriteBarrier::Type::kNone;
150
+ #if V8_ENABLE_CHECKS
151
+ params.type = type;
152
+ #endif // !V8_ENABLE_CHECKS
153
+ return type;
154
+ }
155
+
156
+ #if defined(CPPGC_CAGED_HEAP)
157
+ class V8_EXPORT WriteBarrierTypeForCagedHeapPolicy final {
158
+ public:
159
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
160
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
161
+ WriteBarrier::Params& params,
162
+ HeapHandleCallback callback) {
163
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
164
+ }
165
+
166
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
167
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, MemberStorage value,
168
+ WriteBarrier::Params& params,
169
+ HeapHandleCallback callback) {
170
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
171
+ }
172
+
173
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
174
+ static V8_INLINE WriteBarrier::Type Get(const void* value,
175
+ WriteBarrier::Params& params,
176
+ HeapHandleCallback callback) {
177
+ return GetNoSlot(value, params, callback);
178
+ }
179
+
180
+ private:
181
+ WriteBarrierTypeForCagedHeapPolicy() = delete;
182
+
183
+ template <typename HeapHandleCallback>
184
+ static V8_INLINE WriteBarrier::Type GetNoSlot(const void* value,
185
+ WriteBarrier::Params& params,
186
+ HeapHandleCallback) {
187
+ const bool within_cage = CagedHeapBase::IsWithinCage(value);
188
+ if (!within_cage) return WriteBarrier::Type::kNone;
189
+
190
+ // We know that |value| points either within the normal page or to the
191
+ // beginning of large-page, so extract the page header by bitmasking.
192
+ BasePageHandle* page =
193
+ BasePageHandle::FromPayload(const_cast<void*>(value));
194
+
195
+ HeapHandle& heap_handle = page->heap_handle();
196
+ if (V8_UNLIKELY(heap_handle.is_incremental_marking_in_progress())) {
197
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
198
+ }
199
+
200
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
201
+ }
202
+
203
+ template <WriteBarrier::ValueMode value_mode>
204
+ struct ValueModeDispatch;
205
+ };
206
+
207
+ template <>
208
+ struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
209
+ WriteBarrier::ValueMode::kValuePresent> {
210
+ template <typename HeapHandleCallback>
211
+ static V8_INLINE WriteBarrier::Type Get(const void* slot,
212
+ MemberStorage storage,
213
+ WriteBarrier::Params& params,
214
+ HeapHandleCallback) {
215
+ if (V8_LIKELY(!WriteBarrier::IsEnabled()))
216
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
217
+
218
+ return BarrierEnabledGet(slot, storage.Load(), params);
219
+ }
220
+
221
+ template <typename HeapHandleCallback>
222
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
223
+ WriteBarrier::Params& params,
224
+ HeapHandleCallback) {
225
+ if (V8_LIKELY(!WriteBarrier::IsEnabled()))
226
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
227
+
228
+ return BarrierEnabledGet(slot, value, params);
229
+ }
230
+
231
+ private:
232
+ static V8_INLINE WriteBarrier::Type BarrierEnabledGet(
233
+ const void* slot, const void* value, WriteBarrier::Params& params) {
234
+ const bool within_cage = CagedHeapBase::AreWithinCage(slot, value);
235
+ if (!within_cage) return WriteBarrier::Type::kNone;
236
+
237
+ // We know that |value| points either within the normal page or to the
238
+ // beginning of large-page, so extract the page header by bitmasking.
239
+ BasePageHandle* page =
240
+ BasePageHandle::FromPayload(const_cast<void*>(value));
241
+
242
+ HeapHandle& heap_handle = page->heap_handle();
243
+ if (V8_LIKELY(!heap_handle.is_incremental_marking_in_progress())) {
244
+ #if defined(CPPGC_YOUNG_GENERATION)
245
+ if (!heap_handle.is_young_generation_enabled())
246
+ return WriteBarrier::Type::kNone;
247
+ params.heap = &heap_handle;
248
+ params.slot_offset = CagedHeapBase::OffsetFromAddress(slot);
249
+ params.value_offset = CagedHeapBase::OffsetFromAddress(value);
250
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
251
+ #else // !CPPGC_YOUNG_GENERATION
252
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
253
+ #endif // !CPPGC_YOUNG_GENERATION
254
+ }
255
+
256
+ // Use marking barrier.
257
+ params.heap = &heap_handle;
258
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
259
+ }
260
+ };
261
+
262
+ template <>
263
+ struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
264
+ WriteBarrier::ValueMode::kNoValuePresent> {
265
+ template <typename HeapHandleCallback>
266
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void*,
267
+ WriteBarrier::Params& params,
268
+ HeapHandleCallback callback) {
269
+ if (V8_LIKELY(!WriteBarrier::IsEnabled()))
270
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
271
+
272
+ HeapHandle& handle = callback();
273
+ #if defined(CPPGC_YOUNG_GENERATION)
274
+ if (V8_LIKELY(!handle.is_incremental_marking_in_progress())) {
275
+ if (!handle.is_young_generation_enabled()) {
276
+ return WriteBarrier::Type::kNone;
277
+ }
278
+ params.heap = &handle;
279
+ // Check if slot is on stack.
280
+ if (V8_UNLIKELY(!CagedHeapBase::IsWithinCage(slot))) {
281
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
282
+ }
283
+ params.slot_offset = CagedHeapBase::OffsetFromAddress(slot);
284
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
285
+ }
286
+ #else // !defined(CPPGC_YOUNG_GENERATION)
287
+ if (V8_UNLIKELY(!handle.is_incremental_marking_in_progress())) {
288
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
289
+ }
290
+ #endif // !defined(CPPGC_YOUNG_GENERATION)
291
+ params.heap = &handle;
292
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
293
+ }
294
+ };
295
+
296
+ #endif // CPPGC_CAGED_HEAP
297
+
298
+ class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy final {
299
+ public:
300
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
301
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
302
+ WriteBarrier::Params& params,
303
+ HeapHandleCallback callback) {
304
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
305
+ }
306
+
307
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
308
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, MemberStorage value,
309
+ WriteBarrier::Params& params,
310
+ HeapHandleCallback callback) {
311
+ // `MemberStorage` will always be `RawPointer` for non-caged heap builds.
312
+ // Just convert to `void*` in this case.
313
+ return ValueModeDispatch<value_mode>::Get(slot, value.Load(), params,
314
+ callback);
315
+ }
316
+
317
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
318
+ static V8_INLINE WriteBarrier::Type Get(const void* value,
319
+ WriteBarrier::Params& params,
320
+ HeapHandleCallback callback) {
321
+ // The slot will never be used in `Get()` below.
322
+ return Get<WriteBarrier::ValueMode::kValuePresent>(nullptr, value, params,
323
+ callback);
324
+ }
325
+
326
+ private:
327
+ template <WriteBarrier::ValueMode value_mode>
328
+ struct ValueModeDispatch;
329
+
330
+ WriteBarrierTypeForNonCagedHeapPolicy() = delete;
331
+ };
332
+
333
+ template <>
334
+ struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
335
+ WriteBarrier::ValueMode::kValuePresent> {
336
+ template <typename HeapHandleCallback>
337
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void* object,
338
+ WriteBarrier::Params& params,
339
+ HeapHandleCallback callback) {
340
+ // The following check covers nullptr as well as sentinel pointer.
341
+ if (object <= static_cast<void*>(kSentinelPointer)) {
342
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
343
+ }
344
+ if (V8_LIKELY(!WriteBarrier::IsEnabled())) {
345
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
346
+ }
347
+ // We know that |object| is within the normal page or in the beginning of a
348
+ // large page, so extract the page header by bitmasking.
349
+ BasePageHandle* page =
350
+ BasePageHandle::FromPayload(const_cast<void*>(object));
351
+
352
+ HeapHandle& heap_handle = page->heap_handle();
353
+ if (V8_LIKELY(heap_handle.is_incremental_marking_in_progress())) {
354
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
355
+ }
356
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
357
+ }
358
+ };
359
+
360
+ template <>
361
+ struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
362
+ WriteBarrier::ValueMode::kNoValuePresent> {
363
+ template <typename HeapHandleCallback>
364
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void*,
365
+ WriteBarrier::Params& params,
366
+ HeapHandleCallback callback) {
367
+ if (V8_UNLIKELY(WriteBarrier::IsEnabled())) {
368
+ HeapHandle& handle = callback();
369
+ if (V8_LIKELY(handle.is_incremental_marking_in_progress())) {
370
+ params.heap = &handle;
371
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
372
+ }
373
+ }
374
+ return WriteBarrier::Type::kNone;
375
+ }
376
+ };
377
+
378
+ // static
379
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
380
+ const void* slot, const void* value, WriteBarrier::Params& params) {
381
+ return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(slot, value,
382
+ params, []() {});
383
+ }
384
+
385
+ // static
386
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
387
+ const void* slot, MemberStorage value, WriteBarrier::Params& params) {
388
+ return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(slot, value,
389
+ params, []() {});
390
+ }
391
+
392
+ // static
393
+ template <typename HeapHandleCallback>
394
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
395
+ const void* slot, WriteBarrier::Params& params,
396
+ HeapHandleCallback callback) {
397
+ return WriteBarrierTypePolicy::Get<ValueMode::kNoValuePresent>(
398
+ slot, nullptr, params, callback);
399
+ }
400
+
401
+ // static
402
+ WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
403
+ const void* value, WriteBarrier::Params& params) {
404
+ return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(value, params,
405
+ []() {});
406
+ }
407
+
408
+ // static
409
+ void WriteBarrier::DijkstraMarkingBarrier(const Params& params,
410
+ const void* object) {
411
+ CheckParams(Type::kMarking, params);
412
+ #if defined(CPPGC_CAGED_HEAP)
413
+ // Caged heap already filters out sentinels.
414
+ DijkstraMarkingBarrierSlow(object);
415
+ #else // !CPPGC_CAGED_HEAP
416
+ DijkstraMarkingBarrierSlowWithSentinelCheck(object);
417
+ #endif // !CPPGC_CAGED_HEAP
418
+ }
419
+
420
+ // static
421
+ void WriteBarrier::DijkstraMarkingBarrierRange(const Params& params,
422
+ const void* first_element,
423
+ size_t element_size,
424
+ size_t number_of_elements,
425
+ TraceCallback trace_callback) {
426
+ CheckParams(Type::kMarking, params);
427
+ DijkstraMarkingBarrierRangeSlow(*params.heap, first_element, element_size,
428
+ number_of_elements, trace_callback);
429
+ }
430
+
431
+ // static
432
+ void WriteBarrier::SteeleMarkingBarrier(const Params& params,
433
+ const void* object) {
434
+ CheckParams(Type::kMarking, params);
435
+ #if defined(CPPGC_CAGED_HEAP)
436
+ // Caged heap already filters out sentinels.
437
+ SteeleMarkingBarrierSlow(object);
438
+ #else // !CPPGC_CAGED_HEAP
439
+ SteeleMarkingBarrierSlowWithSentinelCheck(object);
440
+ #endif // !CPPGC_CAGED_HEAP
441
+ }
442
+
443
+ #if defined(CPPGC_YOUNG_GENERATION)
444
+
445
+ // static
446
+ template <WriteBarrier::GenerationalBarrierType type>
447
+ void WriteBarrier::GenerationalBarrier(const Params& params, const void* slot) {
448
+ CheckParams(Type::kGenerational, params);
449
+
450
+ const CagedHeapLocalData& local_data = CagedHeapLocalData::Get();
451
+ const AgeTable& age_table = local_data.age_table;
452
+
453
+ // Bail out if the slot (precise or imprecise) is in young generation.
454
+ if (V8_LIKELY(age_table.GetAge(params.slot_offset) == AgeTable::Age::kYoung))
455
+ return;
456
+
457
+ // Dispatch between different types of barriers.
458
+ // TODO(chromium:1029379): Consider reload local_data in the slow path to
459
+ // reduce register pressure.
460
+ if constexpr (type == GenerationalBarrierType::kPreciseSlot) {
461
+ GenerationalBarrierSlow(local_data, age_table, slot, params.value_offset,
462
+ params.heap);
463
+ } else if constexpr (type ==
464
+ GenerationalBarrierType::kPreciseUncompressedSlot) {
465
+ GenerationalBarrierForUncompressedSlotSlow(
466
+ local_data, age_table, slot, params.value_offset, params.heap);
467
+ } else {
468
+ GenerationalBarrierForSourceObjectSlow(local_data, slot, params.heap);
469
+ }
470
+ }
471
+
472
+ #endif // !CPPGC_YOUNG_GENERATION
473
+
474
+ } // namespace internal
475
+ } // namespace cppgc
476
+
477
+ #endif // INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
@@ -0,0 +1,78 @@
1
+ // Copyright 2020 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_CPPGC_LIVENESS_BROKER_H_
6
+ #define INCLUDE_CPPGC_LIVENESS_BROKER_H_
7
+
8
+ #include "cppgc/heap.h"
9
+ #include "cppgc/member.h"
10
+ #include "cppgc/sentinel-pointer.h"
11
+ #include "cppgc/trace-trait.h"
12
+ #include "v8config.h" // NOLINT(build/include_directory)
13
+
14
+ namespace cppgc {
15
+
16
+ namespace internal {
17
+ class LivenessBrokerFactory;
18
+ } // namespace internal
19
+
20
+ /**
21
+ * The broker is passed to weak callbacks to allow (temporarily) querying
22
+ * the liveness state of an object. References to non-live objects must be
23
+ * cleared when `IsHeapObjectAlive()` returns false.
24
+ *
25
+ * \code
26
+ * class GCedWithCustomWeakCallback final
27
+ * : public GarbageCollected<GCedWithCustomWeakCallback> {
28
+ * public:
29
+ * UntracedMember<Bar> bar;
30
+ *
31
+ * void CustomWeakCallbackMethod(const LivenessBroker& broker) {
32
+ * if (!broker.IsHeapObjectAlive(bar))
33
+ * bar = nullptr;
34
+ * }
35
+ *
36
+ * void Trace(cppgc::Visitor* visitor) const {
37
+ * visitor->RegisterWeakCallbackMethod<
38
+ * GCedWithCustomWeakCallback,
39
+ * &GCedWithCustomWeakCallback::CustomWeakCallbackMethod>(this);
40
+ * }
41
+ * };
42
+ * \endcode
43
+ */
44
+ class V8_EXPORT LivenessBroker final {
45
+ public:
46
+ template <typename T>
47
+ bool IsHeapObjectAlive(const T* object) const {
48
+ // - nullptr objects are considered alive to allow weakness to be used from
49
+ // stack while running into a conservative GC. Treating nullptr as dead
50
+ // would mean that e.g. custom collections could not be strongified on
51
+ // stack.
52
+ // - Sentinel pointers are also preserved in weakness and not cleared.
53
+ return !object || object == kSentinelPointer ||
54
+ IsHeapObjectAliveImpl(
55
+ TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
56
+ }
57
+
58
+ template <typename T>
59
+ bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
60
+ return IsHeapObjectAlive<T>(weak_member.Get());
61
+ }
62
+
63
+ template <typename T>
64
+ bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
65
+ return IsHeapObjectAlive<T>(untraced_member.Get());
66
+ }
67
+
68
+ private:
69
+ LivenessBroker() = default;
70
+
71
+ bool IsHeapObjectAliveImpl(const void*) const;
72
+
73
+ friend class internal::LivenessBrokerFactory;
74
+ };
75
+
76
+ } // namespace cppgc
77
+
78
+ #endif // INCLUDE_CPPGC_LIVENESS_BROKER_H_
@@ -0,0 +1,26 @@
1
+ // Copyright 2020 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_CPPGC_MACROS_H_
6
+ #define INCLUDE_CPPGC_MACROS_H_
7
+
8
+ #include <cstddef>
9
+
10
+ #include "cppgc/internal/compiler-specific.h"
11
+
12
+ namespace cppgc {
13
+
14
+ // Use if the object is only stack allocated.
15
+ #define CPPGC_STACK_ALLOCATED() \
16
+ public: \
17
+ using IsStackAllocatedTypeMarker CPPGC_UNUSED = int; \
18
+ \
19
+ private: \
20
+ void* operator new(size_t) = delete; \
21
+ void* operator new(size_t, void*) = delete; \
22
+ static_assert(true, "Force semicolon.")
23
+
24
+ } // namespace cppgc
25
+
26
+ #endif // INCLUDE_CPPGC_MACROS_H_