aha-libv8-node 16.0.0.0-linux

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 (67) 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 +30 -0
  5. data/lib/libv8-node.rb +1 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8/node/version.rb +7 -0
  8. data/vendor/v8/include/cppgc/allocation.h +229 -0
  9. data/vendor/v8/include/cppgc/common.h +29 -0
  10. data/vendor/v8/include/cppgc/cross-thread-persistent.h +345 -0
  11. data/vendor/v8/include/cppgc/custom-space.h +97 -0
  12. data/vendor/v8/include/cppgc/default-platform.h +75 -0
  13. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  14. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  15. data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
  16. data/vendor/v8/include/cppgc/heap-state.h +59 -0
  17. data/vendor/v8/include/cppgc/heap-statistics.h +110 -0
  18. data/vendor/v8/include/cppgc/heap.h +199 -0
  19. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  20. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  21. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +68 -0
  22. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  23. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  24. data/vendor/v8/include/cppgc/internal/gc-info.h +47 -0
  25. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  26. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  27. data/vendor/v8/include/cppgc/internal/persistent-node.h +132 -0
  28. data/vendor/v8/include/cppgc/internal/pointer-policies.h +143 -0
  29. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  30. data/vendor/v8/include/cppgc/internal/write-barrier.h +390 -0
  31. data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
  32. data/vendor/v8/include/cppgc/macros.h +26 -0
  33. data/vendor/v8/include/cppgc/member.h +271 -0
  34. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  35. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  36. data/vendor/v8/include/cppgc/persistent.h +365 -0
  37. data/vendor/v8/include/cppgc/platform.h +151 -0
  38. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  39. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  40. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  41. data/vendor/v8/include/cppgc/source-location.h +91 -0
  42. data/vendor/v8/include/cppgc/testing.h +50 -0
  43. data/vendor/v8/include/cppgc/trace-trait.h +116 -0
  44. data/vendor/v8/include/cppgc/type-traits.h +228 -0
  45. data/vendor/v8/include/cppgc/visitor.h +340 -0
  46. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  47. data/vendor/v8/include/libplatform/libplatform.h +117 -0
  48. data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
  49. data/vendor/v8/include/v8-cppgc.h +278 -0
  50. data/vendor/v8/include/v8-fast-api-calls.h +419 -0
  51. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  52. data/vendor/v8/include/v8-inspector.h +336 -0
  53. data/vendor/v8/include/v8-internal.h +462 -0
  54. data/vendor/v8/include/v8-metrics.h +189 -0
  55. data/vendor/v8/include/v8-platform.h +710 -0
  56. data/vendor/v8/include/v8-profiler.h +1116 -0
  57. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  58. data/vendor/v8/include/v8-util.h +652 -0
  59. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  60. data/vendor/v8/include/v8-version-string.h +38 -0
  61. data/vendor/v8/include/v8-version.h +20 -0
  62. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  63. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  64. data/vendor/v8/include/v8.h +12479 -0
  65. data/vendor/v8/include/v8config.h +521 -0
  66. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  67. metadata +137 -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( // NOLINT
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, // NOLINT
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) {
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(); } // NOLINT
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,151 @@
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 "v8-platform.h" // NOLINT(build/include_directory)
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace cppgc {
12
+
13
+ // TODO(v8:10346): Create separate includes for concepts that are not
14
+ // V8-specific.
15
+ using IdleTask = v8::IdleTask;
16
+ using JobHandle = v8::JobHandle;
17
+ using JobDelegate = v8::JobDelegate;
18
+ using JobTask = v8::JobTask;
19
+ using PageAllocator = v8::PageAllocator;
20
+ using Task = v8::Task;
21
+ using TaskPriority = v8::TaskPriority;
22
+ using TaskRunner = v8::TaskRunner;
23
+ using TracingController = v8::TracingController;
24
+
25
+ /**
26
+ * Platform interface used by Heap. Contains allocators and executors.
27
+ */
28
+ class V8_EXPORT Platform {
29
+ public:
30
+ virtual ~Platform() = default;
31
+
32
+ /**
33
+ * Returns the allocator used by cppgc to allocate its heap and various
34
+ * support structures.
35
+ */
36
+ virtual PageAllocator* GetPageAllocator() = 0;
37
+
38
+ /**
39
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
40
+ * the past. This function is expected to return at least
41
+ * millisecond-precision values. For this reason,
42
+ * it is recommended that the fixed point be no further in the past than
43
+ * the epoch.
44
+ **/
45
+ virtual double MonotonicallyIncreasingTime() = 0;
46
+
47
+ /**
48
+ * Foreground task runner that should be used by a Heap.
49
+ */
50
+ virtual std::shared_ptr<TaskRunner> GetForegroundTaskRunner() {
51
+ return nullptr;
52
+ }
53
+
54
+ /**
55
+ * Posts `job_task` to run in parallel. Returns a `JobHandle` associated with
56
+ * the `Job`, which can be joined or canceled.
57
+ * This avoids degenerate cases:
58
+ * - Calling `CallOnWorkerThread()` for each work item, causing significant
59
+ * overhead.
60
+ * - Fixed number of `CallOnWorkerThread()` calls that split the work and
61
+ * might run for a long time. This is problematic when many components post
62
+ * "num cores" tasks and all expect to use all the cores. In these cases,
63
+ * the scheduler lacks context to be fair to multiple same-priority requests
64
+ * and/or ability to request lower priority work to yield when high priority
65
+ * work comes in.
66
+ * A canonical implementation of `job_task` looks like:
67
+ * \code
68
+ * class MyJobTask : public JobTask {
69
+ * public:
70
+ * MyJobTask(...) : worker_queue_(...) {}
71
+ * // JobTask implementation.
72
+ * void Run(JobDelegate* delegate) override {
73
+ * while (!delegate->ShouldYield()) {
74
+ * // Smallest unit of work.
75
+ * auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
76
+ * if (!work_item) return;
77
+ * ProcessWork(work_item);
78
+ * }
79
+ * }
80
+ *
81
+ * size_t GetMaxConcurrency() const override {
82
+ * return worker_queue_.GetSize(); // Thread safe.
83
+ * }
84
+ * };
85
+ *
86
+ * // ...
87
+ * auto handle = PostJob(TaskPriority::kUserVisible,
88
+ * std::make_unique<MyJobTask>(...));
89
+ * handle->Join();
90
+ * \endcode
91
+ *
92
+ * `PostJob()` and methods of the returned JobHandle/JobDelegate, must never
93
+ * be called while holding a lock that could be acquired by `JobTask::Run()`
94
+ * or `JobTask::GetMaxConcurrency()` -- that could result in a deadlock. This
95
+ * is because (1) `JobTask::GetMaxConcurrency()` may be invoked while holding
96
+ * internal lock (A), hence `JobTask::GetMaxConcurrency()` can only use a lock
97
+ * (B) if that lock is *never* held while calling back into `JobHandle` from
98
+ * any thread (A=>B/B=>A deadlock) and (2) `JobTask::Run()` or
99
+ * `JobTask::GetMaxConcurrency()` may be invoked synchronously from
100
+ * `JobHandle` (B=>JobHandle::foo=>B deadlock).
101
+ *
102
+ * A sufficient `PostJob()` implementation that uses the default Job provided
103
+ * in libplatform looks like:
104
+ * \code
105
+ * std::unique_ptr<JobHandle> PostJob(
106
+ * TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
107
+ * return std::make_unique<DefaultJobHandle>(
108
+ * std::make_shared<DefaultJobState>(
109
+ * this, std::move(job_task), kNumThreads));
110
+ * }
111
+ * \endcode
112
+ */
113
+ virtual std::unique_ptr<JobHandle> PostJob(
114
+ TaskPriority priority, std::unique_ptr<JobTask> job_task) {
115
+ return nullptr;
116
+ }
117
+
118
+ /**
119
+ * Returns an instance of a `TracingController`. This must be non-nullptr. The
120
+ * default implementation returns an empty `TracingController` that consumes
121
+ * trace data without effect.
122
+ */
123
+ virtual TracingController* GetTracingController();
124
+ };
125
+
126
+ /**
127
+ * Process-global initialization of the garbage collector. Must be called before
128
+ * creating a Heap.
129
+ *
130
+ * Can be called multiple times when paired with `ShutdownProcess()`.
131
+ *
132
+ * \param page_allocator The allocator used for maintaining meta data. Must not
133
+ * change between multiple calls to InitializeProcess.
134
+ */
135
+ V8_EXPORT void InitializeProcess(PageAllocator* page_allocator);
136
+
137
+ /**
138
+ * Must be called after destroying the last used heap. Some process-global
139
+ * metadata may not be returned and reused upon a subsequent
140
+ * `InitializeProcess()` call.
141
+ */
142
+ V8_EXPORT void ShutdownProcess();
143
+
144
+ namespace internal {
145
+
146
+ V8_EXPORT void Abort();
147
+
148
+ } // namespace internal
149
+ } // namespace cppgc
150
+
151
+ #endif // INCLUDE_CPPGC_PLATFORM_H_