libv8 3.16.14.19.1-universal-darwin → 8.4.255.0.1-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8/location.rb +15 -7
  3. data/ext/libv8/paths.rb +6 -19
  4. data/lib/libv8/version.rb +1 -1
  5. data/vendor/v8/include/cppgc/allocation.h +124 -0
  6. data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
  7. data/vendor/v8/include/cppgc/heap.h +50 -0
  8. data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
  9. data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
  10. data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
  11. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  12. data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
  13. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  14. data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
  15. data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
  16. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
  17. data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
  18. data/vendor/v8/include/cppgc/macros.h +26 -0
  19. data/vendor/v8/include/cppgc/member.h +206 -0
  20. data/vendor/v8/include/cppgc/persistent.h +304 -0
  21. data/vendor/v8/include/cppgc/platform.h +31 -0
  22. data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
  23. data/vendor/v8/include/cppgc/source-location.h +59 -0
  24. data/vendor/v8/include/cppgc/trace-trait.h +67 -0
  25. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  26. data/vendor/v8/include/cppgc/visitor.h +137 -0
  27. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  28. data/vendor/v8/include/libplatform/libplatform.h +85 -0
  29. data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
  30. data/vendor/v8/include/v8-fast-api-calls.h +412 -0
  31. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  32. data/vendor/v8/include/v8-inspector.h +327 -0
  33. data/vendor/v8/include/v8-internal.h +389 -0
  34. data/vendor/v8/include/v8-platform.h +577 -0
  35. data/vendor/v8/include/v8-profiler.h +744 -265
  36. data/vendor/v8/include/v8-util.h +652 -0
  37. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  38. data/vendor/v8/include/v8-version-string.h +38 -0
  39. data/vendor/v8/include/v8-version.h +20 -0
  40. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  41. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  42. data/vendor/v8/include/v8.h +10228 -3147
  43. data/vendor/v8/include/v8config.h +465 -0
  44. data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
  45. data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
  46. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  47. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
  48. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
  49. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
  50. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
  51. metadata +52 -32
  52. data/ext/libv8/arch.rb +0 -43
  53. data/vendor/v8/include/v8-debug.h +0 -408
  54. data/vendor/v8/include/v8-preparser.h +0 -118
  55. data/vendor/v8/include/v8-testing.h +0 -105
  56. data/vendor/v8/include/v8stdint.h +0 -54
  57. data/vendor/v8/out/x64.release/libpreparser_lib.a +0 -0
  58. data/vendor/v8/out/x64.release/libv8_base.a +0 -0
  59. data/vendor/v8/out/x64.release/libv8_nosnapshot.a +0 -0
  60. data/vendor/v8/out/x64.release/libv8_snapshot.a +0 -0
@@ -0,0 +1,43 @@
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 <stdint.h>
9
+
10
+ #include "cppgc/internal/finalizer-trait.h"
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+ namespace internal {
15
+
16
+ using GCInfoIndex = uint16_t;
17
+
18
+ class V8_EXPORT RegisteredGCInfoIndex final {
19
+ public:
20
+ RegisteredGCInfoIndex(FinalizationCallback finalization_callback,
21
+ bool has_v_table);
22
+ GCInfoIndex GetIndex() const { return index_; }
23
+
24
+ private:
25
+ const GCInfoIndex index_;
26
+ };
27
+
28
+ // Trait determines how the garbage collector treats objects wrt. to traversing,
29
+ // finalization, and naming.
30
+ template <typename T>
31
+ struct GCInfoTrait {
32
+ static GCInfoIndex Index() {
33
+ static_assert(sizeof(T), "T must be fully defined");
34
+ static const RegisteredGCInfoIndex registered_index(
35
+ FinalizerTrait<T>::kCallback, std::is_polymorphic<T>::value);
36
+ return registered_index.GetIndex();
37
+ }
38
+ };
39
+
40
+ } // namespace internal
41
+ } // namespace cppgc
42
+
43
+ #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_
@@ -0,0 +1,109 @@
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_PERSISTENT_NODE_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_PERSISTENT_NODE_H_
7
+
8
+ #include <array>
9
+ #include <memory>
10
+ #include <vector>
11
+
12
+ #include "cppgc/internal/logging.h"
13
+ #include "cppgc/trace-trait.h"
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace cppgc {
17
+
18
+ class Visitor;
19
+
20
+ namespace internal {
21
+
22
+ // PersistentNode represesents a variant of two states:
23
+ // 1) traceable node with a back pointer to the Persistent object;
24
+ // 2) freelist entry.
25
+ class PersistentNode final {
26
+ public:
27
+ PersistentNode() = default;
28
+
29
+ PersistentNode(const PersistentNode&) = delete;
30
+ PersistentNode& operator=(const PersistentNode&) = delete;
31
+
32
+ void InitializeAsUsedNode(void* owner, TraceCallback trace) {
33
+ owner_ = owner;
34
+ trace_ = trace;
35
+ }
36
+
37
+ void InitializeAsFreeNode(PersistentNode* next) {
38
+ next_ = next;
39
+ trace_ = nullptr;
40
+ }
41
+
42
+ void UpdateOwner(void* owner) {
43
+ CPPGC_DCHECK(IsUsed());
44
+ owner_ = owner;
45
+ }
46
+
47
+ PersistentNode* FreeListNext() const {
48
+ CPPGC_DCHECK(!IsUsed());
49
+ return next_;
50
+ }
51
+
52
+ void Trace(Visitor* visitor) const {
53
+ CPPGC_DCHECK(IsUsed());
54
+ trace_(visitor, owner_);
55
+ }
56
+
57
+ bool IsUsed() const { return trace_; }
58
+
59
+ private:
60
+ // PersistentNode acts as a designated union:
61
+ // If trace_ != nullptr, owner_ points to the corresponding Persistent handle.
62
+ // Otherwise, next_ points to the next freed PersistentNode.
63
+ union {
64
+ void* owner_ = nullptr;
65
+ PersistentNode* next_;
66
+ };
67
+ TraceCallback trace_ = nullptr;
68
+ };
69
+
70
+ class V8_EXPORT PersistentRegion {
71
+ using PersistentNodeSlots = std::array<PersistentNode, 256u>;
72
+
73
+ public:
74
+ PersistentRegion() = default;
75
+
76
+ PersistentRegion(const PersistentRegion&) = delete;
77
+ PersistentRegion& operator=(const PersistentRegion&) = delete;
78
+
79
+ PersistentNode* AllocateNode(void* owner, TraceCallback trace) {
80
+ if (!free_list_head_) {
81
+ EnsureNodeSlots();
82
+ }
83
+ PersistentNode* node = free_list_head_;
84
+ free_list_head_ = free_list_head_->FreeListNext();
85
+ node->InitializeAsUsedNode(owner, trace);
86
+ return node;
87
+ }
88
+
89
+ void FreeNode(PersistentNode* node) {
90
+ node->InitializeAsFreeNode(free_list_head_);
91
+ free_list_head_ = node;
92
+ }
93
+
94
+ void Trace(Visitor*);
95
+
96
+ size_t NodesInUse() const;
97
+
98
+ private:
99
+ void EnsureNodeSlots();
100
+
101
+ std::vector<std::unique_ptr<PersistentNodeSlots>> nodes_;
102
+ PersistentNode* free_list_head_ = nullptr;
103
+ };
104
+
105
+ } // namespace internal
106
+
107
+ } // namespace cppgc
108
+
109
+ #endif // INCLUDE_CPPGC_INTERNAL_PERSISTENT_NODE_H_
@@ -0,0 +1,133 @@
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_POINTER_POLICIES_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
7
+
8
+ #include <cstdint>
9
+ #include <type_traits>
10
+
11
+ #include "cppgc/source-location.h"
12
+ #include "v8config.h" // NOLINT(build/include_directory)
13
+
14
+ namespace cppgc {
15
+ namespace internal {
16
+
17
+ class PersistentRegion;
18
+
19
+ // Tags to distinguish between strong and weak member types.
20
+ class StrongMemberTag;
21
+ class WeakMemberTag;
22
+ class UntracedMemberTag;
23
+
24
+ struct DijkstraWriteBarrierPolicy {
25
+ static void InitializingBarrier(const void*, const void*) {
26
+ // Since in initializing writes the source object is always white, having no
27
+ // barrier doesn't break the tri-color invariant.
28
+ }
29
+ static void AssigningBarrier(const void*, const void*) {
30
+ // TODO(chromium:1056170): Add actual implementation.
31
+ }
32
+ };
33
+
34
+ struct NoWriteBarrierPolicy {
35
+ static void InitializingBarrier(const void*, const void*) {}
36
+ static void AssigningBarrier(const void*, const void*) {}
37
+ };
38
+
39
+ class V8_EXPORT EnabledCheckingPolicy {
40
+ protected:
41
+ EnabledCheckingPolicy();
42
+ void CheckPointer(const void* ptr);
43
+
44
+ private:
45
+ void* impl_;
46
+ };
47
+
48
+ class DisabledCheckingPolicy {
49
+ protected:
50
+ void CheckPointer(const void* raw) {}
51
+ };
52
+
53
+ #if V8_ENABLE_CHECKS
54
+ using DefaultCheckingPolicy = EnabledCheckingPolicy;
55
+ #else
56
+ using DefaultCheckingPolicy = DisabledCheckingPolicy;
57
+ #endif
58
+
59
+ class KeepLocationPolicy {
60
+ public:
61
+ constexpr const SourceLocation& Location() const { return location_; }
62
+
63
+ protected:
64
+ constexpr explicit KeepLocationPolicy(const SourceLocation& location)
65
+ : location_(location) {}
66
+
67
+ // KeepLocationPolicy must not copy underlying source locations.
68
+ KeepLocationPolicy(const KeepLocationPolicy&) = delete;
69
+ KeepLocationPolicy& operator=(const KeepLocationPolicy&) = delete;
70
+
71
+ // Location of the original moved from object should be preserved.
72
+ KeepLocationPolicy(KeepLocationPolicy&&) = default;
73
+ KeepLocationPolicy& operator=(KeepLocationPolicy&&) = default;
74
+
75
+ private:
76
+ SourceLocation location_;
77
+ };
78
+
79
+ class IgnoreLocationPolicy {
80
+ public:
81
+ constexpr SourceLocation Location() const { return {}; }
82
+
83
+ protected:
84
+ constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {}
85
+ };
86
+
87
+ #if CPPGC_SUPPORTS_OBJECT_NAMES
88
+ using DefaultLocationPolicy = KeepLocationPolicy;
89
+ #else
90
+ using DefaultLocationPolicy = IgnoreLocationPolicy;
91
+ #endif
92
+
93
+ struct StrongPersistentPolicy {
94
+ using IsStrongPersistent = std::true_type;
95
+
96
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
97
+ };
98
+
99
+ struct WeakPersistentPolicy {
100
+ using IsStrongPersistent = std::false_type;
101
+
102
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
103
+ };
104
+
105
+ // Persistent/Member forward declarations.
106
+ template <typename T, typename WeaknessPolicy,
107
+ typename LocationPolicy = DefaultLocationPolicy,
108
+ typename CheckingPolicy = DefaultCheckingPolicy>
109
+ class BasicPersistent;
110
+ template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
111
+ typename CheckingPolicy = DefaultCheckingPolicy>
112
+ class BasicMember;
113
+
114
+ // Special tag type used to denote some sentinel member. The semantics of the
115
+ // sentinel is defined by the embedder.
116
+ struct SentinelPointer {
117
+ template <typename T>
118
+ operator T*() const { // NOLINT
119
+ static constexpr intptr_t kSentinelValue = -1;
120
+ return reinterpret_cast<T*>(kSentinelValue);
121
+ }
122
+ // Hidden friends.
123
+ friend bool operator==(SentinelPointer, SentinelPointer) { return true; }
124
+ friend bool operator!=(SentinelPointer, SentinelPointer) { return false; }
125
+ };
126
+
127
+ } // namespace internal
128
+
129
+ constexpr internal::SentinelPointer kSentinelPointer;
130
+
131
+ } // namespace cppgc
132
+
133
+ #endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
@@ -0,0 +1,31 @@
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_PREFINALIZER_HANDLER_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_PREFINALIZER_HANDLER_H_
7
+
8
+ #include "cppgc/heap.h"
9
+ #include "cppgc/liveness-broker.h"
10
+
11
+ namespace cppgc {
12
+ namespace internal {
13
+
14
+ class V8_EXPORT PreFinalizerRegistrationDispatcher final {
15
+ public:
16
+ using PreFinalizerCallback = bool (*)(const LivenessBroker&, void*);
17
+ struct PreFinalizer {
18
+ void* object_;
19
+ PreFinalizerCallback callback_;
20
+
21
+ bool operator==(const PreFinalizer& other);
22
+ };
23
+
24
+ static void RegisterPrefinalizer(cppgc::Heap* heap,
25
+ PreFinalizer prefinalzier);
26
+ };
27
+
28
+ } // namespace internal
29
+ } // namespace cppgc
30
+
31
+ #endif // INCLUDE_CPPGC_INTERNAL_PREFINALIZER_HANDLER_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_LIVENESS_BROKER_H_
6
+ #define INCLUDE_CPPGC_LIVENESS_BROKER_H_
7
+
8
+ #include "cppgc/heap.h"
9
+ #include "cppgc/member.h"
10
+ #include "cppgc/trace-trait.h"
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+
15
+ namespace internal {
16
+ class LivenessBrokerFactory;
17
+ } // namespace internal
18
+
19
+ class V8_EXPORT LivenessBroker final {
20
+ public:
21
+ template <typename T>
22
+ bool IsHeapObjectAlive(const T* object) const {
23
+ return object &&
24
+ IsHeapObjectAliveImpl(
25
+ TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
26
+ }
27
+
28
+ template <typename T>
29
+ bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
30
+ return (weak_member != kSentinelPointer) &&
31
+ IsHeapObjectAlive<T>(weak_member.Get());
32
+ }
33
+
34
+ template <typename T>
35
+ bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
36
+ return (untraced_member != kSentinelPointer) &&
37
+ IsHeapObjectAlive<T>(untraced_member.Get());
38
+ }
39
+
40
+ private:
41
+ LivenessBroker() = default;
42
+
43
+ bool IsHeapObjectAliveImpl(const void*) const;
44
+
45
+ friend class internal::LivenessBrokerFactory;
46
+ };
47
+
48
+ } // namespace cppgc
49
+
50
+ #endif // INCLUDE_CPPGC_LIVENESS_BROKER_H_
@@ -0,0 +1,26 @@
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_MACROS_H_
6
+ #define INCLUDE_CPPGC_MACROS_H_
7
+
8
+ namespace cppgc {
9
+
10
+ namespace internal {
11
+ class __thisIsHereToForceASemicolonAfterThisMacro {};
12
+ } // namespace internal
13
+
14
+ // Use if the object is only stack allocated.
15
+ #define CPPGC_STACK_ALLOCATED() \
16
+ public: \
17
+ using IsStackAllocatedTypeMarker = int; \
18
+ \
19
+ private: \
20
+ void* operator new(size_t) = delete; \
21
+ void* operator new(size_t, void*) = delete; \
22
+ friend class internal::__thisIsHereToForceASemicolonAfterThisMacro
23
+
24
+ } // namespace cppgc
25
+
26
+ #endif // INCLUDE_CPPGC_MACROS_H_
@@ -0,0 +1,206 @@
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_MEMBER_H_
6
+ #define INCLUDE_CPPGC_MEMBER_H_
7
+
8
+ #include <atomic>
9
+ #include <cstddef>
10
+ #include <type_traits>
11
+
12
+ #include "cppgc/internal/pointer-policies.h"
13
+ #include "cppgc/type-traits.h"
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace cppgc {
17
+
18
+ class Visitor;
19
+
20
+ namespace internal {
21
+
22
+ // The basic class from which all Member classes are 'generated'.
23
+ template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
24
+ typename CheckingPolicy>
25
+ class BasicMember : private CheckingPolicy {
26
+ public:
27
+ using PointeeType = T;
28
+
29
+ constexpr BasicMember() = default;
30
+ constexpr BasicMember(std::nullptr_t) {} // NOLINT
31
+ BasicMember(SentinelPointer s) : raw_(s) {} // NOLINT
32
+ BasicMember(T* raw) : raw_(raw) { // NOLINT
33
+ InitializingWriteBarrier();
34
+ this->CheckPointer(raw_);
35
+ }
36
+ BasicMember(T& raw) : BasicMember(&raw) {} // NOLINT
37
+ BasicMember(const BasicMember& other) : BasicMember(other.Get()) {}
38
+ // Allow heterogeneous construction.
39
+ template <typename U, typename OtherBarrierPolicy, typename OtherWeaknessTag,
40
+ typename OtherCheckingPolicy,
41
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
42
+ BasicMember( // NOLINT
43
+ const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
44
+ OtherCheckingPolicy>& other)
45
+ : BasicMember(other.Get()) {}
46
+ // Construction from Persistent.
47
+ template <typename U, typename PersistentWeaknessPolicy,
48
+ typename PersistentLocationPolicy,
49
+ typename PersistentCheckingPolicy,
50
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
51
+ BasicMember( // NOLINT
52
+ const BasicPersistent<U, PersistentWeaknessPolicy,
53
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
54
+ p)
55
+ : BasicMember(p.Get()) {}
56
+
57
+ BasicMember& operator=(const BasicMember& other) {
58
+ return operator=(other.Get());
59
+ }
60
+ // Allow heterogeneous assignment.
61
+ template <typename U, typename OtherWeaknessTag, typename OtherBarrierPolicy,
62
+ typename OtherCheckingPolicy,
63
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
64
+ BasicMember& operator=(
65
+ const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
66
+ OtherCheckingPolicy>& other) {
67
+ return operator=(other.Get());
68
+ }
69
+ // Assignment from Persistent.
70
+ template <typename U, typename PersistentWeaknessPolicy,
71
+ typename PersistentLocationPolicy,
72
+ typename PersistentCheckingPolicy,
73
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
74
+ BasicMember& operator=(
75
+ const BasicPersistent<U, PersistentWeaknessPolicy,
76
+ PersistentLocationPolicy, PersistentCheckingPolicy>&
77
+ other) {
78
+ return operator=(other.Get());
79
+ }
80
+ BasicMember& operator=(T* other) {
81
+ SetRawAtomic(other);
82
+ AssigningWriteBarrier();
83
+ this->CheckPointer(Get());
84
+ return *this;
85
+ }
86
+ BasicMember& operator=(std::nullptr_t) {
87
+ Clear();
88
+ return *this;
89
+ }
90
+ BasicMember& operator=(SentinelPointer s) {
91
+ SetRawAtomic(s);
92
+ return *this;
93
+ }
94
+
95
+ template <typename OtherWeaknessTag, typename OtherBarrierPolicy,
96
+ typename OtherCheckingPolicy>
97
+ void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
98
+ OtherCheckingPolicy>& other) {
99
+ T* tmp = Get();
100
+ *this = other;
101
+ other = tmp;
102
+ }
103
+
104
+ explicit operator bool() const { return Get(); }
105
+ operator T*() const { return Get(); } // NOLINT
106
+ T* operator->() const { return Get(); }
107
+ T& operator*() const { return *Get(); }
108
+
109
+ T* Get() const {
110
+ // Executed by the mutator, hence non atomic load.
111
+ return raw_;
112
+ }
113
+
114
+ void Clear() { SetRawAtomic(nullptr); }
115
+
116
+ T* Release() {
117
+ T* result = Get();
118
+ Clear();
119
+ return result;
120
+ }
121
+
122
+ private:
123
+ void SetRawAtomic(T* raw) {
124
+ reinterpret_cast<std::atomic<T*>*>(&raw_)->store(raw,
125
+ std::memory_order_relaxed);
126
+ }
127
+ T* GetRawAtomic() const {
128
+ return reinterpret_cast<const std::atomic<T*>*>(&raw_)->load(
129
+ std::memory_order_relaxed);
130
+ }
131
+
132
+ void InitializingWriteBarrier() const {
133
+ WriteBarrierPolicy::InitializingBarrier(
134
+ reinterpret_cast<const void*>(&raw_), static_cast<const void*>(raw_));
135
+ }
136
+ void AssigningWriteBarrier() const {
137
+ WriteBarrierPolicy::AssigningBarrier(reinterpret_cast<const void*>(&raw_),
138
+ static_cast<const void*>(raw_));
139
+ }
140
+
141
+ T* raw_ = nullptr;
142
+
143
+ friend class cppgc::Visitor;
144
+ };
145
+
146
+ template <typename T1, typename WeaknessTag1, typename WriteBarrierPolicy1,
147
+ typename CheckingPolicy1, typename T2, typename WeaknessTag2,
148
+ typename WriteBarrierPolicy2, typename CheckingPolicy2>
149
+ bool operator==(
150
+ BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
151
+ BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
152
+ member2) {
153
+ return member1.Get() == member2.Get();
154
+ }
155
+
156
+ template <typename T1, typename WeaknessTag1, typename WriteBarrierPolicy1,
157
+ typename CheckingPolicy1, typename T2, typename WeaknessTag2,
158
+ typename WriteBarrierPolicy2, typename CheckingPolicy2>
159
+ bool operator!=(
160
+ BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
161
+ BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
162
+ member2) {
163
+ return !(member1 == member2);
164
+ }
165
+
166
+ template <typename T, typename WriteBarrierPolicy, typename CheckingPolicy>
167
+ struct IsWeak<
168
+ internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
169
+ : std::true_type {};
170
+
171
+ } // namespace internal
172
+
173
+ /**
174
+ * Members are used in classes to contain strong pointers to other garbage
175
+ * collected objects. All Member fields of a class must be traced in the class'
176
+ * trace method.
177
+ */
178
+ template <typename T>
179
+ using Member = internal::BasicMember<T, internal::StrongMemberTag,
180
+ internal::DijkstraWriteBarrierPolicy>;
181
+
182
+ /**
183
+ * WeakMember is similar to Member in that it is used to point to other garbage
184
+ * collected objects. However instead of creating a strong pointer to the
185
+ * object, the WeakMember creates a weak pointer, which does not keep the
186
+ * pointee alive. Hence if all pointers to to a heap allocated object are weak
187
+ * the object will be garbage collected. At the time of GC the weak pointers
188
+ * will automatically be set to null.
189
+ */
190
+ template <typename T>
191
+ using WeakMember = internal::BasicMember<T, internal::WeakMemberTag,
192
+ internal::DijkstraWriteBarrierPolicy>;
193
+
194
+ /**
195
+ * UntracedMember is a pointer to an on-heap object that is not traced for some
196
+ * reason. Do not use this unless you know what you are doing. Keeping raw
197
+ * pointers to on-heap objects is prohibited unless used from stack. Pointee
198
+ * must be kept alive through other means.
199
+ */
200
+ template <typename T>
201
+ using UntracedMember = internal::BasicMember<T, internal::UntracedMemberTag,
202
+ internal::NoWriteBarrierPolicy>;
203
+
204
+ } // namespace cppgc
205
+
206
+ #endif // INCLUDE_CPPGC_MEMBER_H_