5#ifndef INCLUDE_CPPGC_PERSISTENT_H_
6#define INCLUDE_CPPGC_PERSISTENT_H_
42 mutable const void*
raw_ =
nullptr;
49template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
50 typename CheckingPolicy>
52 public LocationPolicy,
53 private WeaknessPolicy,
54 private CheckingPolicy {
56 using typename WeaknessPolicy::IsStrongPersistent;
62 : LocationPolicy(loc) {}
66 : LocationPolicy(loc) {}
76 if (!IsValid())
return;
78 .AllocateNode(
this, &TraceAsRoot));
79 this->CheckPointer(
Get());
92 template <
typename U,
typename OtherWeaknessPolicy,
93 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
94 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
98 OtherCheckingPolicy>& other,
107 :
PersistentBase(std::move(other)), LocationPolicy(std::move(other)) {
108 if (!IsValid())
return;
110 other.SetValue(
nullptr);
111 other.SetNode(
nullptr);
112 this->CheckPointer(
Get());
116 template <
typename U,
typename MemberBarrierPolicy,
117 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
118 typename MemberStorageType,
119 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
122 U, MemberBarrierPolicy, MemberWeaknessTag,
123 MemberCheckingPolicy, MemberStorageType>& member,
134 template <
typename U,
typename OtherWeaknessPolicy,
135 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
136 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
139 OtherCheckingPolicy>& other) {
145 if (
this == &other)
return *
this;
147 PersistentBase::operator=(std::move(other));
148 LocationPolicy::operator=(std::move(other));
149 if (!IsValid())
return *
this;
153 this->CheckPointer(
Get());
158 template <
typename U,
typename MemberBarrierPolicy,
159 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
160 typename MemberStorageType,
161 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
164 MemberCheckingPolicy, MemberStorageType>&
184 explicit operator bool()
const {
return Get(); }
187 operator T*()
const {
return Get(); }
198 return static_cast<T*
>(
const_cast<void*
>(
GetValue()));
217 template <
typename U,
typename OtherWeaknessPolicy = WeaknessPolicy,
218 typename OtherLocationPolicy = LocationPolicy,
219 typename OtherCheckingPolicy = CheckingPolicy>
224 OtherCheckingPolicy>(
static_cast<U*
>(
Get()));
228 static void TraceAsRoot(
RootVisitor& root_visitor,
const void* ptr) {
232 bool IsValid()
const {
239 void Assign(T* ptr) {
244 this->CheckPointer(ptr);
251 if (!IsValid())
return;
253 .AllocateNode(
this, &TraceAsRoot));
254 this->CheckPointer(
Get());
257 void ClearFromGC()
const {
266 T* GetFromGC()
const {
267 return static_cast<T*
>(
const_cast<void*
>(
GetValue()));
273template <
typename T1,
typename WeaknessPolicy1,
typename LocationPolicy1,
274 typename CheckingPolicy1,
typename T2,
typename WeaknessPolicy2,
275 typename LocationPolicy2,
typename CheckingPolicy2>
277 CheckingPolicy1>& p1,
279 CheckingPolicy2>& p2) {
280 return p1.Get() == p2.Get();
283template <
typename T1,
typename WeaknessPolicy1,
typename LocationPolicy1,
284 typename CheckingPolicy1,
typename T2,
typename WeaknessPolicy2,
285 typename LocationPolicy2,
typename CheckingPolicy2>
287 CheckingPolicy1>& p1,
289 CheckingPolicy2>& p2) {
293template <
typename T1,
typename PersistentWeaknessPolicy,
294 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy,
295 typename T2,
typename MemberWriteBarrierPolicy,
296 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
297 typename MemberStorageType>
300 PersistentLocationPolicy, PersistentCheckingPolicy>&
302 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
303 MemberCheckingPolicy, MemberStorageType>& m) {
304 return p.Get() == m.Get();
307template <
typename T1,
typename PersistentWeaknessPolicy,
308 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy,
309 typename T2,
typename MemberWriteBarrierPolicy,
310 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
311 typename MemberStorageType>
314 PersistentLocationPolicy, PersistentCheckingPolicy>&
316 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
317 MemberCheckingPolicy, MemberStorageType>& m) {
321template <
typename T1,
typename MemberWriteBarrierPolicy,
322 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
323 typename MemberStorageType,
typename T2,
324 typename PersistentWeaknessPolicy,
typename PersistentLocationPolicy,
325 typename PersistentCheckingPolicy>
327 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
328 MemberCheckingPolicy, MemberStorageType>& m,
330 PersistentLocationPolicy, PersistentCheckingPolicy>&
332 return m.Get() == p.Get();
335template <
typename T1,
typename MemberWriteBarrierPolicy,
336 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
337 typename MemberStorageType,
typename T2,
338 typename PersistentWeaknessPolicy,
typename PersistentLocationPolicy,
339 typename PersistentCheckingPolicy>
341 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
342 MemberCheckingPolicy, MemberStorageType>& m,
344 PersistentLocationPolicy, PersistentCheckingPolicy>&
349template <
typename T,
typename LocationPolicy,
typename CheckingPolicy>
351 CheckingPolicy>> : std::true_type {};
Definition: persistent.h:54
BasicPersistent(T &raw, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:82
BasicPersistent(T *raw, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:73
BasicPersistent(const BasicPersistent &other, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:87
T PointeeType
Definition: persistent.h:57
BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > To() const
Definition: persistent.h:222
BasicPersistent(const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:60
BasicPersistent & operator=(BasicPersistent &&other) noexcept
Definition: persistent.h:144
T * Release()
Definition: persistent.h:211
~BasicPersistent()
Definition: persistent.h:127
void Clear()
Definition: persistent.h:201
T * operator->() const
Definition: persistent.h:188
BasicPersistent & operator=(const BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other)
Definition: persistent.h:137
BasicPersistent & operator=(const BasicPersistent &other)
Definition: persistent.h:130
BasicPersistent(SentinelPointer s, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:68
T & operator*() const
Definition: persistent.h:189
BasicPersistent & operator=(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > &member)
Definition: persistent.h:162
BasicPersistent(BasicPersistent &&other, const SourceLocation &loc=SourceLocation::Current()) noexcept
Definition: persistent.h:104
BasicPersistent(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > &member, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:121
BasicPersistent(std::nullptr_t, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:64
T * Get() const
Definition: persistent.h:194
BasicPersistent & operator=(T *other)
Definition: persistent.h:169
BasicPersistent(const BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other, const SourceLocation &loc=SourceLocation::Current())
Definition: persistent.h:96
BasicPersistent & operator=(std::nullptr_t)
Definition: persistent.h:174
BasicPersistent & operator=(SentinelPointer s)
Definition: persistent.h:179
Definition: persistent.h:23
void ClearFromGC() const
Definition: persistent.h:36
const void * GetValue() const
Definition: persistent.h:28
PersistentBase(const void *raw)
Definition: persistent.h:26
void SetValue(const void *value)
Definition: persistent.h:29
PersistentNode * GetNode() const
Definition: persistent.h:31
const void * raw_
Definition: persistent.h:42
PersistentNode * node_
Definition: persistent.h:43
void SetNode(PersistentNode *node)
Definition: persistent.h:32
Definition: persistent-node.h:27
void UpdateOwner(void *owner)
Definition: persistent-node.h:45
Definition: persistent-node.h:78
Definition: visitor.h:441
void Trace(const AnyStrongPersistentType &p)
Definition: visitor.h:450
Definition: v8-source-location.h:31
static constexpr SourceLocation Current()
Definition: v8-source-location.h:44
bool operator!=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:368
bool operator==(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:348
Definition: allocation.h:38
constexpr internal::SentinelPointer kSentinelPointer
Definition: sentinel-pointer.h:35
Definition: type-traits.h:30
Definition: sentinel-pointer.h:17
Definition: pointer-policies.h:245
#define V8_CLANG_NO_SANITIZE(what)
defined(V8_TRIVIAL_ABI)
Definition: v8config.h:754