@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.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 (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -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_NAME_PROVIDER_H_
6
+ #define INCLUDE_CPPGC_NAME_PROVIDER_H_
7
+
8
+ #include "v8config.h" // NOLINT(build/include_directory)
9
+
10
+ namespace cppgc {
11
+
12
+ /**
13
+ * NameProvider allows for providing a human-readable name for garbage-collected
14
+ * objects.
15
+ *
16
+ * There's two cases of names to distinguish:
17
+ * a. Explicitly specified names via using NameProvider. Such names are always
18
+ * preserved in the system.
19
+ * b. Internal names that Oilpan infers from a C++ type on the class hierarchy
20
+ * of the object. This is not necessarily the type of the actually
21
+ * instantiated object.
22
+ *
23
+ * Depending on the build configuration, Oilpan may hide names, i.e., represent
24
+ * them with kHiddenName, of case b. to avoid exposing internal details.
25
+ */
26
+ class V8_EXPORT NameProvider {
27
+ public:
28
+ /**
29
+ * Name that is used when hiding internals.
30
+ */
31
+ static constexpr const char kHiddenName[] = "InternalNode";
32
+
33
+ /**
34
+ * Name that is used in case compiler support is missing for composing a name
35
+ * from C++ types.
36
+ */
37
+ static constexpr const char kNoNameDeducible[] = "<No name>";
38
+
39
+ /**
40
+ * Indicating whether the build supports extracting C++ names as object names.
41
+ *
42
+ * @returns true if C++ names should be hidden and represented by kHiddenName.
43
+ */
44
+ static constexpr bool SupportsCppClassNamesAsObjectNames() {
45
+ #if CPPGC_SUPPORTS_OBJECT_NAMES
46
+ return true;
47
+ #else // !CPPGC_SUPPORTS_OBJECT_NAMES
48
+ return false;
49
+ #endif // !CPPGC_SUPPORTS_OBJECT_NAMES
50
+ }
51
+
52
+ virtual ~NameProvider() = default;
53
+
54
+ /**
55
+ * Specifies a name for the garbage-collected object. Such names will never
56
+ * be hidden, as they are explicitly specified by the user of this API.
57
+ *
58
+ * Implementations of this function must not allocate garbage-collected
59
+ * objects or otherwise modify the cppgc heap.
60
+ *
61
+ * V8 may call this function while generating a heap snapshot or at other
62
+ * times. If V8 is currently generating a heap snapshot (according to
63
+ * HeapProfiler::IsTakingSnapshot), then the returned string must stay alive
64
+ * until the snapshot generation has completed. Otherwise, the returned string
65
+ * must stay alive forever. If you need a place to store a temporary string
66
+ * during snapshot generation, use HeapProfiler::CopyNameForHeapSnapshot.
67
+ *
68
+ * @returns a human readable name for the object.
69
+ */
70
+ virtual const char* GetHumanReadableName() const = 0;
71
+ };
72
+
73
+ } // namespace cppgc
74
+
75
+ #endif // INCLUDE_CPPGC_NAME_PROVIDER_H_
@@ -0,0 +1,58 @@
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_OBJECT_SIZE_TRAIT_H_
6
+ #define INCLUDE_CPPGC_OBJECT_SIZE_TRAIT_H_
7
+
8
+ #include <cstddef>
9
+
10
+ #include "cppgc/type-traits.h"
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+
15
+ namespace internal {
16
+
17
+ struct V8_EXPORT BaseObjectSizeTrait {
18
+ protected:
19
+ static size_t GetObjectSizeForGarbageCollected(const void*);
20
+ static size_t GetObjectSizeForGarbageCollectedMixin(const void*);
21
+ };
22
+
23
+ } // namespace internal
24
+
25
+ namespace subtle {
26
+
27
+ /**
28
+ * Trait specifying how to get the size of an object that was allocated using
29
+ * `MakeGarbageCollected()`. Also supports querying the size with an inner
30
+ * pointer to a mixin.
31
+ */
32
+ template <typename T, bool = IsGarbageCollectedMixinTypeV<T>>
33
+ struct ObjectSizeTrait;
34
+
35
+ template <typename T>
36
+ struct ObjectSizeTrait<T, false> : cppgc::internal::BaseObjectSizeTrait {
37
+ static_assert(sizeof(T), "T must be fully defined");
38
+ static_assert(IsGarbageCollectedTypeV<T>,
39
+ "T must be of type GarbageCollected or GarbageCollectedMixin");
40
+
41
+ static size_t GetSize(const T& object) {
42
+ return GetObjectSizeForGarbageCollected(&object);
43
+ }
44
+ };
45
+
46
+ template <typename T>
47
+ struct ObjectSizeTrait<T, true> : cppgc::internal::BaseObjectSizeTrait {
48
+ static_assert(sizeof(T), "T must be fully defined");
49
+
50
+ static size_t GetSize(const T& object) {
51
+ return GetObjectSizeForGarbageCollectedMixin(&object);
52
+ }
53
+ };
54
+
55
+ } // namespace subtle
56
+ } // namespace cppgc
57
+
58
+ #endif // INCLUDE_CPPGC_OBJECT_SIZE_TRAIT_H_
@@ -0,0 +1,376 @@
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
+ SourceLocation loc = SourceLocation::Current())
62
+ : LocationPolicy(loc) {}
63
+
64
+ BasicPersistent(std::nullptr_t, // NOLINT
65
+ SourceLocation loc = SourceLocation::Current())
66
+ : LocationPolicy(loc) {}
67
+
68
+ BasicPersistent( // NOLINT
69
+ SentinelPointer s, SourceLocation loc = SourceLocation::Current())
70
+ : PersistentBase(s), LocationPolicy(loc) {}
71
+
72
+ // Raw value constructors.
73
+ BasicPersistent(T* raw, // NOLINT
74
+ 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
+ SourceLocation loc = SourceLocation::Current())
84
+ : BasicPersistent(&raw, loc) {}
85
+
86
+ // Copy ctor.
87
+ BasicPersistent(const BasicPersistent& other,
88
+ 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_v<T, U>>>
95
+ // NOLINTNEXTLINE
96
+ BasicPersistent(
97
+ const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
98
+ OtherCheckingPolicy>& other,
99
+ SourceLocation loc = SourceLocation::Current())
100
+ : BasicPersistent(other.Get(), loc) {}
101
+
102
+ // Move ctor. The heterogeneous move ctor is not supported since e.g.
103
+ // persistent can't reuse persistent node from weak persistent.
104
+ BasicPersistent(BasicPersistent&& other,
105
+ 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 MemberStorageType,
118
+ typename = std::enable_if_t<std::is_base_of_v<T, U>>>
119
+ // NOLINTNEXTLINE
120
+ BasicPersistent(const internal::BasicMember<
121
+ U, MemberBarrierPolicy, MemberWeaknessTag,
122
+ MemberCheckingPolicy, MemberStorageType>& member,
123
+ SourceLocation loc = SourceLocation::Current())
124
+ : BasicPersistent(member.Get(), loc) {}
125
+
126
+ ~BasicPersistent() { Clear(); }
127
+
128
+ // Copy assignment.
129
+ BasicPersistent& operator=(const BasicPersistent& other) {
130
+ return operator=(other.Get());
131
+ }
132
+
133
+ template <typename U, typename OtherWeaknessPolicy,
134
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
135
+ typename = std::enable_if_t<std::is_base_of_v<T, U>>>
136
+ BasicPersistent& operator=(
137
+ const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
138
+ OtherCheckingPolicy>& other) {
139
+ return operator=(other.Get());
140
+ }
141
+
142
+ // Move assignment.
143
+ BasicPersistent& operator=(BasicPersistent&& other) noexcept {
144
+ if (this == &other) return *this;
145
+ Clear();
146
+ PersistentBase::operator=(std::move(other));
147
+ LocationPolicy::operator=(std::move(other));
148
+ if (!IsValid()) return *this;
149
+ GetNode()->UpdateOwner(this);
150
+ other.SetValue(nullptr);
151
+ other.SetNode(nullptr);
152
+ this->CheckPointer(Get());
153
+ return *this;
154
+ }
155
+
156
+ // Assignment from member.
157
+ template <typename U, typename MemberBarrierPolicy,
158
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
159
+ typename MemberStorageType,
160
+ typename = std::enable_if_t<std::is_base_of_v<T, U>>>
161
+ BasicPersistent& operator=(
162
+ const internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
163
+ MemberCheckingPolicy, MemberStorageType>&
164
+ member) {
165
+ return operator=(member.Get());
166
+ }
167
+
168
+ BasicPersistent& operator=(T* other) {
169
+ Assign(other);
170
+ return *this;
171
+ }
172
+
173
+ BasicPersistent& operator=(std::nullptr_t) {
174
+ Clear();
175
+ return *this;
176
+ }
177
+
178
+ BasicPersistent& operator=(SentinelPointer s) {
179
+ Assign(s);
180
+ return *this;
181
+ }
182
+
183
+ explicit operator bool() const { return Get(); }
184
+ // Historically we allow implicit conversions to T*.
185
+ // NOLINTNEXTLINE
186
+ operator T*() const { return Get(); }
187
+ T* operator->() const { return Get(); }
188
+ T& operator*() const { return *Get(); }
189
+
190
+ // CFI cast exemption to allow passing SentinelPointer through T* and support
191
+ // heterogeneous assignments between different Member and Persistent handles
192
+ // based on their actual types.
193
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
194
+ // The const_cast below removes the constness from PersistentBase storage.
195
+ // The following static_cast re-adds any constness if specified through the
196
+ // user-visible template parameter T.
197
+ return static_cast<T*>(const_cast<void*>(GetValue()));
198
+ }
199
+
200
+ void Clear() {
201
+ // Simplified version of `Assign()` to allow calling without a complete type
202
+ // `T`.
203
+ if (IsValid()) {
204
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
205
+ SetNode(nullptr);
206
+ }
207
+ SetValue(nullptr);
208
+ }
209
+
210
+ T* Release() {
211
+ T* result = Get();
212
+ Clear();
213
+ return result;
214
+ }
215
+
216
+ template <typename U, typename OtherWeaknessPolicy = WeaknessPolicy,
217
+ typename OtherLocationPolicy = LocationPolicy,
218
+ typename OtherCheckingPolicy = CheckingPolicy>
219
+ BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
220
+ OtherCheckingPolicy>
221
+ To() const {
222
+ return BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
223
+ OtherCheckingPolicy>(static_cast<U*>(Get()));
224
+ }
225
+
226
+ private:
227
+ static void TraceAsRoot(RootVisitor& root_visitor, const void* ptr) {
228
+ root_visitor.Trace(*static_cast<const BasicPersistent*>(ptr));
229
+ }
230
+
231
+ bool IsValid() const {
232
+ // Ideally, handling kSentinelPointer would be done by the embedder. On the
233
+ // other hand, having Persistent aware of it is beneficial since no node
234
+ // gets wasted.
235
+ return GetValue() != nullptr && GetValue() != kSentinelPointer;
236
+ }
237
+
238
+ void Assign(T* ptr) {
239
+ if (IsValid()) {
240
+ if (ptr && ptr != kSentinelPointer) {
241
+ // Simply assign the pointer reusing the existing node.
242
+ SetValue(ptr);
243
+ this->CheckPointer(ptr);
244
+ return;
245
+ }
246
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
247
+ SetNode(nullptr);
248
+ }
249
+ SetValue(ptr);
250
+ if (!IsValid()) return;
251
+ SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
252
+ .AllocateNode(this, &TraceAsRoot));
253
+ this->CheckPointer(Get());
254
+ }
255
+
256
+ void ClearFromGC() const {
257
+ if (IsValid()) {
258
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
259
+ PersistentBase::ClearFromGC();
260
+ }
261
+ }
262
+
263
+ // Set Get() for details.
264
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast")
265
+ T* GetFromGC() const {
266
+ return static_cast<T*>(const_cast<void*>(GetValue()));
267
+ }
268
+
269
+ friend class internal::RootVisitor;
270
+ };
271
+
272
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
273
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
274
+ typename LocationPolicy2, typename CheckingPolicy2>
275
+ bool operator==(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
276
+ CheckingPolicy1>& p1,
277
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
278
+ CheckingPolicy2>& p2) {
279
+ return p1.Get() == p2.Get();
280
+ }
281
+
282
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
283
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
284
+ typename LocationPolicy2, typename CheckingPolicy2>
285
+ bool operator!=(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
286
+ CheckingPolicy1>& p1,
287
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
288
+ CheckingPolicy2>& p2) {
289
+ return !(p1 == p2);
290
+ }
291
+
292
+ template <typename T1, typename PersistentWeaknessPolicy,
293
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
294
+ typename T2, typename MemberWriteBarrierPolicy,
295
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
296
+ typename MemberStorageType>
297
+ bool operator==(
298
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
299
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
300
+ p,
301
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
302
+ MemberCheckingPolicy, MemberStorageType>& m) {
303
+ return p.Get() == m.Get();
304
+ }
305
+
306
+ template <typename T1, typename PersistentWeaknessPolicy,
307
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
308
+ typename T2, typename MemberWriteBarrierPolicy,
309
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
310
+ typename MemberStorageType>
311
+ bool operator!=(
312
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
313
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
314
+ p,
315
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
316
+ MemberCheckingPolicy, MemberStorageType>& m) {
317
+ return !(p == m);
318
+ }
319
+
320
+ template <typename T1, typename MemberWriteBarrierPolicy,
321
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
322
+ typename MemberStorageType, typename T2,
323
+ typename PersistentWeaknessPolicy, typename PersistentLocationPolicy,
324
+ typename PersistentCheckingPolicy>
325
+ bool operator==(
326
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
327
+ MemberCheckingPolicy, MemberStorageType>& m,
328
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
329
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
330
+ p) {
331
+ return m.Get() == p.Get();
332
+ }
333
+
334
+ template <typename T1, typename MemberWriteBarrierPolicy,
335
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
336
+ typename MemberStorageType, typename T2,
337
+ typename PersistentWeaknessPolicy, typename PersistentLocationPolicy,
338
+ typename PersistentCheckingPolicy>
339
+ bool operator!=(
340
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
341
+ MemberCheckingPolicy, MemberStorageType>& m,
342
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
343
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
344
+ p) {
345
+ return !(m == p);
346
+ }
347
+
348
+ template <typename T, typename LocationPolicy, typename CheckingPolicy>
349
+ struct IsWeak<BasicPersistent<T, internal::WeakPersistentPolicy, LocationPolicy,
350
+ CheckingPolicy>> : std::true_type {};
351
+ } // namespace internal
352
+
353
+ /**
354
+ * Persistent is a way to create a strong pointer from an off-heap object to
355
+ * another on-heap object. As long as the Persistent handle is alive the GC will
356
+ * keep the object pointed to alive. The Persistent handle is always a GC root
357
+ * from the point of view of the GC. Persistent must be constructed and
358
+ * destructed in the same thread.
359
+ */
360
+ template <typename T>
361
+ using Persistent =
362
+ internal::BasicPersistent<T, internal::StrongPersistentPolicy>;
363
+
364
+ /**
365
+ * WeakPersistent is a way to create a weak pointer from an off-heap object to
366
+ * an on-heap object. The pointer is automatically cleared when the pointee gets
367
+ * collected. WeakPersistent must be constructed and destructed in the same
368
+ * thread.
369
+ */
370
+ template <typename T>
371
+ using WeakPersistent =
372
+ internal::BasicPersistent<T, internal::WeakPersistentPolicy>;
373
+
374
+ } // namespace cppgc
375
+
376
+ #endif // INCLUDE_CPPGC_PERSISTENT_H_
@@ -0,0 +1,174 @@
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 GetForegroundTaskRunner(TaskPriority::kUserBlocking);
56
+ }
57
+
58
+ /**
59
+ * Returns a TaskRunner with a specific |priority| which can be used to post a
60
+ * task on the foreground thread.
61
+ */
62
+ virtual std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
63
+ TaskPriority priority) {
64
+ return nullptr;
65
+ }
66
+
67
+ /**
68
+ * Posts `job_task` to run in parallel. Returns a `JobHandle` associated with
69
+ * the `Job`, which can be joined or canceled.
70
+ * This avoids degenerate cases:
71
+ * - Calling `CallOnWorkerThread()` for each work item, causing significant
72
+ * overhead.
73
+ * - Fixed number of `CallOnWorkerThread()` calls that split the work and
74
+ * might run for a long time. This is problematic when many components post
75
+ * "num cores" tasks and all expect to use all the cores. In these cases,
76
+ * the scheduler lacks context to be fair to multiple same-priority requests
77
+ * and/or ability to request lower priority work to yield when high priority
78
+ * work comes in.
79
+ * A canonical implementation of `job_task` looks like:
80
+ * \code
81
+ * class MyJobTask : public JobTask {
82
+ * public:
83
+ * MyJobTask(...) : worker_queue_(...) {}
84
+ * // JobTask implementation.
85
+ * void Run(JobDelegate* delegate) override {
86
+ * while (!delegate->ShouldYield()) {
87
+ * // Smallest unit of work.
88
+ * auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
89
+ * if (!work_item) return;
90
+ * ProcessWork(work_item);
91
+ * }
92
+ * }
93
+ *
94
+ * size_t GetMaxConcurrency() const override {
95
+ * return worker_queue_.GetSize(); // Thread safe.
96
+ * }
97
+ * };
98
+ *
99
+ * // ...
100
+ * auto handle = PostJob(TaskPriority::kUserVisible,
101
+ * std::make_unique<MyJobTask>(...));
102
+ * handle->Join();
103
+ * \endcode
104
+ *
105
+ * `PostJob()` and methods of the returned JobHandle/JobDelegate, must never
106
+ * be called while holding a lock that could be acquired by `JobTask::Run()`
107
+ * or `JobTask::GetMaxConcurrency()` -- that could result in a deadlock. This
108
+ * is because (1) `JobTask::GetMaxConcurrency()` may be invoked while holding
109
+ * internal lock (A), hence `JobTask::GetMaxConcurrency()` can only use a lock
110
+ * (B) if that lock is *never* held while calling back into `JobHandle` from
111
+ * any thread (A=>B/B=>A deadlock) and (2) `JobTask::Run()` or
112
+ * `JobTask::GetMaxConcurrency()` may be invoked synchronously from
113
+ * `JobHandle` (B=>JobHandle::foo=>B deadlock).
114
+ *
115
+ * A sufficient `PostJob()` implementation that uses the default Job provided
116
+ * in libplatform looks like:
117
+ * \code
118
+ * std::unique_ptr<JobHandle> PostJob(
119
+ * TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
120
+ * return std::make_unique<DefaultJobHandle>(
121
+ * std::make_shared<DefaultJobState>(
122
+ * this, std::move(job_task), kNumThreads));
123
+ * }
124
+ * \endcode
125
+ */
126
+ virtual std::unique_ptr<JobHandle> PostJob(
127
+ TaskPriority priority, std::unique_ptr<JobTask> job_task) {
128
+ return nullptr;
129
+ }
130
+
131
+ /**
132
+ * Returns an instance of a `TracingController`. This must be non-nullptr. The
133
+ * default implementation returns an empty `TracingController` that consumes
134
+ * trace data without effect.
135
+ */
136
+ virtual TracingController* GetTracingController();
137
+ };
138
+
139
+ V8_EXPORT bool IsInitialized();
140
+
141
+ /**
142
+ * Process-global initialization of the garbage collector. Must be called before
143
+ * creating a Heap.
144
+ *
145
+ * Can be called multiple times when paired with `ShutdownProcess()`.
146
+ *
147
+ * \param page_allocator The allocator used for maintaining meta data. Must stay
148
+ * always alive and not change between multiple calls to InitializeProcess. If
149
+ * no allocator is provided, a default internal version will be used.
150
+ * \param desired_heap_size Desired amount of virtual address space to reserve
151
+ * for the heap, in bytes. Actual size will be clamped to minimum and maximum
152
+ * values based on compile-time settings and may be rounded up. If this
153
+ * parameter is zero, a default value will be used.
154
+ */
155
+ V8_EXPORT void InitializeProcess(PageAllocator* page_allocator = nullptr,
156
+ size_t desired_heap_size = 0);
157
+
158
+ /**
159
+ * Must be called after destroying the last used heap. Some process-global
160
+ * metadata may not be returned and reused upon a subsequent
161
+ * `InitializeProcess()` call.
162
+ */
163
+ V8_EXPORT void ShutdownProcess();
164
+
165
+ namespace internal {
166
+
167
+ V8_EXPORT void Fatal(const std::string& reason = std::string(),
168
+ SourceLocation = SourceLocation::Current());
169
+
170
+ } // namespace internal
171
+
172
+ } // namespace cppgc
173
+
174
+ #endif // INCLUDE_CPPGC_PLATFORM_H_