libv8-node 16.10.0.0-x86_64-darwin

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 (68) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +1 -0
  3. data/ext/libv8-node/location.rb +76 -0
  4. data/ext/libv8-node/paths.rb +34 -0
  5. data/lib/libv8/node/version.rb +7 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8-node.rb +1 -0
  8. data/vendor/v8/include/cppgc/allocation.h +232 -0
  9. data/vendor/v8/include/cppgc/common.h +29 -0
  10. data/vendor/v8/include/cppgc/cross-thread-persistent.h +384 -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/explicit-management.h +82 -0
  15. data/vendor/v8/include/cppgc/garbage-collected.h +117 -0
  16. data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
  17. data/vendor/v8/include/cppgc/heap-state.h +70 -0
  18. data/vendor/v8/include/cppgc/heap-statistics.h +120 -0
  19. data/vendor/v8/include/cppgc/heap.h +201 -0
  20. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  21. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  22. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +68 -0
  23. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  24. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  25. data/vendor/v8/include/cppgc/internal/gc-info.h +76 -0
  26. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  27. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  28. data/vendor/v8/include/cppgc/internal/persistent-node.h +172 -0
  29. data/vendor/v8/include/cppgc/internal/pointer-policies.h +175 -0
  30. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  31. data/vendor/v8/include/cppgc/internal/write-barrier.h +396 -0
  32. data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
  33. data/vendor/v8/include/cppgc/macros.h +26 -0
  34. data/vendor/v8/include/cppgc/member.h +286 -0
  35. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  36. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  37. data/vendor/v8/include/cppgc/persistent.h +365 -0
  38. data/vendor/v8/include/cppgc/platform.h +153 -0
  39. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  40. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  41. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  42. data/vendor/v8/include/cppgc/source-location.h +92 -0
  43. data/vendor/v8/include/cppgc/testing.h +99 -0
  44. data/vendor/v8/include/cppgc/trace-trait.h +116 -0
  45. data/vendor/v8/include/cppgc/type-traits.h +247 -0
  46. data/vendor/v8/include/cppgc/visitor.h +377 -0
  47. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  48. data/vendor/v8/include/libplatform/libplatform.h +117 -0
  49. data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
  50. data/vendor/v8/include/v8-cppgc.h +325 -0
  51. data/vendor/v8/include/v8-fast-api-calls.h +791 -0
  52. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  53. data/vendor/v8/include/v8-inspector.h +348 -0
  54. data/vendor/v8/include/v8-internal.h +499 -0
  55. data/vendor/v8/include/v8-metrics.h +202 -0
  56. data/vendor/v8/include/v8-platform.h +709 -0
  57. data/vendor/v8/include/v8-profiler.h +1123 -0
  58. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  59. data/vendor/v8/include/v8-util.h +652 -0
  60. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  61. data/vendor/v8/include/v8-version-string.h +38 -0
  62. data/vendor/v8/include/v8-version.h +20 -0
  63. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  64. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  65. data/vendor/v8/include/v8.h +12648 -0
  66. data/vendor/v8/include/v8config.h +515 -0
  67. data/vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a +0 -0
  68. metadata +138 -0
@@ -0,0 +1,201 @@
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_H_
6
+ #define INCLUDE_CPPGC_HEAP_H_
7
+
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+ #include <memory>
11
+ #include <vector>
12
+
13
+ #include "cppgc/common.h"
14
+ #include "cppgc/custom-space.h"
15
+ #include "cppgc/platform.h"
16
+ #include "v8config.h" // NOLINT(build/include_directory)
17
+
18
+ /**
19
+ * cppgc - A C++ garbage collection library.
20
+ */
21
+ namespace cppgc {
22
+
23
+ class AllocationHandle;
24
+
25
+ /**
26
+ * Implementation details of cppgc. Those details are considered internal and
27
+ * may change at any point in time without notice. Users should never rely on
28
+ * the contents of this namespace.
29
+ */
30
+ namespace internal {
31
+ class Heap;
32
+ } // namespace internal
33
+
34
+ /**
35
+ * Used for additional heap APIs.
36
+ */
37
+ class HeapHandle;
38
+
39
+ class V8_EXPORT Heap {
40
+ public:
41
+ /**
42
+ * Specifies the stack state the embedder is in.
43
+ */
44
+ using StackState = EmbedderStackState;
45
+
46
+ /**
47
+ * Specifies whether conservative stack scanning is supported.
48
+ */
49
+ enum class StackSupport : uint8_t {
50
+ /**
51
+ * Conservative stack scan is supported.
52
+ */
53
+ kSupportsConservativeStackScan,
54
+ /**
55
+ * Conservative stack scan is not supported. Embedders may use this option
56
+ * when using custom infrastructure that is unsupported by the library.
57
+ */
58
+ kNoConservativeStackScan,
59
+ };
60
+
61
+ /**
62
+ * Specifies supported marking types
63
+ */
64
+ enum class MarkingType : uint8_t {
65
+ /**
66
+ * Atomic stop-the-world marking. This option does not require any write
67
+ * barriers but is the most intrusive in terms of jank.
68
+ */
69
+ kAtomic,
70
+ /**
71
+ * Incremental marking, i.e. interleave marking is the rest of the
72
+ * application on the same thread.
73
+ */
74
+ kIncremental,
75
+ /**
76
+ * Incremental and concurrent marking.
77
+ */
78
+ kIncrementalAndConcurrent
79
+ };
80
+
81
+ /**
82
+ * Specifies supported sweeping types
83
+ */
84
+ enum class SweepingType : uint8_t {
85
+ /**
86
+ * Atomic stop-the-world sweeping. All of sweeping is performed at once.
87
+ */
88
+ kAtomic,
89
+ /**
90
+ * Incremental and concurrent sweeping. Sweeping is split and interleaved
91
+ * with the rest of the application.
92
+ */
93
+ kIncrementalAndConcurrent
94
+ };
95
+
96
+ /**
97
+ * Constraints for a Heap setup.
98
+ */
99
+ struct ResourceConstraints {
100
+ /**
101
+ * Allows the heap to grow to some initial size in bytes before triggering
102
+ * garbage collections. This is useful when it is known that applications
103
+ * need a certain minimum heap to run to avoid repeatedly invoking the
104
+ * garbage collector when growing the heap.
105
+ */
106
+ size_t initial_heap_size_bytes = 0;
107
+ };
108
+
109
+ /**
110
+ * Options specifying Heap properties (e.g. custom spaces) when initializing a
111
+ * heap through `Heap::Create()`.
112
+ */
113
+ struct HeapOptions {
114
+ /**
115
+ * Creates reasonable defaults for instantiating a Heap.
116
+ *
117
+ * \returns the HeapOptions that can be passed to `Heap::Create()`.
118
+ */
119
+ static HeapOptions Default() { return {}; }
120
+
121
+ /**
122
+ * Custom spaces added to heap are required to have indices forming a
123
+ * numbered sequence starting at 0, i.e., their `kSpaceIndex` must
124
+ * correspond to the index they reside in the vector.
125
+ */
126
+ std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
127
+
128
+ /**
129
+ * Specifies whether conservative stack scan is supported. When conservative
130
+ * stack scan is not supported, the collector may try to invoke
131
+ * garbage collections using non-nestable task, which are guaranteed to have
132
+ * no interesting stack, through the provided Platform. If such tasks are
133
+ * not supported by the Platform, the embedder must take care of invoking
134
+ * the GC through `ForceGarbageCollectionSlow()`.
135
+ */
136
+ StackSupport stack_support = StackSupport::kSupportsConservativeStackScan;
137
+
138
+ /**
139
+ * Specifies which types of marking are supported by the heap.
140
+ */
141
+ MarkingType marking_support = MarkingType::kIncrementalAndConcurrent;
142
+
143
+ /**
144
+ * Specifies which types of sweeping are supported by the heap.
145
+ */
146
+ SweepingType sweeping_support = SweepingType::kIncrementalAndConcurrent;
147
+
148
+ /**
149
+ * Resource constraints specifying various properties that the internal
150
+ * GC scheduler follows.
151
+ */
152
+ ResourceConstraints resource_constraints;
153
+ };
154
+
155
+ /**
156
+ * Creates a new heap that can be used for object allocation.
157
+ *
158
+ * \param platform implemented and provided by the embedder.
159
+ * \param options HeapOptions specifying various properties for the Heap.
160
+ * \returns a new Heap instance.
161
+ */
162
+ static std::unique_ptr<Heap> Create(
163
+ std::shared_ptr<Platform> platform,
164
+ HeapOptions options = HeapOptions::Default());
165
+
166
+ virtual ~Heap() = default;
167
+
168
+ /**
169
+ * Forces garbage collection.
170
+ *
171
+ * \param source String specifying the source (or caller) triggering a
172
+ * forced garbage collection.
173
+ * \param reason String specifying the reason for the forced garbage
174
+ * collection.
175
+ * \param stack_state The embedder stack state, see StackState.
176
+ */
177
+ void ForceGarbageCollectionSlow(
178
+ const char* source, const char* reason,
179
+ StackState stack_state = StackState::kMayContainHeapPointers);
180
+
181
+ /**
182
+ * \returns the opaque handle for allocating objects using
183
+ * `MakeGarbageCollected()`.
184
+ */
185
+ AllocationHandle& GetAllocationHandle();
186
+
187
+ /**
188
+ * \returns the opaque heap handle which may be used to refer to this heap in
189
+ * other APIs. Valid as long as the underlying `Heap` is alive.
190
+ */
191
+ HeapHandle& GetHeapHandle();
192
+
193
+ private:
194
+ Heap() = default;
195
+
196
+ friend class internal::Heap;
197
+ };
198
+
199
+ } // namespace cppgc
200
+
201
+ #endif // INCLUDE_CPPGC_HEAP_H_
@@ -0,0 +1,47 @@
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_INTERNAL_API_CONSTANTS_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
7
+
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+ namespace internal {
15
+
16
+ // Embedders should not rely on this code!
17
+
18
+ // Internal constants to avoid exposing internal types on the API surface.
19
+ namespace api_constants {
20
+
21
+ constexpr size_t kKB = 1024;
22
+ constexpr size_t kMB = kKB * 1024;
23
+ constexpr size_t kGB = kMB * 1024;
24
+
25
+ // Offset of the uint16_t bitfield from the payload contaning the
26
+ // in-construction bit. This is subtracted from the payload pointer to get
27
+ // to the right bitfield.
28
+ static constexpr size_t kFullyConstructedBitFieldOffsetFromPayload =
29
+ 2 * sizeof(uint16_t);
30
+ // Mask for in-construction bit.
31
+ static constexpr uint16_t kFullyConstructedBitMask = uint16_t{1};
32
+
33
+ static constexpr size_t kPageSize = size_t{1} << 17;
34
+
35
+ static constexpr size_t kLargeObjectSizeThreshold = kPageSize / 2;
36
+
37
+ #if defined(CPPGC_CAGED_HEAP)
38
+ constexpr size_t kCagedHeapReservationSize = static_cast<size_t>(4) * kGB;
39
+ constexpr size_t kCagedHeapReservationAlignment = kCagedHeapReservationSize;
40
+ #endif
41
+
42
+ } // namespace api_constants
43
+
44
+ } // namespace internal
45
+ } // namespace cppgc
46
+
47
+ #endif // INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
@@ -0,0 +1,48 @@
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_INTERNAL_ATOMIC_ENTRY_FLAG_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_ATOMIC_ENTRY_FLAG_H_
7
+
8
+ #include <atomic>
9
+
10
+ namespace cppgc {
11
+ namespace internal {
12
+
13
+ // A flag which provides a fast check whether a scope may be entered on the
14
+ // current thread, without needing to access thread-local storage or mutex. Can
15
+ // have false positives (i.e., spuriously report that it might be entered), so
16
+ // it is expected that this will be used in tandem with a precise check that the
17
+ // scope is in fact entered on that thread.
18
+ //
19
+ // Example:
20
+ // g_frobnicating_flag.MightBeEntered() &&
21
+ // ThreadLocalFrobnicator().IsFrobnicating()
22
+ //
23
+ // Relaxed atomic operations are sufficient, since:
24
+ // - all accesses remain atomic
25
+ // - each thread must observe its own operations in order
26
+ // - no thread ever exits the flag more times than it enters (if used correctly)
27
+ // And so if a thread observes zero, it must be because it has observed an equal
28
+ // number of exits as entries.
29
+ class AtomicEntryFlag final {
30
+ public:
31
+ void Enter() { entries_.fetch_add(1, std::memory_order_relaxed); }
32
+ void Exit() { entries_.fetch_sub(1, std::memory_order_relaxed); }
33
+
34
+ // Returns false only if the current thread is not between a call to Enter
35
+ // and a call to Exit. Returns true if this thread or another thread may
36
+ // currently be in the scope guarded by this flag.
37
+ bool MightBeEntered() const {
38
+ return entries_.load(std::memory_order_relaxed) != 0;
39
+ }
40
+
41
+ private:
42
+ std::atomic_int entries_{0};
43
+ };
44
+
45
+ } // namespace internal
46
+ } // namespace cppgc
47
+
48
+ #endif // INCLUDE_CPPGC_INTERNAL_ATOMIC_ENTRY_FLAG_H_
@@ -0,0 +1,68 @@
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_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
7
+
8
+ #include <array>
9
+
10
+ #include "cppgc/internal/api-constants.h"
11
+ #include "cppgc/internal/logging.h"
12
+ #include "cppgc/platform.h"
13
+ #include "v8config.h" // NOLINT(build/include_directory)
14
+
15
+ namespace cppgc {
16
+ namespace internal {
17
+
18
+ class HeapBase;
19
+
20
+ #if defined(CPPGC_YOUNG_GENERATION)
21
+
22
+ // AgeTable contains entries that correspond to 4KB memory regions. Each entry
23
+ // can be in one of three states: kOld, kYoung or kUnknown.
24
+ class AgeTable final {
25
+ static constexpr size_t kGranularityBits = 12; // 4KiB per byte.
26
+
27
+ public:
28
+ enum class Age : uint8_t { kOld, kYoung, kUnknown };
29
+
30
+ static constexpr size_t kEntrySizeInBytes = 1 << kGranularityBits;
31
+
32
+ Age& operator[](uintptr_t offset) { return table_[entry(offset)]; }
33
+ Age operator[](uintptr_t offset) const { return table_[entry(offset)]; }
34
+
35
+ void Reset(PageAllocator* allocator);
36
+
37
+ private:
38
+ static constexpr size_t kAgeTableSize =
39
+ api_constants::kCagedHeapReservationSize >> kGranularityBits;
40
+
41
+ size_t entry(uintptr_t offset) const {
42
+ const size_t entry = offset >> kGranularityBits;
43
+ CPPGC_DCHECK(table_.size() > entry);
44
+ return entry;
45
+ }
46
+
47
+ std::array<Age, kAgeTableSize> table_;
48
+ };
49
+
50
+ static_assert(sizeof(AgeTable) == 1 * api_constants::kMB,
51
+ "Size of AgeTable is 1MB");
52
+
53
+ #endif // CPPGC_YOUNG_GENERATION
54
+
55
+ struct CagedHeapLocalData final {
56
+ explicit CagedHeapLocalData(HeapBase* heap_base) : heap_base(heap_base) {}
57
+
58
+ bool is_incremental_marking_in_progress = false;
59
+ HeapBase* heap_base = nullptr;
60
+ #if defined(CPPGC_YOUNG_GENERATION)
61
+ AgeTable age_table;
62
+ #endif
63
+ };
64
+
65
+ } // namespace internal
66
+ } // namespace cppgc
67
+
68
+ #endif // INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
@@ -0,0 +1,38 @@
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_INTERNAL_COMPILER_SPECIFIC_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_COMPILER_SPECIFIC_H_
7
+
8
+ namespace cppgc {
9
+
10
+ #if defined(__has_attribute)
11
+ #define CPPGC_HAS_ATTRIBUTE(FEATURE) __has_attribute(FEATURE)
12
+ #else
13
+ #define CPPGC_HAS_ATTRIBUTE(FEATURE) 0
14
+ #endif
15
+
16
+ #if defined(__has_cpp_attribute)
17
+ #define CPPGC_HAS_CPP_ATTRIBUTE(FEATURE) __has_cpp_attribute(FEATURE)
18
+ #else
19
+ #define CPPGC_HAS_CPP_ATTRIBUTE(FEATURE) 0
20
+ #endif
21
+
22
+ // [[no_unique_address]] comes in C++20 but supported in clang with -std >=
23
+ // c++11.
24
+ #if CPPGC_HAS_CPP_ATTRIBUTE(no_unique_address)
25
+ #define CPPGC_NO_UNIQUE_ADDRESS [[no_unique_address]]
26
+ #else
27
+ #define CPPGC_NO_UNIQUE_ADDRESS
28
+ #endif
29
+
30
+ #if CPPGC_HAS_ATTRIBUTE(unused)
31
+ #define CPPGC_UNUSED __attribute__((unused))
32
+ #else
33
+ #define CPPGC_UNUSED
34
+ #endif
35
+
36
+ } // namespace cppgc
37
+
38
+ #endif // INCLUDE_CPPGC_INTERNAL_COMPILER_SPECIFIC_H_
@@ -0,0 +1,90 @@
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_INTERNAL_FINALIZER_TRAIT_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
7
+
8
+ #include <type_traits>
9
+
10
+ #include "cppgc/type-traits.h"
11
+
12
+ namespace cppgc {
13
+ namespace internal {
14
+
15
+ using FinalizationCallback = void (*)(void*);
16
+
17
+ template <typename T, typename = void>
18
+ struct HasFinalizeGarbageCollectedObject : std::false_type {};
19
+
20
+ template <typename T>
21
+ struct HasFinalizeGarbageCollectedObject<
22
+ T, void_t<decltype(std::declval<T>().FinalizeGarbageCollectedObject())>>
23
+ : std::true_type {};
24
+
25
+ // The FinalizerTraitImpl specifies how to finalize objects.
26
+ template <typename T, bool isFinalized>
27
+ struct FinalizerTraitImpl;
28
+
29
+ template <typename T>
30
+ struct FinalizerTraitImpl<T, true> {
31
+ private:
32
+ // Dispatch to custom FinalizeGarbageCollectedObject().
33
+ struct Custom {
34
+ static void Call(void* obj) {
35
+ static_cast<T*>(obj)->FinalizeGarbageCollectedObject();
36
+ }
37
+ };
38
+
39
+ // Dispatch to regular destructor.
40
+ struct Destructor {
41
+ static void Call(void* obj) { static_cast<T*>(obj)->~T(); }
42
+ };
43
+
44
+ using FinalizeImpl =
45
+ std::conditional_t<HasFinalizeGarbageCollectedObject<T>::value, Custom,
46
+ Destructor>;
47
+
48
+ public:
49
+ static void Finalize(void* obj) {
50
+ static_assert(sizeof(T), "T must be fully defined");
51
+ FinalizeImpl::Call(obj);
52
+ }
53
+ };
54
+
55
+ template <typename T>
56
+ struct FinalizerTraitImpl<T, false> {
57
+ static void Finalize(void* obj) {
58
+ static_assert(sizeof(T), "T must be fully defined");
59
+ }
60
+ };
61
+
62
+ // The FinalizerTrait is used to determine if a type requires finalization and
63
+ // what finalization means.
64
+ template <typename T>
65
+ struct FinalizerTrait {
66
+ private:
67
+ // Object has a finalizer if it has
68
+ // - a custom FinalizeGarbageCollectedObject method, or
69
+ // - a destructor.
70
+ static constexpr bool kNonTrivialFinalizer =
71
+ internal::HasFinalizeGarbageCollectedObject<T>::value ||
72
+ !std::is_trivially_destructible<typename std::remove_cv<T>::type>::value;
73
+
74
+ static void Finalize(void* obj) {
75
+ internal::FinalizerTraitImpl<T, kNonTrivialFinalizer>::Finalize(obj);
76
+ }
77
+
78
+ public:
79
+ // The callback used to finalize an object of type T.
80
+ static constexpr FinalizationCallback kCallback =
81
+ kNonTrivialFinalizer ? Finalize : nullptr;
82
+ };
83
+
84
+ template <typename T>
85
+ constexpr FinalizationCallback FinalizerTrait<T>::kCallback;
86
+
87
+ } // namespace internal
88
+ } // namespace cppgc
89
+
90
+ #endif // INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
@@ -0,0 +1,76 @@
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_INTERNAL_GC_INFO_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
7
+
8
+ #include <atomic>
9
+ #include <cstdint>
10
+ #include <type_traits>
11
+
12
+ #include "cppgc/internal/finalizer-trait.h"
13
+ #include "cppgc/internal/name-trait.h"
14
+ #include "cppgc/trace-trait.h"
15
+ #include "v8config.h" // NOLINT(build/include_directory)
16
+
17
+ namespace cppgc {
18
+ namespace internal {
19
+
20
+ using GCInfoIndex = uint16_t;
21
+
22
+ // Acquires a new GC info object and returns the index. In addition, also
23
+ // updates `registered_index` atomically.
24
+ V8_EXPORT GCInfoIndex
25
+ EnsureGCInfoIndex(std::atomic<GCInfoIndex>& registered_index,
26
+ FinalizationCallback, TraceCallback, NameCallback, bool);
27
+
28
+ // Fold types based on finalizer behavior. Note that finalizer characteristics
29
+ // align with trace behavior, i.e., destructors are virtual when trace methods
30
+ // are and vice versa.
31
+ template <typename T, typename ParentMostGarbageCollectedType>
32
+ struct GCInfoFolding {
33
+ static constexpr bool kHasVirtualDestructorAtBase =
34
+ std::has_virtual_destructor<ParentMostGarbageCollectedType>::value;
35
+ static constexpr bool kBothTypesAreTriviallyDestructible =
36
+ std::is_trivially_destructible<ParentMostGarbageCollectedType>::value &&
37
+ std::is_trivially_destructible<T>::value;
38
+ static constexpr bool kHasCustomFinalizerDispatchAtBase =
39
+ internal::HasFinalizeGarbageCollectedObject<
40
+ ParentMostGarbageCollectedType>::value;
41
+ #ifdef CPPGC_SUPPORTS_OBJECT_NAMES
42
+ static constexpr bool kWantsDetailedObjectNames = true;
43
+ #else // !CPPGC_SUPPORTS_OBJECT_NAMES
44
+ static constexpr bool kWantsDetailedObjectNames = false;
45
+ #endif // !CPPGC_SUPPORTS_OBJECT_NAMES
46
+
47
+ // Folding would regresses name resolution when deriving names from C++
48
+ // class names as it would just folds a name to the base class name.
49
+ using ResultType = std::conditional_t<(kHasVirtualDestructorAtBase ||
50
+ kBothTypesAreTriviallyDestructible ||
51
+ kHasCustomFinalizerDispatchAtBase) &&
52
+ !kWantsDetailedObjectNames,
53
+ ParentMostGarbageCollectedType, T>;
54
+ };
55
+
56
+ // Trait determines how the garbage collector treats objects wrt. to traversing,
57
+ // finalization, and naming.
58
+ template <typename T>
59
+ struct GCInfoTrait final {
60
+ static GCInfoIndex Index() {
61
+ static_assert(sizeof(T), "T must be fully defined");
62
+ static std::atomic<GCInfoIndex>
63
+ registered_index; // Uses zero initialization.
64
+ const GCInfoIndex index = registered_index.load(std::memory_order_acquire);
65
+ return index ? index
66
+ : EnsureGCInfoIndex(
67
+ registered_index, FinalizerTrait<T>::kCallback,
68
+ TraceTrait<T>::Trace, NameTrait<T>::GetName,
69
+ std::is_polymorphic<T>::value);
70
+ }
71
+ };
72
+
73
+ } // namespace internal
74
+ } // namespace cppgc
75
+
76
+ #endif // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
@@ -0,0 +1,50 @@
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_INTERNAL_LOGGING_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_LOGGING_H_
7
+
8
+ #include "cppgc/source-location.h"
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace cppgc {
12
+ namespace internal {
13
+
14
+ void V8_EXPORT DCheckImpl(const char*,
15
+ const SourceLocation& = SourceLocation::Current());
16
+ [[noreturn]] void V8_EXPORT
17
+ FatalImpl(const char*, const SourceLocation& = SourceLocation::Current());
18
+
19
+ // Used to ignore -Wunused-variable.
20
+ template <typename>
21
+ struct EatParams {};
22
+
23
+ #if DEBUG
24
+ #define CPPGC_DCHECK_MSG(condition, message) \
25
+ do { \
26
+ if (V8_UNLIKELY(!(condition))) { \
27
+ ::cppgc::internal::DCheckImpl(message); \
28
+ } \
29
+ } while (false)
30
+ #else
31
+ #define CPPGC_DCHECK_MSG(condition, message) \
32
+ (static_cast<void>(::cppgc::internal::EatParams<decltype( \
33
+ static_cast<void>(condition), message)>{}))
34
+ #endif
35
+
36
+ #define CPPGC_DCHECK(condition) CPPGC_DCHECK_MSG(condition, #condition)
37
+
38
+ #define CPPGC_CHECK_MSG(condition, message) \
39
+ do { \
40
+ if (V8_UNLIKELY(!(condition))) { \
41
+ ::cppgc::internal::FatalImpl(message); \
42
+ } \
43
+ } while (false)
44
+
45
+ #define CPPGC_CHECK(condition) CPPGC_CHECK_MSG(condition, #condition)
46
+
47
+ } // namespace internal
48
+ } // namespace cppgc
49
+
50
+ #endif // INCLUDE_CPPGC_INTERNAL_LOGGING_H_