libv8-node 16.10.0.0-arm64-darwin

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