libv8-node 15.14.0.1-x86_64-linux-musl → 16.10.0.0-x86_64-linux-musl

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 +1 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/include/cppgc/allocation.h +104 -45
  6. data/vendor/v8/include/cppgc/common.h +9 -6
  7. data/vendor/v8/include/cppgc/cross-thread-persistent.h +384 -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 +236 -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 +57 -1
  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 +353 -35
  26. data/vendor/v8/include/cppgc/liveness-broker.h +7 -1
  27. data/vendor/v8/include/cppgc/macros.h +2 -0
  28. data/vendor/v8/include/cppgc/member.h +85 -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 +33 -9
  32. data/vendor/v8/include/cppgc/platform.h +48 -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 +187 -23
  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 +562 -159
  45. data/vendor/v8/include/v8-inspector.h +23 -2
  46. data/vendor/v8/include/v8-internal.h +99 -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 +1192 -642
  54. data/vendor/v8/include/v8config.h +40 -9
  55. data/vendor/v8/{out.gn → x86_64-linux-musl}/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +17 -5
  57. data/vendor/v8/include/cppgc/internal/process-heap.h +0 -34
@@ -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_
@@ -0,0 +1,82 @@
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_EXPLICIT_MANAGEMENT_H_
6
+ #define INCLUDE_CPPGC_EXPLICIT_MANAGEMENT_H_
7
+
8
+ #include <cstddef>
9
+
10
+ #include "cppgc/allocation.h"
11
+ #include "cppgc/internal/logging.h"
12
+ #include "cppgc/type-traits.h"
13
+
14
+ namespace cppgc {
15
+
16
+ class HeapHandle;
17
+
18
+ namespace internal {
19
+
20
+ V8_EXPORT void FreeUnreferencedObject(HeapHandle&, void*);
21
+ V8_EXPORT bool Resize(void*, size_t);
22
+
23
+ } // namespace internal
24
+
25
+ namespace subtle {
26
+
27
+ /**
28
+ * Informs the garbage collector that `object` can be immediately reclaimed. The
29
+ * destructor may not be invoked immediately but only on next garbage
30
+ * collection.
31
+ *
32
+ * It is up to the embedder to guarantee that no other object holds a reference
33
+ * to `object` after calling `FreeUnreferencedObject()`. In case such a
34
+ * reference exists, it's use results in a use-after-free.
35
+ *
36
+ * To aid in using the API, `FreeUnreferencedObject()` may be called from
37
+ * destructors on objects that would be reclaimed in the same garbage collection
38
+ * cycle.
39
+ *
40
+ * \param heap_handle The corresponding heap.
41
+ * \param object Reference to an object that is of type `GarbageCollected` and
42
+ * should be immediately reclaimed.
43
+ */
44
+ template <typename T>
45
+ void FreeUnreferencedObject(HeapHandle& heap_handle, T& object) {
46
+ static_assert(IsGarbageCollectedTypeV<T>,
47
+ "Object must be of type GarbageCollected.");
48
+ internal::FreeUnreferencedObject(heap_handle, &object);
49
+ }
50
+
51
+ /**
52
+ * Tries to resize `object` of type `T` with additional bytes on top of
53
+ * sizeof(T). Resizing is only useful with trailing inlined storage, see e.g.
54
+ * `MakeGarbageCollected(AllocationHandle&, AdditionalBytes)`.
55
+ *
56
+ * `Resize()` performs growing or shrinking as needed and may skip the operation
57
+ * for internal reasons, see return value.
58
+ *
59
+ * It is up to the embedder to guarantee that in case of shrinking a larger
60
+ * object down, the reclaimed area is not used anymore. Any subsequent use
61
+ * results in a use-after-free.
62
+ *
63
+ * The `object` must be live when calling `Resize()`.
64
+ *
65
+ * \param object Reference to an object that is of type `GarbageCollected` and
66
+ * should be resized.
67
+ * \param additional_bytes Bytes in addition to sizeof(T) that the object should
68
+ * provide.
69
+ * \returns true when the operation was successful and the result can be relied
70
+ * on, and false otherwise.
71
+ */
72
+ template <typename T>
73
+ bool Resize(T& object, AdditionalBytes additional_bytes) {
74
+ static_assert(IsGarbageCollectedTypeV<T>,
75
+ "Object must be of type GarbageCollected.");
76
+ return internal::Resize(&object, sizeof(T) + additional_bytes.value);
77
+ }
78
+
79
+ } // namespace subtle
80
+ } // namespace cppgc
81
+
82
+ #endif // INCLUDE_CPPGC_EXPLICIT_MANAGEMENT_H_
@@ -39,8 +39,8 @@ class GarbageCollectedBase {
39
39
  } // namespace internal
40
40
 
41
41
  /**
42
- * Base class for managed objects. Only descendent types of GarbageCollected
43
- * can be constructed using MakeGarbageCollected. Must be inherited from as
42
+ * Base class for managed objects. Only descendent types of `GarbageCollected`
43
+ * can be constructed using `MakeGarbageCollected()`. Must be inherited from as
44
44
  * left-most base class.
45
45
  *
46
46
  * Types inheriting from GarbageCollected must provide a method of
@@ -73,10 +73,11 @@ class GarbageCollectedBase {
73
73
  * };
74
74
  * \endcode
75
75
  */
76
- template <typename>
76
+ template <typename T>
77
77
  class GarbageCollected : public internal::GarbageCollectedBase {
78
78
  public:
79
79
  using IsGarbageCollectedTypeMarker = void;
80
+ using ParentMostGarbageCollectedType = T;
80
81
 
81
82
  protected:
82
83
  GarbageCollected() = default;
@@ -0,0 +1,236 @@
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_HEAP_CONSISTENCY_H_
6
+ #define INCLUDE_CPPGC_HEAP_CONSISTENCY_H_
7
+
8
+ #include <cstddef>
9
+
10
+ #include "cppgc/internal/write-barrier.h"
11
+ #include "cppgc/macros.h"
12
+ #include "cppgc/trace-trait.h"
13
+ #include "v8config.h" // NOLINT(build/include_directory)
14
+
15
+ namespace cppgc {
16
+
17
+ class HeapHandle;
18
+
19
+ namespace subtle {
20
+
21
+ /**
22
+ * **DO NOT USE: Use the appropriate managed types.**
23
+ *
24
+ * Consistency helpers that aid in maintaining a consistent internal state of
25
+ * the garbage collector.
26
+ */
27
+ class HeapConsistency final {
28
+ public:
29
+ using WriteBarrierParams = internal::WriteBarrier::Params;
30
+ using WriteBarrierType = internal::WriteBarrier::Type;
31
+
32
+ /**
33
+ * Gets the required write barrier type for a specific write.
34
+ *
35
+ * \param slot Slot containing the pointer to the object. The slot itself
36
+ * must reside in an object that has been allocated using
37
+ * `MakeGarbageCollected()`.
38
+ * \param value The pointer to the object. May be an interior pointer to an
39
+ * interface of the actual object.
40
+ * \param params Parameters that may be used for actual write barrier calls.
41
+ * Only filled if return value indicates that a write barrier is needed. The
42
+ * contents of the `params` are an implementation detail.
43
+ * \returns whether a write barrier is needed and which barrier to invoke.
44
+ */
45
+ static V8_INLINE WriteBarrierType GetWriteBarrierType(
46
+ const void* slot, const void* value, WriteBarrierParams& params) {
47
+ return internal::WriteBarrier::GetWriteBarrierType(slot, value, params);
48
+ }
49
+
50
+ /**
51
+ * Gets the required write barrier type for a specific write.
52
+ *
53
+ * \param slot Slot to some part of an object. The object must not necessarily
54
+ have been allocated using `MakeGarbageCollected()` but can also live
55
+ off-heap or on stack.
56
+ * \param params Parameters that may be used for actual write barrier calls.
57
+ * Only filled if return value indicates that a write barrier is needed. The
58
+ * contents of the `params` are an implementation detail.
59
+ * \param callback Callback returning the corresponding heap handle. The
60
+ * callback is only invoked if the heap cannot otherwise be figured out. The
61
+ * callback must not allocate.
62
+ * \returns whether a write barrier is needed and which barrier to invoke.
63
+ */
64
+ template <typename HeapHandleCallback>
65
+ static V8_INLINE WriteBarrierType
66
+ GetWriteBarrierType(const void* slot, WriteBarrierParams& params,
67
+ HeapHandleCallback callback) {
68
+ return internal::WriteBarrier::GetWriteBarrierType(slot, params, callback);
69
+ }
70
+
71
+ /**
72
+ * Conservative Dijkstra-style write barrier that processes an object if it
73
+ * has not yet been processed.
74
+ *
75
+ * \param params The parameters retrieved from `GetWriteBarrierType()`.
76
+ * \param object The pointer to the object. May be an interior pointer to a
77
+ * an interface of the actual object.
78
+ */
79
+ static V8_INLINE void DijkstraWriteBarrier(const WriteBarrierParams& params,
80
+ const void* object) {
81
+ internal::WriteBarrier::DijkstraMarkingBarrier(params, object);
82
+ }
83
+
84
+ /**
85
+ * Conservative Dijkstra-style write barrier that processes a range of
86
+ * elements if they have not yet been processed.
87
+ *
88
+ * \param params The parameters retrieved from `GetWriteBarrierType()`.
89
+ * \param first_element Pointer to the first element that should be processed.
90
+ * The slot itself must reside in an object that has been allocated using
91
+ * `MakeGarbageCollected()`.
92
+ * \param element_size Size of the element in bytes.
93
+ * \param number_of_elements Number of elements that should be processed,
94
+ * starting with `first_element`.
95
+ * \param trace_callback The trace callback that should be invoked for each
96
+ * element if necessary.
97
+ */
98
+ static V8_INLINE void DijkstraWriteBarrierRange(
99
+ const WriteBarrierParams& params, const void* first_element,
100
+ size_t element_size, size_t number_of_elements,
101
+ TraceCallback trace_callback) {
102
+ internal::WriteBarrier::DijkstraMarkingBarrierRange(
103
+ params, first_element, element_size, number_of_elements,
104
+ trace_callback);
105
+ }
106
+
107
+ /**
108
+ * Steele-style write barrier that re-processes an object if it has already
109
+ * been processed.
110
+ *
111
+ * \param params The parameters retrieved from `GetWriteBarrierType()`.
112
+ * \param object The pointer to the object which must point to an object that
113
+ * has been allocated using `MakeGarbageCollected()`. Interior pointers are
114
+ * not supported.
115
+ */
116
+ static V8_INLINE void SteeleWriteBarrier(const WriteBarrierParams& params,
117
+ const void* object) {
118
+ internal::WriteBarrier::SteeleMarkingBarrier(params, object);
119
+ }
120
+
121
+ /**
122
+ * Generational barrier for maintaining consistency when running with multiple
123
+ * generations.
124
+ *
125
+ * \param params The parameters retrieved from `GetWriteBarrierType()`.
126
+ * \param slot Slot containing the pointer to the object. The slot itself
127
+ * must reside in an object that has been allocated using
128
+ * `MakeGarbageCollected()`.
129
+ */
130
+ static V8_INLINE void GenerationalBarrier(const WriteBarrierParams& params,
131
+ const void* slot) {
132
+ internal::WriteBarrier::GenerationalBarrier(params, slot);
133
+ }
134
+
135
+ private:
136
+ HeapConsistency() = delete;
137
+ };
138
+
139
+ /**
140
+ * Disallows garbage collection finalizations. Any garbage collection triggers
141
+ * result in a crash when in this scope.
142
+ *
143
+ * Note that the garbage collector already covers paths that can lead to garbage
144
+ * collections, so user code does not require checking
145
+ * `IsGarbageCollectionAllowed()` before allocations.
146
+ */
147
+ class V8_EXPORT V8_NODISCARD DisallowGarbageCollectionScope final {
148
+ CPPGC_STACK_ALLOCATED();
149
+
150
+ public:
151
+ /**
152
+ * \returns whether garbage collections are currently allowed.
153
+ */
154
+ static bool IsGarbageCollectionAllowed(HeapHandle& heap_handle);
155
+
156
+ /**
157
+ * Enters a disallow garbage collection scope. Must be paired with `Leave()`.
158
+ * Prefer a scope instance of `DisallowGarbageCollectionScope`.
159
+ *
160
+ * \param heap_handle The corresponding heap.
161
+ */
162
+ static void Enter(HeapHandle& heap_handle);
163
+
164
+ /**
165
+ * Leaves a disallow garbage collection scope. Must be paired with `Enter()`.
166
+ * Prefer a scope instance of `DisallowGarbageCollectionScope`.
167
+ *
168
+ * \param heap_handle The corresponding heap.
169
+ */
170
+ static void Leave(HeapHandle& heap_handle);
171
+
172
+ /**
173
+ * Constructs a scoped object that automatically enters and leaves a disallow
174
+ * garbage collection scope based on its lifetime.
175
+ *
176
+ * \param heap_handle The corresponding heap.
177
+ */
178
+ explicit DisallowGarbageCollectionScope(HeapHandle& heap_handle);
179
+ ~DisallowGarbageCollectionScope();
180
+
181
+ DisallowGarbageCollectionScope(const DisallowGarbageCollectionScope&) =
182
+ delete;
183
+ DisallowGarbageCollectionScope& operator=(
184
+ const DisallowGarbageCollectionScope&) = delete;
185
+
186
+ private:
187
+ HeapHandle& heap_handle_;
188
+ };
189
+
190
+ /**
191
+ * Avoids invoking garbage collection finalizations. Already running garbage
192
+ * collection phase are unaffected by this scope.
193
+ *
194
+ * Should only be used temporarily as the scope has an impact on memory usage
195
+ * and follow up garbage collections.
196
+ */
197
+ class V8_EXPORT V8_NODISCARD NoGarbageCollectionScope final {
198
+ CPPGC_STACK_ALLOCATED();
199
+
200
+ public:
201
+ /**
202
+ * Enters a no garbage collection scope. Must be paired with `Leave()`. Prefer
203
+ * a scope instance of `NoGarbageCollectionScope`.
204
+ *
205
+ * \param heap_handle The corresponding heap.
206
+ */
207
+ static void Enter(HeapHandle& heap_handle);
208
+
209
+ /**
210
+ * Leaves a no garbage collection scope. Must be paired with `Enter()`. Prefer
211
+ * a scope instance of `NoGarbageCollectionScope`.
212
+ *
213
+ * \param heap_handle The corresponding heap.
214
+ */
215
+ static void Leave(HeapHandle& heap_handle);
216
+
217
+ /**
218
+ * Constructs a scoped object that automatically enters and leaves a no
219
+ * garbage collection scope based on its lifetime.
220
+ *
221
+ * \param heap_handle The corresponding heap.
222
+ */
223
+ explicit NoGarbageCollectionScope(HeapHandle& heap_handle);
224
+ ~NoGarbageCollectionScope();
225
+
226
+ NoGarbageCollectionScope(const NoGarbageCollectionScope&) = delete;
227
+ NoGarbageCollectionScope& operator=(const NoGarbageCollectionScope&) = delete;
228
+
229
+ private:
230
+ HeapHandle& heap_handle_;
231
+ };
232
+
233
+ } // namespace subtle
234
+ } // namespace cppgc
235
+
236
+ #endif // INCLUDE_CPPGC_HEAP_CONSISTENCY_H_
@@ -0,0 +1,70 @@
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_HEAP_STATE_H_
6
+ #define INCLUDE_CPPGC_HEAP_STATE_H_
7
+
8
+ #include "v8config.h" // NOLINT(build/include_directory)
9
+
10
+ namespace cppgc {
11
+
12
+ class HeapHandle;
13
+
14
+ namespace subtle {
15
+
16
+ /**
17
+ * Helpers to peek into heap-internal state.
18
+ */
19
+ class V8_EXPORT HeapState final {
20
+ public:
21
+ /**
22
+ * Returns whether the garbage collector is marking. This API is experimental
23
+ * and is expected to be removed in future.
24
+ *
25
+ * \param heap_handle The corresponding heap.
26
+ * \returns true if the garbage collector is currently marking, and false
27
+ * otherwise.
28
+ */
29
+ static bool IsMarking(const HeapHandle& heap_handle);
30
+
31
+ /*
32
+ * Returns whether the garbage collector is sweeping. This API is experimental
33
+ * and is expected to be removed in future.
34
+ *
35
+ * \param heap_handle The corresponding heap.
36
+ * \returns true if the garbage collector is currently sweeping, and false
37
+ * otherwise.
38
+ */
39
+ static bool IsSweeping(const HeapHandle& heap_handle);
40
+
41
+ /**
42
+ * Returns whether the garbage collector is in the atomic pause, i.e., the
43
+ * mutator is stopped from running. This API is experimental and is expected
44
+ * to be removed in future.
45
+ *
46
+ * \param heap_handle The corresponding heap.
47
+ * \returns true if the garbage collector is currently in the atomic pause,
48
+ * and false otherwise.
49
+ */
50
+ static bool IsInAtomicPause(const HeapHandle& heap_handle);
51
+
52
+ /**
53
+ * Returns whether the last garbage collection was finalized conservatively
54
+ * (i.e., with a non-empty stack). This API is experimental and is expected to
55
+ * be removed in future.
56
+ *
57
+ * \param heap_handle The corresponding heap.
58
+ * \returns true if the last garbage collection was finalized conservatively,
59
+ * and false otherwise.
60
+ */
61
+ static bool PreviousGCWasConservative(const HeapHandle& heap_handle);
62
+
63
+ private:
64
+ HeapState() = delete;
65
+ };
66
+
67
+ } // namespace subtle
68
+ } // namespace cppgc
69
+
70
+ #endif // INCLUDE_CPPGC_HEAP_STATE_H_