node-linux-arm64 20.5.1 → 20.6.0

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 (50) hide show
  1. package/CHANGELOG.md +226 -0
  2. package/LICENSE +1 -1
  3. package/README.md +6 -0
  4. package/bin/node +0 -0
  5. package/include/node/common.gypi +1 -1
  6. package/include/node/cppgc/allocation.h +310 -0
  7. package/include/node/cppgc/cross-thread-persistent.h +466 -0
  8. package/include/node/cppgc/custom-space.h +97 -0
  9. package/include/node/cppgc/default-platform.h +67 -0
  10. package/include/node/cppgc/ephemeron-pair.h +30 -0
  11. package/include/node/cppgc/explicit-management.h +100 -0
  12. package/include/node/cppgc/garbage-collected.h +106 -0
  13. package/include/node/cppgc/heap-consistency.h +309 -0
  14. package/include/node/cppgc/heap-handle.h +48 -0
  15. package/include/node/cppgc/heap-state.h +82 -0
  16. package/include/node/cppgc/heap-statistics.h +120 -0
  17. package/include/node/cppgc/heap.h +202 -0
  18. package/include/node/cppgc/internal/api-constants.h +68 -0
  19. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  20. package/include/node/cppgc/internal/base-page-handle.h +45 -0
  21. package/include/node/cppgc/internal/caged-heap-local-data.h +111 -0
  22. package/include/node/cppgc/internal/caged-heap.h +61 -0
  23. package/include/node/cppgc/internal/compiler-specific.h +38 -0
  24. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  25. package/include/node/cppgc/internal/gc-info.h +157 -0
  26. package/include/node/cppgc/internal/logging.h +50 -0
  27. package/include/node/cppgc/internal/member-storage.h +248 -0
  28. package/include/node/cppgc/internal/name-trait.h +137 -0
  29. package/include/node/cppgc/internal/persistent-node.h +214 -0
  30. package/include/node/cppgc/internal/pointer-policies.h +243 -0
  31. package/include/node/cppgc/internal/write-barrier.h +487 -0
  32. package/include/node/cppgc/liveness-broker.h +78 -0
  33. package/include/node/cppgc/macros.h +35 -0
  34. package/include/node/cppgc/member.h +604 -0
  35. package/include/node/cppgc/name-provider.h +65 -0
  36. package/include/node/cppgc/object-size-trait.h +58 -0
  37. package/include/node/cppgc/persistent.h +373 -0
  38. package/include/node/cppgc/platform.h +158 -0
  39. package/include/node/cppgc/prefinalizer.h +75 -0
  40. package/include/node/cppgc/process-heap-statistics.h +36 -0
  41. package/include/node/cppgc/sentinel-pointer.h +32 -0
  42. package/include/node/cppgc/source-location.h +92 -0
  43. package/include/node/cppgc/testing.h +106 -0
  44. package/include/node/cppgc/trace-trait.h +120 -0
  45. package/include/node/cppgc/type-traits.h +250 -0
  46. package/include/node/cppgc/visitor.h +426 -0
  47. package/include/node/node.h +26 -3
  48. package/include/node/node_version.h +2 -2
  49. package/include/node/v8-cppgc.h +245 -0
  50. package/package.json +1 -1
@@ -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,373 @@
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 MemberStorageType,
118
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
119
+ BasicPersistent(const internal::BasicMember<
120
+ U, MemberBarrierPolicy, MemberWeaknessTag,
121
+ MemberCheckingPolicy, MemberStorageType>& member,
122
+ const SourceLocation& loc = SourceLocation::Current())
123
+ : BasicPersistent(member.Get(), loc) {}
124
+
125
+ ~BasicPersistent() { Clear(); }
126
+
127
+ // Copy assignment.
128
+ BasicPersistent& operator=(const BasicPersistent& other) {
129
+ return operator=(other.Get());
130
+ }
131
+
132
+ template <typename U, typename OtherWeaknessPolicy,
133
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
134
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
135
+ BasicPersistent& operator=(
136
+ const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
137
+ OtherCheckingPolicy>& other) {
138
+ return operator=(other.Get());
139
+ }
140
+
141
+ // Move assignment.
142
+ BasicPersistent& operator=(BasicPersistent&& other) noexcept {
143
+ if (this == &other) return *this;
144
+ Clear();
145
+ PersistentBase::operator=(std::move(other));
146
+ LocationPolicy::operator=(std::move(other));
147
+ if (!IsValid()) return *this;
148
+ GetNode()->UpdateOwner(this);
149
+ other.SetValue(nullptr);
150
+ other.SetNode(nullptr);
151
+ this->CheckPointer(Get());
152
+ return *this;
153
+ }
154
+
155
+ // Assignment from member.
156
+ template <typename U, typename MemberBarrierPolicy,
157
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
158
+ typename MemberStorageType,
159
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
160
+ BasicPersistent& operator=(
161
+ const internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
162
+ MemberCheckingPolicy, MemberStorageType>&
163
+ member) {
164
+ return operator=(member.Get());
165
+ }
166
+
167
+ BasicPersistent& operator=(T* other) {
168
+ Assign(other);
169
+ return *this;
170
+ }
171
+
172
+ BasicPersistent& operator=(std::nullptr_t) {
173
+ Clear();
174
+ return *this;
175
+ }
176
+
177
+ BasicPersistent& operator=(SentinelPointer s) {
178
+ Assign(s);
179
+ return *this;
180
+ }
181
+
182
+ explicit operator bool() const { return Get(); }
183
+ operator T*() const { return Get(); }
184
+ T* operator->() const { return Get(); }
185
+ T& operator*() const { return *Get(); }
186
+
187
+ // CFI cast exemption to allow passing SentinelPointer through T* and support
188
+ // heterogeneous assignments between different Member and Persistent handles
189
+ // based on their actual types.
190
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
191
+ // The const_cast below removes the constness from PersistentBase storage.
192
+ // The following static_cast re-adds any constness if specified through the
193
+ // user-visible template parameter T.
194
+ return static_cast<T*>(const_cast<void*>(GetValue()));
195
+ }
196
+
197
+ void Clear() {
198
+ // Simplified version of `Assign()` to allow calling without a complete type
199
+ // `T`.
200
+ if (IsValid()) {
201
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
202
+ SetNode(nullptr);
203
+ }
204
+ SetValue(nullptr);
205
+ }
206
+
207
+ T* Release() {
208
+ T* result = Get();
209
+ Clear();
210
+ return result;
211
+ }
212
+
213
+ template <typename U, typename OtherWeaknessPolicy = WeaknessPolicy,
214
+ typename OtherLocationPolicy = LocationPolicy,
215
+ typename OtherCheckingPolicy = CheckingPolicy>
216
+ BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
217
+ OtherCheckingPolicy>
218
+ To() const {
219
+ return BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
220
+ OtherCheckingPolicy>(static_cast<U*>(Get()));
221
+ }
222
+
223
+ private:
224
+ static void TraceAsRoot(RootVisitor& root_visitor, const void* ptr) {
225
+ root_visitor.Trace(*static_cast<const BasicPersistent*>(ptr));
226
+ }
227
+
228
+ bool IsValid() const {
229
+ // Ideally, handling kSentinelPointer would be done by the embedder. On the
230
+ // other hand, having Persistent aware of it is beneficial since no node
231
+ // gets wasted.
232
+ return GetValue() != nullptr && GetValue() != kSentinelPointer;
233
+ }
234
+
235
+ void Assign(T* ptr) {
236
+ if (IsValid()) {
237
+ if (ptr && ptr != kSentinelPointer) {
238
+ // Simply assign the pointer reusing the existing node.
239
+ SetValue(ptr);
240
+ this->CheckPointer(ptr);
241
+ return;
242
+ }
243
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
244
+ SetNode(nullptr);
245
+ }
246
+ SetValue(ptr);
247
+ if (!IsValid()) return;
248
+ SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
249
+ .AllocateNode(this, &TraceAsRoot));
250
+ this->CheckPointer(Get());
251
+ }
252
+
253
+ void ClearFromGC() const {
254
+ if (IsValid()) {
255
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
256
+ PersistentBase::ClearFromGC();
257
+ }
258
+ }
259
+
260
+ // Set Get() for details.
261
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast")
262
+ T* GetFromGC() const {
263
+ return static_cast<T*>(const_cast<void*>(GetValue()));
264
+ }
265
+
266
+ friend class internal::RootVisitor;
267
+ };
268
+
269
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
270
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
271
+ typename LocationPolicy2, typename CheckingPolicy2>
272
+ bool operator==(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
273
+ CheckingPolicy1>& p1,
274
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
275
+ CheckingPolicy2>& p2) {
276
+ return p1.Get() == p2.Get();
277
+ }
278
+
279
+ template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
280
+ typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
281
+ typename LocationPolicy2, typename CheckingPolicy2>
282
+ bool operator!=(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
283
+ CheckingPolicy1>& p1,
284
+ const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
285
+ CheckingPolicy2>& p2) {
286
+ return !(p1 == p2);
287
+ }
288
+
289
+ template <typename T1, typename PersistentWeaknessPolicy,
290
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
291
+ typename T2, typename MemberWriteBarrierPolicy,
292
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
293
+ typename MemberStorageType>
294
+ bool operator==(
295
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
296
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
297
+ p,
298
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
299
+ MemberCheckingPolicy, MemberStorageType>& m) {
300
+ return p.Get() == m.Get();
301
+ }
302
+
303
+ template <typename T1, typename PersistentWeaknessPolicy,
304
+ typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
305
+ typename T2, typename MemberWriteBarrierPolicy,
306
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
307
+ typename MemberStorageType>
308
+ bool operator!=(
309
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
310
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
311
+ p,
312
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
313
+ MemberCheckingPolicy, MemberStorageType>& m) {
314
+ return !(p == m);
315
+ }
316
+
317
+ template <typename T1, typename MemberWriteBarrierPolicy,
318
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
319
+ typename MemberStorageType, typename T2,
320
+ typename PersistentWeaknessPolicy, typename PersistentLocationPolicy,
321
+ typename PersistentCheckingPolicy>
322
+ bool operator==(
323
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
324
+ MemberCheckingPolicy, MemberStorageType>& m,
325
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
326
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
327
+ p) {
328
+ return m.Get() == p.Get();
329
+ }
330
+
331
+ template <typename T1, typename MemberWriteBarrierPolicy,
332
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
333
+ typename MemberStorageType, typename T2,
334
+ typename PersistentWeaknessPolicy, typename PersistentLocationPolicy,
335
+ typename PersistentCheckingPolicy>
336
+ bool operator!=(
337
+ const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
338
+ MemberCheckingPolicy, MemberStorageType>& m,
339
+ const BasicPersistent<T1, PersistentWeaknessPolicy,
340
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
341
+ p) {
342
+ return !(m == p);
343
+ }
344
+
345
+ template <typename T, typename LocationPolicy, typename CheckingPolicy>
346
+ struct IsWeak<BasicPersistent<T, internal::WeakPersistentPolicy, LocationPolicy,
347
+ CheckingPolicy>> : std::true_type {};
348
+ } // namespace internal
349
+
350
+ /**
351
+ * Persistent is a way to create a strong pointer from an off-heap object to
352
+ * another on-heap object. As long as the Persistent handle is alive the GC will
353
+ * keep the object pointed to alive. The Persistent handle is always a GC root
354
+ * from the point of view of the GC. Persistent must be constructed and
355
+ * destructed in the same thread.
356
+ */
357
+ template <typename T>
358
+ using Persistent =
359
+ internal::BasicPersistent<T, internal::StrongPersistentPolicy>;
360
+
361
+ /**
362
+ * WeakPersistent is a way to create a weak pointer from an off-heap object to
363
+ * an on-heap object. The pointer is automatically cleared when the pointee gets
364
+ * collected. WeakPersistent must be constructed and destructed in the same
365
+ * thread.
366
+ */
367
+ template <typename T>
368
+ using WeakPersistent =
369
+ internal::BasicPersistent<T, internal::WeakPersistentPolicy>;
370
+
371
+ } // namespace cppgc
372
+
373
+ #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_