libv8-node 15.14.0.0-x86_64-linux → 16.17.0.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +1 -1
  3. data/ext/libv8-node/paths.rb +5 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/include/cppgc/allocation.h +105 -45
  6. data/vendor/v8/include/cppgc/common.h +9 -6
  7. data/vendor/v8/include/cppgc/cross-thread-persistent.h +413 -0
  8. data/vendor/v8/include/cppgc/custom-space.h +37 -2
  9. data/vendor/v8/include/cppgc/default-platform.h +47 -48
  10. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  11. data/vendor/v8/include/cppgc/explicit-management.h +82 -0
  12. data/vendor/v8/include/cppgc/garbage-collected.h +4 -3
  13. data/vendor/v8/include/cppgc/heap-consistency.h +253 -0
  14. data/vendor/v8/include/cppgc/heap-state.h +70 -0
  15. data/vendor/v8/include/cppgc/heap-statistics.h +120 -0
  16. data/vendor/v8/include/cppgc/heap.h +68 -6
  17. data/vendor/v8/include/cppgc/internal/api-constants.h +3 -3
  18. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +2 -1
  19. data/vendor/v8/include/cppgc/internal/compiler-specific.h +2 -2
  20. data/vendor/v8/include/cppgc/internal/gc-info.h +44 -13
  21. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  22. data/vendor/v8/include/cppgc/internal/persistent-node.h +58 -2
  23. data/vendor/v8/include/cppgc/internal/pointer-policies.h +69 -28
  24. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +1 -1
  25. data/vendor/v8/include/cppgc/internal/write-barrier.h +390 -35
  26. data/vendor/v8/include/cppgc/liveness-broker.h +11 -2
  27. data/vendor/v8/include/cppgc/macros.h +2 -0
  28. data/vendor/v8/include/cppgc/member.h +87 -25
  29. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  30. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  31. data/vendor/v8/include/cppgc/persistent.h +40 -10
  32. data/vendor/v8/include/cppgc/platform.h +49 -25
  33. data/vendor/v8/include/cppgc/prefinalizer.h +1 -1
  34. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  35. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  36. data/vendor/v8/include/cppgc/source-location.h +2 -1
  37. data/vendor/v8/include/cppgc/testing.h +99 -0
  38. data/vendor/v8/include/cppgc/trace-trait.h +8 -3
  39. data/vendor/v8/include/cppgc/type-traits.h +157 -19
  40. data/vendor/v8/include/cppgc/visitor.h +194 -28
  41. data/vendor/v8/include/libplatform/libplatform.h +11 -0
  42. data/vendor/v8/include/libplatform/v8-tracing.h +2 -0
  43. data/vendor/v8/include/v8-cppgc.h +258 -159
  44. data/vendor/v8/include/v8-fast-api-calls.h +603 -155
  45. data/vendor/v8/include/v8-inspector.h +22 -4
  46. data/vendor/v8/include/v8-internal.h +111 -27
  47. data/vendor/v8/include/v8-metrics.h +77 -8
  48. data/vendor/v8/include/v8-platform.h +47 -22
  49. data/vendor/v8/include/v8-profiler.h +75 -11
  50. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  51. data/vendor/v8/include/v8-util.h +1 -1
  52. data/vendor/v8/include/v8-version.h +4 -4
  53. data/vendor/v8/include/v8.h +1196 -642
  54. data/vendor/v8/include/v8config.h +87 -11
  55. data/vendor/v8/{out.gn → x86_64-linux}/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +17 -5
  57. data/vendor/v8/include/cppgc/internal/process-heap.h +0 -34
@@ -0,0 +1,413 @@
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_CROSS_THREAD_PERSISTENT_H_
6
+ #define INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
7
+
8
+ #include <atomic>
9
+
10
+ #include "cppgc/internal/persistent-node.h"
11
+ #include "cppgc/internal/pointer-policies.h"
12
+ #include "cppgc/persistent.h"
13
+ #include "cppgc/visitor.h"
14
+
15
+ namespace cppgc {
16
+ namespace internal {
17
+
18
+ // Wrapper around PersistentBase that allows accessing poisoned memory when
19
+ // using ASAN. This is needed as the GC of the heap that owns the value
20
+ // of a CTP, may clear it (heap termination, weakness) while the object
21
+ // holding the CTP may be poisoned as itself may be deemed dead.
22
+ class CrossThreadPersistentBase : public PersistentBase {
23
+ public:
24
+ CrossThreadPersistentBase() = default;
25
+ explicit CrossThreadPersistentBase(const void* raw) : PersistentBase(raw) {}
26
+
27
+ V8_CLANG_NO_SANITIZE("address") const void* GetValueFromGC() const {
28
+ return raw_;
29
+ }
30
+
31
+ V8_CLANG_NO_SANITIZE("address")
32
+ PersistentNode* GetNodeFromGC() const { return node_; }
33
+
34
+ V8_CLANG_NO_SANITIZE("address")
35
+ void ClearFromGC() const {
36
+ raw_ = nullptr;
37
+ node_ = nullptr;
38
+ }
39
+ };
40
+
41
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
42
+ typename CheckingPolicy>
43
+ class BasicCrossThreadPersistent final : public CrossThreadPersistentBase,
44
+ public LocationPolicy,
45
+ private WeaknessPolicy,
46
+ private CheckingPolicy {
47
+ public:
48
+ using typename WeaknessPolicy::IsStrongPersistent;
49
+ using PointeeType = T;
50
+
51
+ ~BasicCrossThreadPersistent() { Clear(); }
52
+
53
+ BasicCrossThreadPersistent(
54
+ const SourceLocation& loc = SourceLocation::Current())
55
+ : LocationPolicy(loc) {}
56
+
57
+ BasicCrossThreadPersistent(
58
+ std::nullptr_t, const SourceLocation& loc = SourceLocation::Current())
59
+ : LocationPolicy(loc) {}
60
+
61
+ BasicCrossThreadPersistent(
62
+ SentinelPointer s, const SourceLocation& loc = SourceLocation::Current())
63
+ : CrossThreadPersistentBase(s), LocationPolicy(loc) {}
64
+
65
+ BasicCrossThreadPersistent(
66
+ T* raw, const SourceLocation& loc = SourceLocation::Current())
67
+ : CrossThreadPersistentBase(raw), LocationPolicy(loc) {
68
+ if (!IsValid(raw)) return;
69
+ PersistentRegionLock guard;
70
+ CrossThreadPersistentRegion& region = this->GetPersistentRegion(raw);
71
+ SetNode(region.AllocateNode(this, &Trace));
72
+ this->CheckPointer(raw);
73
+ }
74
+
75
+ class UnsafeCtorTag {
76
+ private:
77
+ UnsafeCtorTag() = default;
78
+ template <typename U, typename OtherWeaknessPolicy,
79
+ typename OtherLocationPolicy, typename OtherCheckingPolicy>
80
+ friend class BasicCrossThreadPersistent;
81
+ };
82
+
83
+ BasicCrossThreadPersistent(
84
+ UnsafeCtorTag, T* raw,
85
+ const SourceLocation& loc = SourceLocation::Current())
86
+ : CrossThreadPersistentBase(raw), LocationPolicy(loc) {
87
+ if (!IsValid(raw)) return;
88
+ CrossThreadPersistentRegion& region = this->GetPersistentRegion(raw);
89
+ SetNode(region.AllocateNode(this, &Trace));
90
+ this->CheckPointer(raw);
91
+ }
92
+
93
+ BasicCrossThreadPersistent(
94
+ T& raw, const SourceLocation& loc = SourceLocation::Current())
95
+ : BasicCrossThreadPersistent(&raw, loc) {}
96
+
97
+ template <typename U, typename MemberBarrierPolicy,
98
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
99
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
100
+ BasicCrossThreadPersistent(
101
+ internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
102
+ MemberCheckingPolicy>
103
+ member,
104
+ const SourceLocation& loc = SourceLocation::Current())
105
+ : BasicCrossThreadPersistent(member.Get(), loc) {}
106
+
107
+ BasicCrossThreadPersistent(
108
+ const BasicCrossThreadPersistent& other,
109
+ const SourceLocation& loc = SourceLocation::Current())
110
+ : BasicCrossThreadPersistent(loc) {
111
+ // Invoke operator=.
112
+ *this = other;
113
+ }
114
+
115
+ // Heterogeneous ctor.
116
+ template <typename U, typename OtherWeaknessPolicy,
117
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
118
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
119
+ BasicCrossThreadPersistent(
120
+ const BasicCrossThreadPersistent<U, OtherWeaknessPolicy,
121
+ OtherLocationPolicy,
122
+ OtherCheckingPolicy>& other,
123
+ const SourceLocation& loc = SourceLocation::Current())
124
+ : BasicCrossThreadPersistent(loc) {
125
+ *this = other;
126
+ }
127
+
128
+ BasicCrossThreadPersistent(
129
+ BasicCrossThreadPersistent&& other,
130
+ const SourceLocation& loc = SourceLocation::Current()) noexcept {
131
+ // Invoke operator=.
132
+ *this = std::move(other);
133
+ }
134
+
135
+ BasicCrossThreadPersistent& operator=(
136
+ const BasicCrossThreadPersistent& other) {
137
+ PersistentRegionLock guard;
138
+ AssignUnsafe(other.Get());
139
+ return *this;
140
+ }
141
+
142
+ template <typename U, typename OtherWeaknessPolicy,
143
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
144
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
145
+ BasicCrossThreadPersistent& operator=(
146
+ const BasicCrossThreadPersistent<U, OtherWeaknessPolicy,
147
+ OtherLocationPolicy,
148
+ OtherCheckingPolicy>& other) {
149
+ PersistentRegionLock guard;
150
+ AssignUnsafe(other.Get());
151
+ return *this;
152
+ }
153
+
154
+ BasicCrossThreadPersistent& operator=(BasicCrossThreadPersistent&& other) {
155
+ if (this == &other) return *this;
156
+ Clear();
157
+ PersistentRegionLock guard;
158
+ PersistentBase::operator=(std::move(other));
159
+ LocationPolicy::operator=(std::move(other));
160
+ if (!IsValid(GetValue())) return *this;
161
+ GetNode()->UpdateOwner(this);
162
+ other.SetValue(nullptr);
163
+ other.SetNode(nullptr);
164
+ this->CheckPointer(Get());
165
+ return *this;
166
+ }
167
+
168
+ BasicCrossThreadPersistent& operator=(T* other) {
169
+ Assign(other);
170
+ return *this;
171
+ }
172
+
173
+ // Assignment from member.
174
+ template <typename U, typename MemberBarrierPolicy,
175
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
176
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
177
+ BasicCrossThreadPersistent& operator=(
178
+ internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
179
+ MemberCheckingPolicy>
180
+ member) {
181
+ return operator=(member.Get());
182
+ }
183
+
184
+ BasicCrossThreadPersistent& operator=(std::nullptr_t) {
185
+ Clear();
186
+ return *this;
187
+ }
188
+
189
+ BasicCrossThreadPersistent& operator=(SentinelPointer s) {
190
+ Assign(s);
191
+ return *this;
192
+ }
193
+
194
+ /**
195
+ * Returns a pointer to the stored object.
196
+ *
197
+ * Note: **Not thread-safe.**
198
+ *
199
+ * \returns a pointer to the stored object.
200
+ */
201
+ // CFI cast exemption to allow passing SentinelPointer through T* and support
202
+ // heterogeneous assignments between different Member and Persistent handles
203
+ // based on their actual types.
204
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
205
+ return static_cast<T*>(const_cast<void*>(GetValue()));
206
+ }
207
+
208
+ /**
209
+ * Clears the stored object.
210
+ */
211
+ void Clear() {
212
+ // Simplified version of `Assign()` to allow calling without a complete type
213
+ // `T`.
214
+ const void* old_value = GetValue();
215
+ if (IsValid(old_value)) {
216
+ PersistentRegionLock guard;
217
+ old_value = GetValue();
218
+ // The fast path check (IsValid()) does not acquire the lock. Reload
219
+ // the value to ensure the reference has not been cleared.
220
+ if (IsValid(old_value)) {
221
+ CrossThreadPersistentRegion& region =
222
+ this->GetPersistentRegion(old_value);
223
+ region.FreeNode(GetNode());
224
+ SetNode(nullptr);
225
+ } else {
226
+ CPPGC_DCHECK(!GetNode());
227
+ }
228
+ }
229
+ SetValue(nullptr);
230
+ }
231
+
232
+ /**
233
+ * Returns a pointer to the stored object and releases it.
234
+ *
235
+ * Note: **Not thread-safe.**
236
+ *
237
+ * \returns a pointer to the stored object.
238
+ */
239
+ T* Release() {
240
+ T* result = Get();
241
+ Clear();
242
+ return result;
243
+ }
244
+
245
+ /**
246
+ * Conversio to boolean.
247
+ *
248
+ * Note: **Not thread-safe.**
249
+ *
250
+ * \returns true if an actual object has been stored and false otherwise.
251
+ */
252
+ explicit operator bool() const { return Get(); }
253
+
254
+ /**
255
+ * Conversion to object of type T.
256
+ *
257
+ * Note: **Not thread-safe.**
258
+ *
259
+ * \returns the object.
260
+ */
261
+ operator T*() const { return Get(); }
262
+
263
+ /**
264
+ * Dereferences the stored object.
265
+ *
266
+ * Note: **Not thread-safe.**
267
+ */
268
+ T* operator->() const { return Get(); }
269
+ T& operator*() const { return *Get(); }
270
+
271
+ template <typename U, typename OtherWeaknessPolicy = WeaknessPolicy,
272
+ typename OtherLocationPolicy = LocationPolicy,
273
+ typename OtherCheckingPolicy = CheckingPolicy>
274
+ BasicCrossThreadPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
275
+ OtherCheckingPolicy>
276
+ To() const {
277
+ using OtherBasicCrossThreadPersistent =
278
+ BasicCrossThreadPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
279
+ OtherCheckingPolicy>;
280
+ PersistentRegionLock guard;
281
+ return OtherBasicCrossThreadPersistent(
282
+ typename OtherBasicCrossThreadPersistent::UnsafeCtorTag(),
283
+ static_cast<U*>(Get()));
284
+ }
285
+
286
+ template <typename U = T,
287
+ typename = typename std::enable_if<!BasicCrossThreadPersistent<
288
+ U, WeaknessPolicy>::IsStrongPersistent::value>::type>
289
+ BasicCrossThreadPersistent<U, internal::StrongCrossThreadPersistentPolicy>
290
+ Lock() const {
291
+ return BasicCrossThreadPersistent<
292
+ U, internal::StrongCrossThreadPersistentPolicy>(*this);
293
+ }
294
+
295
+ private:
296
+ static bool IsValid(const void* ptr) {
297
+ return ptr && ptr != kSentinelPointer;
298
+ }
299
+
300
+ static void Trace(Visitor* v, const void* ptr) {
301
+ const auto* handle = static_cast<const BasicCrossThreadPersistent*>(ptr);
302
+ v->TraceRoot(*handle, handle->Location());
303
+ }
304
+
305
+ void Assign(T* ptr) {
306
+ const void* old_value = GetValue();
307
+ if (IsValid(old_value)) {
308
+ PersistentRegionLock guard;
309
+ old_value = GetValue();
310
+ // The fast path check (IsValid()) does not acquire the lock. Reload
311
+ // the value to ensure the reference has not been cleared.
312
+ if (IsValid(old_value)) {
313
+ CrossThreadPersistentRegion& region =
314
+ this->GetPersistentRegion(old_value);
315
+ if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) {
316
+ SetValue(ptr);
317
+ this->CheckPointer(ptr);
318
+ return;
319
+ }
320
+ region.FreeNode(GetNode());
321
+ SetNode(nullptr);
322
+ } else {
323
+ CPPGC_DCHECK(!GetNode());
324
+ }
325
+ }
326
+ SetValue(ptr);
327
+ if (!IsValid(ptr)) return;
328
+ PersistentRegionLock guard;
329
+ SetNode(this->GetPersistentRegion(ptr).AllocateNode(this, &Trace));
330
+ this->CheckPointer(ptr);
331
+ }
332
+
333
+ void AssignUnsafe(T* ptr) {
334
+ PersistentRegionLock::AssertLocked();
335
+ const void* old_value = GetValue();
336
+ if (IsValid(old_value)) {
337
+ CrossThreadPersistentRegion& region =
338
+ this->GetPersistentRegion(old_value);
339
+ if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) {
340
+ SetValue(ptr);
341
+ this->CheckPointer(ptr);
342
+ return;
343
+ }
344
+ region.FreeNode(GetNode());
345
+ SetNode(nullptr);
346
+ }
347
+ SetValue(ptr);
348
+ if (!IsValid(ptr)) return;
349
+ SetNode(this->GetPersistentRegion(ptr).AllocateNode(this, &Trace));
350
+ this->CheckPointer(ptr);
351
+ }
352
+
353
+ void ClearFromGC() const {
354
+ if (IsValid(GetValueFromGC())) {
355
+ WeaknessPolicy::GetPersistentRegion(GetValueFromGC())
356
+ .FreeNode(GetNodeFromGC());
357
+ CrossThreadPersistentBase::ClearFromGC();
358
+ }
359
+ }
360
+
361
+ // See Get() for details.
362
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast")
363
+ T* GetFromGC() const {
364
+ return static_cast<T*>(const_cast<void*>(GetValueFromGC()));
365
+ }
366
+
367
+ friend class cppgc::Visitor;
368
+ };
369
+
370
+ template <typename T, typename LocationPolicy, typename CheckingPolicy>
371
+ struct IsWeak<
372
+ BasicCrossThreadPersistent<T, internal::WeakCrossThreadPersistentPolicy,
373
+ LocationPolicy, CheckingPolicy>>
374
+ : std::true_type {};
375
+
376
+ } // namespace internal
377
+
378
+ namespace subtle {
379
+
380
+ /**
381
+ * **DO NOT USE: Has known caveats, see below.**
382
+ *
383
+ * CrossThreadPersistent allows retaining objects from threads other than the
384
+ * thread the owning heap is operating on.
385
+ *
386
+ * Known caveats:
387
+ * - Does not protect the heap owning an object from terminating.
388
+ * - Reaching transitively through the graph is unsupported as objects may be
389
+ * moved concurrently on the thread owning the object.
390
+ */
391
+ template <typename T>
392
+ using CrossThreadPersistent = internal::BasicCrossThreadPersistent<
393
+ T, internal::StrongCrossThreadPersistentPolicy>;
394
+
395
+ /**
396
+ * **DO NOT USE: Has known caveats, see below.**
397
+ *
398
+ * CrossThreadPersistent allows weakly retaining objects from threads other than
399
+ * the thread the owning heap is operating on.
400
+ *
401
+ * Known caveats:
402
+ * - Does not protect the heap owning an object from terminating.
403
+ * - Reaching transitively through the graph is unsupported as objects may be
404
+ * moved concurrently on the thread owning the object.
405
+ */
406
+ template <typename T>
407
+ using WeakCrossThreadPersistent = internal::BasicCrossThreadPersistent<
408
+ T, internal::WeakCrossThreadPersistentPolicy>;
409
+
410
+ } // namespace subtle
411
+ } // namespace cppgc
412
+
413
+ #endif // INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
@@ -9,8 +9,11 @@
9
9
 
10
10
  namespace cppgc {
11
11
 
12
+ /**
13
+ * Index identifying a custom space.
14
+ */
12
15
  struct CustomSpaceIndex {
13
- CustomSpaceIndex(size_t value) : value(value) {} // NOLINT
16
+ constexpr CustomSpaceIndex(size_t value) : value(value) {} // NOLINT
14
17
  size_t value;
15
18
  };
16
19
 
@@ -22,11 +25,12 @@ class CustomSpaceBase {
22
25
  public:
23
26
  virtual ~CustomSpaceBase() = default;
24
27
  virtual CustomSpaceIndex GetCustomSpaceIndex() const = 0;
28
+ virtual bool IsCompactable() const = 0;
25
29
  };
26
30
 
27
31
  /**
28
32
  * Base class custom spaces should directly inherit from. The class inheriting
29
- * from CustomSpace must define kSpaceIndex as unique space index. These
33
+ * from `CustomSpace` must define `kSpaceIndex` as unique space index. These
30
34
  * indices need for form a sequence starting at 0.
31
35
  *
32
36
  * Example:
@@ -44,9 +48,18 @@ class CustomSpaceBase {
44
48
  template <typename ConcreteCustomSpace>
45
49
  class CustomSpace : public CustomSpaceBase {
46
50
  public:
51
+ /**
52
+ * Compaction is only supported on spaces that manually manage slots
53
+ * recording.
54
+ */
55
+ static constexpr bool kSupportsCompaction = false;
56
+
47
57
  CustomSpaceIndex GetCustomSpaceIndex() const final {
48
58
  return ConcreteCustomSpace::kSpaceIndex;
49
59
  }
60
+ bool IsCompactable() const final {
61
+ return ConcreteCustomSpace::kSupportsCompaction;
62
+ }
50
63
  };
51
64
 
52
65
  /**
@@ -57,6 +70,28 @@ struct SpaceTrait {
57
70
  using Space = void;
58
71
  };
59
72
 
73
+ namespace internal {
74
+
75
+ template <typename CustomSpace>
76
+ struct IsAllocatedOnCompactableSpaceImpl {
77
+ static constexpr bool value = CustomSpace::kSupportsCompaction;
78
+ };
79
+
80
+ template <>
81
+ struct IsAllocatedOnCompactableSpaceImpl<void> {
82
+ // Non-custom spaces are by default not compactable.
83
+ static constexpr bool value = false;
84
+ };
85
+
86
+ template <typename T>
87
+ struct IsAllocatedOnCompactableSpace {
88
+ public:
89
+ static constexpr bool value =
90
+ IsAllocatedOnCompactableSpaceImpl<typename SpaceTrait<T>::Space>::value;
91
+ };
92
+
93
+ } // namespace internal
94
+
60
95
  } // namespace cppgc
61
96
 
62
97
  #endif // INCLUDE_CPPGC_CUSTOM_SPACE_H_
@@ -6,69 +6,68 @@
6
6
  #define INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
7
7
 
8
8
  #include <memory>
9
- #include <thread> // NOLINT(build/c++11)
10
9
  #include <vector>
11
10
 
12
11
  #include "cppgc/platform.h"
12
+ #include "libplatform/libplatform.h"
13
13
  #include "v8config.h" // NOLINT(build/include_directory)
14
14
 
15
15
  namespace cppgc {
16
16
 
17
17
  /**
18
- * Default task runner implementation. Keep posted tasks in a list that can be
19
- * processed by calling RunSingleTask() or RunUntilIdle().
18
+ * Platform provided by cppgc. Uses V8's DefaultPlatform provided by
19
+ * libplatform internally. Exception: `GetForegroundTaskRunner()`, see below.
20
20
  */
21
- class V8_EXPORT DefaultTaskRunner final : public cppgc::TaskRunner {
21
+ class V8_EXPORT DefaultPlatform : public Platform {
22
22
  public:
23
- DefaultTaskRunner() = default;
24
-
25
- DefaultTaskRunner(const DefaultTaskRunner&) = delete;
26
- DefaultTaskRunner& operator=(const DefaultTaskRunner&) = delete;
27
-
28
- void PostTask(std::unique_ptr<cppgc::Task> task) override;
29
- void PostNonNestableTask(std::unique_ptr<cppgc::Task> task) override;
30
- void PostDelayedTask(std::unique_ptr<cppgc::Task> task, double) override;
31
- void PostNonNestableDelayedTask(std::unique_ptr<cppgc::Task> task,
32
- double) override;
33
-
34
- void PostIdleTask(std::unique_ptr<cppgc::IdleTask> task) override;
35
- bool IdleTasksEnabled() override { return true; }
36
-
37
- bool RunSingleTask();
38
- bool RunSingleIdleTask(double duration_in_seconds);
39
-
40
- void RunUntilIdle();
41
-
42
- private:
43
- std::vector<std::unique_ptr<cppgc::Task>> tasks_;
44
- std::vector<std::unique_ptr<cppgc::IdleTask>> idle_tasks_;
45
- };
46
-
47
- /**
48
- * Default platform implementation that uses std::thread for spawning job tasks.
49
- */
50
- class V8_EXPORT DefaultPlatform final : public Platform {
51
- public:
52
- DefaultPlatform();
53
- ~DefaultPlatform() noexcept override;
54
-
55
- cppgc::PageAllocator* GetPageAllocator() final;
56
-
57
- double MonotonicallyIncreasingTime() final;
58
-
59
- std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() final;
23
+ /**
24
+ * Use this method instead of 'cppgc::InitializeProcess' when using
25
+ * 'cppgc::DefaultPlatform'. 'cppgc::DefaultPlatform::InitializeProcess'
26
+ * will initialize cppgc and v8 if needed (for non-standalone builds).
27
+ *
28
+ * \param platform DefaultPlatform instance used to initialize cppgc/v8.
29
+ */
30
+ static void InitializeProcess(DefaultPlatform* platform);
31
+
32
+ using IdleTaskSupport = v8::platform::IdleTaskSupport;
33
+ explicit DefaultPlatform(
34
+ int thread_pool_size = 0,
35
+ IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
36
+ std::unique_ptr<TracingController> tracing_controller = {})
37
+ : v8_platform_(v8::platform::NewDefaultPlatform(
38
+ thread_pool_size, idle_task_support,
39
+ v8::platform::InProcessStackDumping::kDisabled,
40
+ std::move(tracing_controller))) {}
41
+
42
+ cppgc::PageAllocator* GetPageAllocator() override {
43
+ return v8_platform_->GetPageAllocator();
44
+ }
45
+
46
+ double MonotonicallyIncreasingTime() override {
47
+ return v8_platform_->MonotonicallyIncreasingTime();
48
+ }
49
+
50
+ std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() override {
51
+ // V8's default platform creates a new task runner when passed the
52
+ // `v8::Isolate` pointer the first time. For non-default platforms this will
53
+ // require getting the appropriate task runner.
54
+ return v8_platform_->GetForegroundTaskRunner(kNoIsolate);
55
+ }
60
56
 
61
57
  std::unique_ptr<cppgc::JobHandle> PostJob(
62
58
  cppgc::TaskPriority priority,
63
- std::unique_ptr<cppgc::JobTask> job_task) final;
59
+ std::unique_ptr<cppgc::JobTask> job_task) override {
60
+ return v8_platform_->PostJob(priority, std::move(job_task));
61
+ }
62
+
63
+ TracingController* GetTracingController() override {
64
+ return v8_platform_->GetTracingController();
65
+ }
64
66
 
65
- void WaitAllForegroundTasks();
66
- void WaitAllBackgroundTasks();
67
+ protected:
68
+ static constexpr v8::Isolate* kNoIsolate = nullptr;
67
69
 
68
- private:
69
- std::unique_ptr<PageAllocator> page_allocator_;
70
- std::shared_ptr<DefaultTaskRunner> foreground_task_runner_;
71
- std::vector<std::shared_ptr<std::thread>> job_threads_;
70
+ std::unique_ptr<v8::Platform> v8_platform_;
72
71
  };
73
72
 
74
73
  } // namespace cppgc
@@ -0,0 +1,30 @@
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_EPHEMERON_PAIR_H_
6
+ #define INCLUDE_CPPGC_EPHEMERON_PAIR_H_
7
+
8
+ #include "cppgc/liveness-broker.h"
9
+ #include "cppgc/member.h"
10
+
11
+ namespace cppgc {
12
+
13
+ /**
14
+ * An ephemeron pair is used to conditionally retain an object.
15
+ * The `value` will be kept alive only if the `key` is alive.
16
+ */
17
+ template <typename K, typename V>
18
+ struct EphemeronPair {
19
+ EphemeronPair(K* k, V* v) : key(k), value(v) {}
20
+ WeakMember<K> key;
21
+ Member<V> value;
22
+
23
+ void ClearValueIfKeyIsDead(const LivenessBroker& broker) {
24
+ if (!broker.IsHeapObjectAlive(key)) value = nullptr;
25
+ }
26
+ };
27
+
28
+ } // namespace cppgc
29
+
30
+ #endif // INCLUDE_CPPGC_EPHEMERON_PAIR_H_