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 {};
BasicPersistent & operator=(BasicPersistent &&other) noexcept
BasicPersistent(BasicPersistent &&other, const SourceLocation &loc=SourceLocation::Current()) noexcept
BasicPersistent(T *raw, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent(const BasicPersistent &other, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent(std::nullptr_t, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent & operator=(T *other)
V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T *Get() const
BasicPersistent & operator=(std::nullptr_t)
BasicPersistent & operator=(SentinelPointer s)
BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > To() const
BasicPersistent(const BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent & operator=(const BasicPersistent &other)
BasicPersistent & operator=(const BasicPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other)
BasicPersistent(const SourceLocation &loc=SourceLocation::Current())
BasicPersistent(T &raw, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent & operator=(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > &member)
BasicPersistent(SentinelPointer s, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > &member, const SourceLocation &loc=SourceLocation::Current())
const void * GetValue() const
PersistentBase(const void *raw)
void SetValue(const void *value)
PersistentNode * GetNode() const
void SetNode(PersistentNode *node)
void UpdateOwner(void *owner)
void Trace(const AnyStrongPersistentType &p)
static constexpr SourceLocation Current()
V8_INLINE bool operator==(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
V8_INLINE bool operator!=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
constexpr internal::SentinelPointer kSentinelPointer
#define V8_CLANG_NO_SANITIZE(what)
defined(V8_TRIVIAL_ABI)