@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,366 @@
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_PERSISTENT_H_
6
+ #define INCLUDE_CPPGC_PERSISTENT_H_
7
+
8
+ #include <type_traits>
9
+
10
+ #include "cppgc/internal/persistent-node.h"
11
+ #include "cppgc/internal/pointer-policies.h"
12
+ #include "cppgc/sentinel-pointer.h"
13
+ #include "cppgc/source-location.h"
14
+ #include "cppgc/type-traits.h"
15
+ #include "cppgc/visitor.h"
16
+ #include "v8config.h" // NOLINT(build/include_directory)
17
+
18
+ namespace cppgc {
19
+ namespace internal {
20
+
21
+ // PersistentBase always refers to the object as const object and defers to
22
+ // BasicPersistent on casting to the right type as needed.
23
+ class PersistentBase {
24
+ protected:
25
+ PersistentBase() = default;
26
+ explicit PersistentBase(const void* raw) : raw_(raw) {}
27
+
28
+ const void* GetValue() const { return raw_; }
29
+ void SetValue(const void* value) { raw_ = value; }
30
+
31
+ PersistentNode* GetNode() const { return node_; }
32
+ void SetNode(PersistentNode* node) { node_ = node; }
33
+
34
+ // Performs a shallow clear which assumes that internal persistent nodes are
35
+ // destroyed elsewhere.
36
+ void ClearFromGC() const {
37
+ raw_ = nullptr;
38
+ node_ = nullptr;
39
+ }
40
+
41
+ protected:
42
+ mutable const void* raw_ = nullptr;
43
+ mutable PersistentNode* node_ = nullptr;
44
+
45
+ friend class PersistentRegionBase;
46
+ };
47
+
48
+ // The basic class from which all Persistent classes are generated.
49
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
50
+ typename CheckingPolicy>
51
+ class BasicPersistent final : public PersistentBase,
52
+ public LocationPolicy,
53
+ private WeaknessPolicy,
54
+ private CheckingPolicy {
55
+ public:
56
+ using typename WeaknessPolicy::IsStrongPersistent;
57
+ using PointeeType = T;
58
+
59
+ // Null-state/sentinel constructors.
60
+ BasicPersistent( // NOLINT
61
+ const SourceLocation& loc = SourceLocation::Current())
62
+ : LocationPolicy(loc) {}
63
+
64
+ BasicPersistent(std::nullptr_t, // NOLINT
65
+ const SourceLocation& loc = SourceLocation::Current())
66
+ : LocationPolicy(loc) {}
67
+
68
+ BasicPersistent( // NOLINT
69
+ SentinelPointer s, const SourceLocation& loc = SourceLocation::Current())
70
+ : PersistentBase(s), LocationPolicy(loc) {}
71
+
72
+ // Raw value constructors.
73
+ BasicPersistent(T* raw, // NOLINT
74
+ const SourceLocation& loc = SourceLocation::Current())
75
+ : PersistentBase(raw), LocationPolicy(loc) {
76
+ if (!IsValid()) return;
77
+ SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
78
+ .AllocateNode(this, &TraceAsRoot));
79
+ this->CheckPointer(Get());
80
+ }
81
+
82
+ BasicPersistent(T& raw, // NOLINT
83
+ const SourceLocation& loc = SourceLocation::Current())
84
+ : BasicPersistent(&raw, loc) {}
85
+
86
+ // Copy ctor.
87
+ BasicPersistent(const BasicPersistent& other,
88
+ const SourceLocation& loc = SourceLocation::Current())
89
+ : BasicPersistent(other.Get(), loc) {}
90
+
91
+ // Heterogeneous ctor.
92
+ template <typename U, typename OtherWeaknessPolicy,
93
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
94
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
95
+ BasicPersistent(
96
+ const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
97
+ OtherCheckingPolicy>& other,
98
+ const SourceLocation& loc = SourceLocation::Current())
99
+ : BasicPersistent(other.Get(), loc) {}
100
+
101
+ // Move ctor. The heterogeneous move ctor is not supported since e.g.
102
+ // persistent can't reuse persistent node from weak persistent.
103
+ BasicPersistent(
104
+ BasicPersistent&& other,
105
+ const SourceLocation& loc = SourceLocation::Current()) noexcept
106
+ : PersistentBase(std::move(other)), LocationPolicy(std::move(other)) {
107
+ if (!IsValid()) return;
108
+ GetNode()->UpdateOwner(this);
109
+ other.SetValue(nullptr);
110
+ other.SetNode(nullptr);
111
+ this->CheckPointer(Get());
112
+ }
113
+
114
+ // Constructor from member.
115
+ template <typename U, typename MemberBarrierPolicy,
116
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
117
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
118
+ BasicPersistent(
119
+ const internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
120
+ MemberCheckingPolicy>& member,
121
+ const SourceLocation& loc = SourceLocation::Current())
122
+ : BasicPersistent(member.Get(), loc) {}
123
+
124
+ ~BasicPersistent() { Clear(); }
125
+
126
+ // Copy assignment.
127
+ BasicPersistent& operator=(const BasicPersistent& other) {
128
+ return operator=(other.Get());
129
+ }
130
+
131
+ template <typename U, typename OtherWeaknessPolicy,
132
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
133
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
134
+ BasicPersistent& operator=(
135
+ const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
136
+ OtherCheckingPolicy>& other) {
137
+ return operator=(other.Get());
138
+ }
139
+
140
+ // Move assignment.
141
+ BasicPersistent& operator=(BasicPersistent&& other) noexcept {
142
+ if (this == &other) return *this;
143
+ Clear();
144
+ PersistentBase::operator=(std::move(other));
145
+ LocationPolicy::operator=(std::move(other));
146
+ if (!IsValid()) return *this;
147
+ GetNode()->UpdateOwner(this);
148
+ other.SetValue(nullptr);
149
+ other.SetNode(nullptr);
150
+ this->CheckPointer(Get());
151
+ return *this;
152
+ }
153
+
154
+ // Assignment from member.
155
+ template <typename U, typename MemberBarrierPolicy,
156
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
157
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
158
+ BasicPersistent& operator=(
159
+ const internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
160
+ MemberCheckingPolicy>& member) {
161
+ return operator=(member.Get());
162
+ }
163
+
164
+ BasicPersistent& operator=(T* other) {
165
+ Assign(other);
166
+ return *this;
167
+ }
168
+
169
+ BasicPersistent& operator=(std::nullptr_t) {
170
+ Clear();
171
+ return *this;
172
+ }
173
+
174
+ BasicPersistent& operator=(SentinelPointer s) {
175
+ Assign(s);
176
+ return *this;
177
+ }
178
+
179
+ explicit operator bool() const { return Get(); }
180
+ operator T*() const { return Get(); }
181
+ T* operator->() const { return Get(); }
182
+ T& operator*() const { return *Get(); }
183
+
184
+ // CFI cast exemption to allow passing SentinelPointer through T* and support
185
+ // heterogeneous assignments between different Member and Persistent handles
186
+ // based on their actual types.
187
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
188
+ // The const_cast below removes the constness from PersistentBase storage.
189
+ // The following static_cast re-adds any constness if specified through the
190
+ // user-visible template parameter T.
191
+ return static_cast<T*>(const_cast<void*>(GetValue()));
192
+ }
193
+
194
+ void Clear() {
195
+ // Simplified version of `Assign()` to allow calling without a complete type
196
+ // `T`.
197
+ if (IsValid()) {
198
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
199
+ SetNode(nullptr);
200
+ }
201
+ SetValue(nullptr);
202
+ }
203
+
204
+ T* Release() {
205
+ T* result = Get();
206
+ Clear();
207
+ return result;
208
+ }
209
+
210
+ template <typename U, typename OtherWeaknessPolicy = WeaknessPolicy,
211
+ typename OtherLocationPolicy = LocationPolicy,
212
+ typename OtherCheckingPolicy = CheckingPolicy>
213
+ BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
214
+ OtherCheckingPolicy>
215
+ To() const {
216
+ return BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
217
+ OtherCheckingPolicy>(static_cast<U*>(Get()));
218
+ }
219
+
220
+ private:
221
+ static void TraceAsRoot(RootVisitor& root_visitor, const void* ptr) {
222
+ root_visitor.Trace(*static_cast<const BasicPersistent*>(ptr));
223
+ }
224
+
225
+ bool IsValid() const {
226
+ // Ideally, handling kSentinelPointer would be done by the embedder. On the
227
+ // other hand, having Persistent aware of it is beneficial since no node
228
+ // gets wasted.
229
+ return GetValue() != nullptr && GetValue() != kSentinelPointer;
230
+ }
231
+
232
+ void Assign(T* ptr) {
233
+ if (IsValid()) {
234
+ if (ptr && ptr != kSentinelPointer) {
235
+ // Simply assign the pointer reusing the existing node.
236
+ SetValue(ptr);
237
+ this->CheckPointer(ptr);
238
+ return;
239
+ }
240
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
241
+ SetNode(nullptr);
242
+ }
243
+ SetValue(ptr);
244
+ if (!IsValid()) return;
245
+ SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
246
+ .AllocateNode(this, &TraceAsRoot));
247
+ this->CheckPointer(Get());
248
+ }
249
+
250
+ void ClearFromGC() const {
251
+ if (IsValid()) {
252
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
253
+ PersistentBase::ClearFromGC();
254
+ }
255
+ }
256
+
257
+ // Set Get() for details.
258
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast")
259
+ T* GetFromGC() const {
260
+ return static_cast<T*>(const_cast<void*>(GetValue()));
261
+ }
262
+
263
+ friend class internal::RootVisitor;
264
+ };
265
+
266
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
267
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
268
+ typename LocationPolicy2, typename CheckingPolicy2>
269
+ bool operator==(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
270
+ CheckingPolicy1>& p1,
271
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
272
+ CheckingPolicy2>& p2) {
273
+ return p1.Get() == p2.Get();
274
+ }
275
+
276
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
277
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
278
+ typename LocationPolicy2, typename CheckingPolicy2>
279
+ bool operator!=(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
280
+ CheckingPolicy1>& p1,
281
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
282
+ CheckingPolicy2>& p2) {
283
+ return !(p1 == p2);
284
+ }
285
+
286
+ template <typename T1, typename PersistentWeaknessPolicy,
287
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
288
+ typename T2, typename MemberWriteBarrierPolicy,
289
+ typename MemberWeaknessTag, typename MemberCheckingPolicy>
290
+ bool operator==(
291
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
292
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
293
+ p,
294
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
295
+ MemberCheckingPolicy>& m) {
296
+ return p.Get() == m.Get();
297
+ }
298
+
299
+ template <typename T1, typename PersistentWeaknessPolicy,
300
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
301
+ typename T2, typename MemberWriteBarrierPolicy,
302
+ typename MemberWeaknessTag, typename MemberCheckingPolicy>
303
+ bool operator!=(
304
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
305
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
306
+ p,
307
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
308
+ MemberCheckingPolicy>& m) {
309
+ return !(p == m);
310
+ }
311
+
312
+ template <typename T1, typename MemberWriteBarrierPolicy,
313
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
314
+ typename T2, typename PersistentWeaknessPolicy,
315
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy>
316
+ bool operator==(
317
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
318
+ MemberCheckingPolicy>& m,
319
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
320
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
321
+ p) {
322
+ return m.Get() == p.Get();
323
+ }
324
+
325
+ template <typename T1, typename MemberWriteBarrierPolicy,
326
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
327
+ typename T2, typename PersistentWeaknessPolicy,
328
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy>
329
+ bool operator!=(
330
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
331
+ MemberCheckingPolicy>& m,
332
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
333
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
334
+ p) {
335
+ return !(m == p);
336
+ }
337
+
338
+ template <typename T, typename LocationPolicy, typename CheckingPolicy>
339
+ struct IsWeak<BasicPersistent<T, internal::WeakPersistentPolicy, LocationPolicy,
340
+ CheckingPolicy>> : std::true_type {};
341
+ } // namespace internal
342
+
343
+ /**
344
+ * Persistent is a way to create a strong pointer from an off-heap object to
345
+ * another on-heap object. As long as the Persistent handle is alive the GC will
346
+ * keep the object pointed to alive. The Persistent handle is always a GC root
347
+ * from the point of view of the GC. Persistent must be constructed and
348
+ * destructed in the same thread.
349
+ */
350
+ template <typename T>
351
+ using Persistent =
352
+ internal::BasicPersistent<T, internal::StrongPersistentPolicy>;
353
+
354
+ /**
355
+ * WeakPersistent is a way to create a weak pointer from an off-heap object to
356
+ * an on-heap object. The pointer is automatically cleared when the pointee gets
357
+ * collected. WeakPersistent must be constructed and destructed in the same
358
+ * thread.
359
+ */
360
+ template <typename T>
361
+ using WeakPersistent =
362
+ internal::BasicPersistent<T, internal::WeakPersistentPolicy>;
363
+
364
+ } // namespace cppgc
365
+
366
+ #endif // INCLUDE_CPPGC_PERSISTENT_H_
@@ -0,0 +1,158 @@
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_PLATFORM_H_
6
+ #define INCLUDE_CPPGC_PLATFORM_H_
7
+
8
+ #include <memory>
9
+
10
+ #include "cppgc/source-location.h"
11
+ #include "v8-platform.h" // NOLINT(build/include_directory)
12
+ #include "v8config.h" // NOLINT(build/include_directory)
13
+
14
+ namespace cppgc {
15
+
16
+ // TODO(v8:10346): Create separate includes for concepts that are not
17
+ // V8-specific.
18
+ using IdleTask = v8::IdleTask;
19
+ using JobHandle = v8::JobHandle;
20
+ using JobDelegate = v8::JobDelegate;
21
+ using JobTask = v8::JobTask;
22
+ using PageAllocator = v8::PageAllocator;
23
+ using Task = v8::Task;
24
+ using TaskPriority = v8::TaskPriority;
25
+ using TaskRunner = v8::TaskRunner;
26
+ using TracingController = v8::TracingController;
27
+
28
+ /**
29
+ * Platform interface used by Heap. Contains allocators and executors.
30
+ */
31
+ class V8_EXPORT Platform {
32
+ public:
33
+ virtual ~Platform() = default;
34
+
35
+ /**
36
+ * \returns the allocator used by cppgc to allocate its heap and various
37
+ * support structures. Returning nullptr results in using the `PageAllocator`
38
+ * provided by `cppgc::InitializeProcess()` instead.
39
+ */
40
+ virtual PageAllocator* GetPageAllocator() = 0;
41
+
42
+ /**
43
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
44
+ * the past. This function is expected to return at least
45
+ * millisecond-precision values. For this reason,
46
+ * it is recommended that the fixed point be no further in the past than
47
+ * the epoch.
48
+ **/
49
+ virtual double MonotonicallyIncreasingTime() = 0;
50
+
51
+ /**
52
+ * Foreground task runner that should be used by a Heap.
53
+ */
54
+ virtual std::shared_ptr<TaskRunner> GetForegroundTaskRunner() {
55
+ return nullptr;
56
+ }
57
+
58
+ /**
59
+ * Posts `job_task` to run in parallel. Returns a `JobHandle` associated with
60
+ * the `Job`, which can be joined or canceled.
61
+ * This avoids degenerate cases:
62
+ * - Calling `CallOnWorkerThread()` for each work item, causing significant
63
+ * overhead.
64
+ * - Fixed number of `CallOnWorkerThread()` calls that split the work and
65
+ * might run for a long time. This is problematic when many components post
66
+ * "num cores" tasks and all expect to use all the cores. In these cases,
67
+ * the scheduler lacks context to be fair to multiple same-priority requests
68
+ * and/or ability to request lower priority work to yield when high priority
69
+ * work comes in.
70
+ * A canonical implementation of `job_task` looks like:
71
+ * \code
72
+ * class MyJobTask : public JobTask {
73
+ * public:
74
+ * MyJobTask(...) : worker_queue_(...) {}
75
+ * // JobTask implementation.
76
+ * void Run(JobDelegate* delegate) override {
77
+ * while (!delegate->ShouldYield()) {
78
+ * // Smallest unit of work.
79
+ * auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
80
+ * if (!work_item) return;
81
+ * ProcessWork(work_item);
82
+ * }
83
+ * }
84
+ *
85
+ * size_t GetMaxConcurrency() const override {
86
+ * return worker_queue_.GetSize(); // Thread safe.
87
+ * }
88
+ * };
89
+ *
90
+ * // ...
91
+ * auto handle = PostJob(TaskPriority::kUserVisible,
92
+ * std::make_unique<MyJobTask>(...));
93
+ * handle->Join();
94
+ * \endcode
95
+ *
96
+ * `PostJob()` and methods of the returned JobHandle/JobDelegate, must never
97
+ * be called while holding a lock that could be acquired by `JobTask::Run()`
98
+ * or `JobTask::GetMaxConcurrency()` -- that could result in a deadlock. This
99
+ * is because (1) `JobTask::GetMaxConcurrency()` may be invoked while holding
100
+ * internal lock (A), hence `JobTask::GetMaxConcurrency()` can only use a lock
101
+ * (B) if that lock is *never* held while calling back into `JobHandle` from
102
+ * any thread (A=>B/B=>A deadlock) and (2) `JobTask::Run()` or
103
+ * `JobTask::GetMaxConcurrency()` may be invoked synchronously from
104
+ * `JobHandle` (B=>JobHandle::foo=>B deadlock).
105
+ *
106
+ * A sufficient `PostJob()` implementation that uses the default Job provided
107
+ * in libplatform looks like:
108
+ * \code
109
+ * std::unique_ptr<JobHandle> PostJob(
110
+ * TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
111
+ * return std::make_unique<DefaultJobHandle>(
112
+ * std::make_shared<DefaultJobState>(
113
+ * this, std::move(job_task), kNumThreads));
114
+ * }
115
+ * \endcode
116
+ */
117
+ virtual std::unique_ptr<JobHandle> PostJob(
118
+ TaskPriority priority, std::unique_ptr<JobTask> job_task) {
119
+ return nullptr;
120
+ }
121
+
122
+ /**
123
+ * Returns an instance of a `TracingController`. This must be non-nullptr. The
124
+ * default implementation returns an empty `TracingController` that consumes
125
+ * trace data without effect.
126
+ */
127
+ virtual TracingController* GetTracingController();
128
+ };
129
+
130
+ /**
131
+ * Process-global initialization of the garbage collector. Must be called before
132
+ * creating a Heap.
133
+ *
134
+ * Can be called multiple times when paired with `ShutdownProcess()`.
135
+ *
136
+ * \param page_allocator The allocator used for maintaining meta data. Must stay
137
+ * always alive and not change between multiple calls to InitializeProcess. If
138
+ * no allocator is provided, a default internal version will be used.
139
+ */
140
+ V8_EXPORT void InitializeProcess(PageAllocator* page_allocator = nullptr);
141
+
142
+ /**
143
+ * Must be called after destroying the last used heap. Some process-global
144
+ * metadata may not be returned and reused upon a subsequent
145
+ * `InitializeProcess()` call.
146
+ */
147
+ V8_EXPORT void ShutdownProcess();
148
+
149
+ namespace internal {
150
+
151
+ V8_EXPORT void Fatal(const std::string& reason = std::string(),
152
+ const SourceLocation& = SourceLocation::Current());
153
+
154
+ } // namespace internal
155
+
156
+ } // namespace cppgc
157
+
158
+ #endif // INCLUDE_CPPGC_PLATFORM_H_
@@ -0,0 +1,75 @@
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_PREFINALIZER_H_
6
+ #define INCLUDE_CPPGC_PREFINALIZER_H_
7
+
8
+ #include "cppgc/internal/compiler-specific.h"
9
+ #include "cppgc/liveness-broker.h"
10
+
11
+ namespace cppgc {
12
+
13
+ namespace internal {
14
+
15
+ class V8_EXPORT PrefinalizerRegistration final {
16
+ public:
17
+ using Callback = bool (*)(const cppgc::LivenessBroker&, void*);
18
+
19
+ PrefinalizerRegistration(void*, Callback);
20
+
21
+ void* operator new(size_t, void* location) = delete;
22
+ void* operator new(size_t) = delete;
23
+ };
24
+
25
+ } // namespace internal
26
+
27
+ /**
28
+ * Macro must be used in the private section of `Class` and registers a
29
+ * prefinalization callback `void Class::PreFinalizer()`. The callback is
30
+ * invoked on garbage collection after the collector has found an object to be
31
+ * dead.
32
+ *
33
+ * Callback properties:
34
+ * - The callback is invoked before a possible destructor for the corresponding
35
+ * object.
36
+ * - The callback may access the whole object graph, irrespective of whether
37
+ * objects are considered dead or alive.
38
+ * - The callback is invoked on the same thread as the object was created on.
39
+ *
40
+ * Example:
41
+ * \code
42
+ * class WithPrefinalizer : public GarbageCollected<WithPrefinalizer> {
43
+ * CPPGC_USING_PRE_FINALIZER(WithPrefinalizer, Dispose);
44
+ *
45
+ * public:
46
+ * void Trace(Visitor*) const {}
47
+ * void Dispose() { prefinalizer_called = true; }
48
+ * ~WithPrefinalizer() {
49
+ * // prefinalizer_called == true
50
+ * }
51
+ * private:
52
+ * bool prefinalizer_called = false;
53
+ * };
54
+ * \endcode
55
+ */
56
+ #define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer) \
57
+ public: \
58
+ static bool InvokePreFinalizer(const cppgc::LivenessBroker& liveness_broker, \
59
+ void* object) { \
60
+ static_assert(cppgc::IsGarbageCollectedOrMixinTypeV<Class>, \
61
+ "Only garbage collected objects can have prefinalizers"); \
62
+ Class* self = static_cast<Class*>(object); \
63
+ if (liveness_broker.IsHeapObjectAlive(self)) return false; \
64
+ self->PreFinalizer(); \
65
+ return true; \
66
+ } \
67
+ \
68
+ private: \
69
+ CPPGC_NO_UNIQUE_ADDRESS cppgc::internal::PrefinalizerRegistration \
70
+ prefinalizer_dummy_{this, Class::InvokePreFinalizer}; \
71
+ static_assert(true, "Force semicolon.")
72
+
73
+ } // namespace cppgc
74
+
75
+ #endif // INCLUDE_CPPGC_PREFINALIZER_H_
@@ -0,0 +1,36 @@
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_PROCESS_HEAP_STATISTICS_H_
6
+ #define INCLUDE_CPPGC_PROCESS_HEAP_STATISTICS_H_
7
+
8
+ #include <atomic>
9
+ #include <cstddef>
10
+
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+ namespace internal {
15
+ class ProcessHeapStatisticsUpdater;
16
+ } // namespace internal
17
+
18
+ class V8_EXPORT ProcessHeapStatistics final {
19
+ public:
20
+ static size_t TotalAllocatedObjectSize() {
21
+ return total_allocated_object_size_.load(std::memory_order_relaxed);
22
+ }
23
+ static size_t TotalAllocatedSpace() {
24
+ return total_allocated_space_.load(std::memory_order_relaxed);
25
+ }
26
+
27
+ private:
28
+ static std::atomic_size_t total_allocated_space_;
29
+ static std::atomic_size_t total_allocated_object_size_;
30
+
31
+ friend class internal::ProcessHeapStatisticsUpdater;
32
+ };
33
+
34
+ } // namespace cppgc
35
+
36
+ #endif // INCLUDE_CPPGC_PROCESS_HEAP_STATISTICS_H_
@@ -0,0 +1,32 @@
1
+ // Copyright 2021 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_SENTINEL_POINTER_H_
6
+ #define INCLUDE_CPPGC_SENTINEL_POINTER_H_
7
+
8
+ #include <cstdint>
9
+
10
+ namespace cppgc {
11
+ namespace internal {
12
+
13
+ // Special tag type used to denote some sentinel member. The semantics of the
14
+ // sentinel is defined by the embedder.
15
+ struct SentinelPointer {
16
+ static constexpr intptr_t kSentinelValue = 0b10;
17
+ template <typename T>
18
+ operator T*() const {
19
+ return reinterpret_cast<T*>(kSentinelValue);
20
+ }
21
+ // Hidden friends.
22
+ friend bool operator==(SentinelPointer, SentinelPointer) { return true; }
23
+ friend bool operator!=(SentinelPointer, SentinelPointer) { return false; }
24
+ };
25
+
26
+ } // namespace internal
27
+
28
+ constexpr internal::SentinelPointer kSentinelPointer;
29
+
30
+ } // namespace cppgc
31
+
32
+ #endif // INCLUDE_CPPGC_SENTINEL_POINTER_H_