v8  9.0.257(node16.0.0)
V8 is Google's open source JavaScript engine
pointer-policies.h
Go to the documentation of this file.
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/internal/write-barrier.h"
12 #include "cppgc/source-location.h"
13 #include "v8config.h" // NOLINT(build/include_directory)
14 
15 namespace cppgc {
16 namespace internal {
17 
18 class PersistentRegion;
19 
20 // Tags to distinguish between strong and weak member types.
21 class StrongMemberTag;
22 class WeakMemberTag;
23 class UntracedMemberTag;
24 
26  static void InitializingBarrier(const void*, const void*) {
27  // Since in initializing writes the source object is always white, having no
28  // barrier doesn't break the tri-color invariant.
29  }
30  static void AssigningBarrier(const void* slot, const void* value) {
31  WriteBarrier::Params params;
32  switch (WriteBarrier::GetWriteBarrierType(slot, value, params)) {
33  case WriteBarrier::Type::kGenerational:
34  WriteBarrier::GenerationalBarrier(params, slot);
35  break;
36  case WriteBarrier::Type::kMarking:
37  WriteBarrier::DijkstraMarkingBarrier(params, value);
38  break;
39  case WriteBarrier::Type::kNone:
40  break;
41  }
42  }
43 };
44 
46  static void InitializingBarrier(const void*, const void*) {}
47  static void AssigningBarrier(const void*, const void*) {}
48 };
49 
51  protected:
53  void CheckPointer(const void* ptr);
54 
55  private:
56  void* impl_;
57 };
58 
60  protected:
61  void CheckPointer(const void* raw) {}
62 };
63 
64 #if V8_ENABLE_CHECKS
66 #else
67 using DefaultCheckingPolicy = DisabledCheckingPolicy;
68 #endif
69 
71  public:
72  constexpr const SourceLocation& Location() const { return location_; }
73 
74  protected:
75  constexpr KeepLocationPolicy() = default;
76  constexpr explicit KeepLocationPolicy(const SourceLocation& location)
77  : location_(location) {}
78 
79  // KeepLocationPolicy must not copy underlying source locations.
80  KeepLocationPolicy(const KeepLocationPolicy&) = delete;
82 
83  // Location of the original moved from object should be preserved.
86 
87  private:
88  SourceLocation location_;
89 };
90 
92  public:
93  constexpr SourceLocation Location() const { return {}; }
94 
95  protected:
96  constexpr IgnoreLocationPolicy() = default;
97  constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {}
98 };
99 
100 #if CPPGC_SUPPORTS_OBJECT_NAMES
102 #else
103 using DefaultLocationPolicy = IgnoreLocationPolicy;
104 #endif
105 
107  using IsStrongPersistent = std::true_type;
108  static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
109 };
110 
112  using IsStrongPersistent = std::false_type;
113  static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
114 };
115 
117  using IsStrongPersistent = std::true_type;
118  static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
119 };
120 
122  using IsStrongPersistent = std::false_type;
123  static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
124 };
125 
126 // Forward declarations setting up the default policies.
127 template <typename T, typename WeaknessPolicy,
128  typename LocationPolicy = DefaultLocationPolicy,
129  typename CheckingPolicy = DisabledCheckingPolicy>
131 template <typename T, typename WeaknessPolicy,
132  typename LocationPolicy = DefaultLocationPolicy,
133  typename CheckingPolicy = DefaultCheckingPolicy>
135 template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
136  typename CheckingPolicy = DefaultCheckingPolicy>
137 class BasicMember;
138 
139 } // namespace internal
140 
141 } // namespace cppgc
142 
143 #endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
cppgc::internal::IgnoreLocationPolicy::Location
constexpr SourceLocation Location() const
Definition: pointer-policies.h:93
cppgc::internal::EnabledCheckingPolicy::CheckPointer
void CheckPointer(const void *ptr)
cppgc::SourceLocation::SourceLocation
constexpr SourceLocation()=default
cppgc::Visitor::BasicPersistent
friend class internal::BasicPersistent
Definition: visitor.h:325
cppgc::internal::StrongCrossThreadPersistentPolicy
Definition: pointer-policies.h:116
cppgc::internal::KeepLocationPolicy::KeepLocationPolicy
constexpr KeepLocationPolicy(const SourceLocation &location)
Definition: pointer-policies.h:76
cppgc::internal::WriteBarrier::GenerationalBarrier
static V8_INLINE void GenerationalBarrier(const Params &params, const void *slot)
Definition: write-barrier.h:79
cppgc::internal::WriteBarrier::Type::kGenerational
@ kGenerational
cppgc::internal::WeakPersistentPolicy
Definition: pointer-policies.h:111
cppgc::internal::DijkstraWriteBarrierPolicy
Definition: pointer-policies.h:25
cppgc::internal::WriteBarrier::Type::kMarking
@ kMarking
cppgc::internal::EnabledCheckingPolicy::EnabledCheckingPolicy
EnabledCheckingPolicy()
cppgc::internal::DisabledCheckingPolicy
Definition: pointer-policies.h:59
cppgc::internal::StrongCrossThreadPersistentPolicy::GetPersistentRegion
static V8_EXPORT PersistentRegion & GetPersistentRegion(const void *object)
cppgc::internal::KeepLocationPolicy::KeepLocationPolicy
constexpr KeepLocationPolicy()=default
cppgc::internal::DijkstraWriteBarrierPolicy::InitializingBarrier
static void InitializingBarrier(const void *, const void *)
Definition: pointer-policies.h:26
cppgc::internal::EnabledCheckingPolicy
Definition: pointer-policies.h:50
cppgc::internal::WeakCrossThreadPersistentPolicy
Definition: pointer-policies.h:121
cppgc::internal::StrongPersistentPolicy::GetPersistentRegion
static V8_EXPORT PersistentRegion & GetPersistentRegion(const void *object)
cppgc::internal::WriteBarrier::Type::kNone
@ kNone
cppgc::internal::NoWriteBarrierPolicy::AssigningBarrier
static void AssigningBarrier(const void *, const void *)
Definition: pointer-policies.h:47
cppgc
Definition: allocation.h:17
V8_EXPORT
#define V8_EXPORT
Definition: v8config.h:512
cppgc::internal::IgnoreLocationPolicy::IgnoreLocationPolicy
constexpr IgnoreLocationPolicy()=default
cppgc::SourceLocation::Current
static constexpr SourceLocation Current()
Definition: source-location.h:43
cppgc::internal::KeepLocationPolicy::KeepLocationPolicy
KeepLocationPolicy(const KeepLocationPolicy &)=delete
cppgc::internal::KeepLocationPolicy::operator=
KeepLocationPolicy & operator=(const KeepLocationPolicy &)=delete
cppgc::internal::DisabledCheckingPolicy::CheckPointer
void CheckPointer(const void *raw)
Definition: pointer-policies.h:61
cppgc::internal::WeakPersistentPolicy::GetPersistentRegion
static V8_EXPORT PersistentRegion & GetPersistentRegion(const void *object)
cppgc::internal::WriteBarrier::Params
Definition: write-barrier.h:36
cppgc::internal::WriteBarrier::Type
Type
Definition: write-barrier.h:30
cppgc::Visitor::BasicCrossThreadPersistent
friend class internal::BasicCrossThreadPersistent
Definition: visitor.h:322
cppgc::internal::WriteBarrier::DijkstraMarkingBarrier
static V8_INLINE void DijkstraMarkingBarrier(const Params &params, const void *object)
Definition: write-barrier.h:337
cppgc::internal::KeepLocationPolicy
Definition: pointer-policies.h:70
cppgc::internal::WriteBarrier::GetWriteBarrierType
static V8_INLINE Type GetWriteBarrierType(const void *slot, const void *value, Params &params)
Definition: write-barrier.h:312
cppgc::internal::KeepLocationPolicy::KeepLocationPolicy
KeepLocationPolicy(KeepLocationPolicy &&)=default
cppgc::internal::WeakCrossThreadPersistentPolicy::GetPersistentRegion
static V8_EXPORT PersistentRegion & GetPersistentRegion(const void *object)
cppgc::internal::NoWriteBarrierPolicy
Definition: pointer-policies.h:45
cppgc::internal
Definition: allocation.h:22
cppgc::internal::KeepLocationPolicy::Location
constexpr const SourceLocation & Location() const
Definition: pointer-policies.h:72
cppgc::internal::IgnoreLocationPolicy::IgnoreLocationPolicy
constexpr IgnoreLocationPolicy(const SourceLocation &)
Definition: pointer-policies.h:97
cppgc::internal::IgnoreLocationPolicy
Definition: pointer-policies.h:91
cppgc::internal::StrongPersistentPolicy
Definition: pointer-policies.h:106
cppgc::internal::KeepLocationPolicy::operator=
KeepLocationPolicy & operator=(KeepLocationPolicy &&)=default
cppgc::internal::NoWriteBarrierPolicy::InitializingBarrier
static void InitializingBarrier(const void *, const void *)
Definition: pointer-policies.h:46
cppgc::internal::DijkstraWriteBarrierPolicy::AssigningBarrier
static void AssigningBarrier(const void *slot, const void *value)
Definition: pointer-policies.h:30