5#ifndef INCLUDE_CPPGC_PERSISTENT_H_
6#define INCLUDE_CPPGC_PERSISTENT_H_
45 mutable const void*
raw_ =
nullptr;
52template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
53 typename CheckingPolicy>
55 public LocationPolicy,
56 private WeaknessPolicy,
57 private CheckingPolicy {
59 using typename WeaknessPolicy::IsStrongPersistent;
65 : LocationPolicy(loc) {}
69 : LocationPolicy(loc) {}
79 if (!IsValid())
return;
81 .AllocateNode(
this, &BasicPersistent::Trace));
82 this->CheckPointer(Get());
95 template <
typename U,
typename OtherWeaknessPolicy,
96 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
97 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
100 OtherCheckingPolicy>& other,
109 :
PersistentBase(std::move(other)), LocationPolicy(std::move(other)) {
110 if (!IsValid())
return;
112 other.SetValue(
nullptr);
113 other.SetNode(
nullptr);
114 this->CheckPointer(Get());
118 template <
typename U,
typename MemberBarrierPolicy,
119 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
120 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
123 MemberCheckingPolicy>& 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 = std::enable_if_t<std::is_base_of<T, U>::value>>
163 MemberCheckingPolicy>& member) {
182 explicit operator bool()
const {
return Get(); }
183 operator T*()
const {
return Get(); }
194 return static_cast<T*
>(
const_cast<void*
>(
GetValue()));
213 template <
typename U,
typename OtherWeaknessPolicy = WeaknessPolicy,
214 typename OtherLocationPolicy = LocationPolicy,
215 typename OtherCheckingPolicy = CheckingPolicy>
220 OtherCheckingPolicy>(
static_cast<U*
>(Get()));
224 static void Trace(
Visitor* v,
const void* ptr) {
226 v->TraceRoot(*persistent, persistent->Location());
229 bool IsValid()
const {
236 void Assign(T* ptr) {
241 this->CheckPointer(ptr);
248 if (!IsValid())
return;
250 .AllocateNode(
this, &BasicPersistent::Trace));
251 this->CheckPointer(Get());
254 void ClearFromGC()
const {
263 T* GetFromGC()
const {
264 return static_cast<T*
>(
const_cast<void*
>(
GetValue()));
270template <
typename T1,
typename WeaknessPolicy1,
typename LocationPolicy1,
271 typename CheckingPolicy1,
typename T2,
typename WeaknessPolicy2,
272 typename LocationPolicy2,
typename CheckingPolicy2>
274 CheckingPolicy1>& p1,
276 CheckingPolicy2>& p2) {
277 return p1.Get() == p2.Get();
280template <
typename T1,
typename WeaknessPolicy1,
typename LocationPolicy1,
281 typename CheckingPolicy1,
typename T2,
typename WeaknessPolicy2,
282 typename LocationPolicy2,
typename CheckingPolicy2>
284 CheckingPolicy1>& p1,
286 CheckingPolicy2>& p2) {
290template <
typename T1,
typename PersistentWeaknessPolicy,
291 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy,
292 typename T2,
typename MemberWriteBarrierPolicy,
293 typename MemberWeaknessTag,
typename MemberCheckingPolicy>
296 PersistentLocationPolicy, PersistentCheckingPolicy>&
298 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
299 MemberCheckingPolicy>& m) {
300 return p.Get() == m.Get();
303template <
typename T1,
typename PersistentWeaknessPolicy,
304 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy,
305 typename T2,
typename MemberWriteBarrierPolicy,
306 typename MemberWeaknessTag,
typename MemberCheckingPolicy>
309 PersistentLocationPolicy, PersistentCheckingPolicy>&
311 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
312 MemberCheckingPolicy>& m) {
316template <
typename T1,
typename MemberWriteBarrierPolicy,
317 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
318 typename T2,
typename PersistentWeaknessPolicy,
319 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy>
321 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
322 MemberCheckingPolicy>& m,
324 PersistentLocationPolicy, PersistentCheckingPolicy>&
326 return m.Get() == p.Get();
329template <
typename T1,
typename MemberWriteBarrierPolicy,
330 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
331 typename T2,
typename PersistentWeaknessPolicy,
332 typename PersistentLocationPolicy,
typename PersistentCheckingPolicy>
334 const BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
335 MemberCheckingPolicy>& m,
337 PersistentLocationPolicy, PersistentCheckingPolicy>&
342template <
typename T,
typename LocationPolicy,
typename CheckingPolicy>
344 CheckingPolicy>> : std::true_type {};
static constexpr SourceLocation Current()
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=(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy > &member)
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(const internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy > &member, const SourceLocation &loc=SourceLocation::Current())
BasicPersistent(SentinelPointer s, 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)
bool operator!=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1 > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2 > &member2)
bool operator==(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1 > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2 > &member2)
constexpr internal::SentinelPointer kSentinelPointer
#define V8_CLANG_NO_SANITIZE(what)