5#ifndef INCLUDE_CPPGC_MEMBER_H_
6#define INCLUDE_CPPGC_MEMBER_H_
31template <
typename StorageType>
50 return reinterpret_cast<const void**
>(
const_cast<MemberBase*
>(
this));
60 reinterpret_cast<std::atomic<RawStorage>&
>(raw_).store(
61 other, std::memory_order_relaxed);
69 friend class MemberDebugHelper;
75template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
76 typename CheckingPolicy,
typename StorageType>
78 private CheckingPolicy {
89 InitializingWriteBarrier(raw);
90 this->CheckPointer(Get());
100 :
Base(nullptr, atomic) {}
104 :
Base(raw, atomic) {
105 InitializingWriteBarrier(raw);
106 this->CheckPointer(Get());
118 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
119 typename OtherCheckingPolicy,
120 std::enable_if_t<internal::IsDecayedSameV<T, U>>* =
nullptr>
122 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
123 OtherCheckingPolicy, StorageType>& other)
126 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
127 typename OtherCheckingPolicy,
128 std::enable_if_t<internal::IsStrictlyBaseOfV<T, U>>* =
nullptr>
130 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
131 OtherCheckingPolicy, StorageType>& other)
143 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
144 typename OtherCheckingPolicy,
145 std::enable_if_t<internal::IsDecayedSameV<T, U>>* =
nullptr>
147 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
148 StorageType>&& other) noexcept
153 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
154 typename OtherCheckingPolicy,
155 std::enable_if_t<internal::IsStrictlyBaseOfV<T, U>>* =
nullptr>
157 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
158 StorageType>&& other) noexcept
164 template <
typename U,
typename PersistentWeaknessPolicy,
165 typename PersistentLocationPolicy,
166 typename PersistentCheckingPolicy,
167 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
169 PersistentLocationPolicy,
170 PersistentCheckingPolicy>& p)
181 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
182 typename OtherCheckingPolicy>
184 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
185 OtherCheckingPolicy, StorageType>& other) {
186 if constexpr (internal::IsDecayedSameV<T, U>) {
187 return operator=(other.GetRawStorage());
189 static_assert(internal::IsStrictlyBaseOfV<T, U>);
190 return operator=(other.Get());
196 operator=(other.GetRawStorage());
204 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
205 typename OtherCheckingPolicy>
207 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
208 StorageType>&& other)
noexcept {
209 if constexpr (internal::IsDecayedSameV<T, U>) {
210 operator=(other.GetRawStorage());
212 static_assert(internal::IsStrictlyBaseOfV<T, U>);
213 operator=(other.Get());
220 template <
typename U,
typename PersistentWeaknessPolicy,
221 typename PersistentLocationPolicy,
222 typename PersistentCheckingPolicy,
223 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
226 PersistentLocationPolicy, PersistentCheckingPolicy>&
228 return operator=(other.Get());
232 Base::SetRawAtomic(other);
233 AssigningWriteBarrier(other);
234 this->CheckPointer(Get());
243 Base::SetRawAtomic(s);
247 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
248 typename OtherCheckingPolicy>
250 OtherCheckingPolicy, StorageType>& other) {
251 auto tmp = GetRawStorage();
256 V8_INLINE explicit operator bool()
const {
return !Base::IsCleared(); }
270 return static_cast<T*
>(
const_cast<void*
>(Base::GetRaw()));
284 return reinterpret_cast<const T**
>(Base::GetRawSlot());
288 return Base::GetRawStorage();
293 InitializingWriteBarrier(Get());
294 this->CheckPointer(Get());
297 V8_INLINE BasicMember& operator=(RawStorage other) {
298 Base::SetRawStorageAtomic(other);
299 AssigningWriteBarrier();
300 this->CheckPointer(Get());
304 V8_INLINE const T* GetRawAtomic()
const {
305 return static_cast<const T*
>(Base::GetRawAtomic());
308 V8_INLINE void InitializingWriteBarrier(T* value)
const {
309 WriteBarrierPolicy::InitializingBarrier(Base::GetRawSlot(), value);
311 V8_INLINE void AssigningWriteBarrier(T* value)
const {
312 WriteBarrierPolicy::template AssigningBarrier<
313 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(), value);
315 V8_INLINE void AssigningWriteBarrier()
const {
316 WriteBarrierPolicy::template AssigningBarrier<
317 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(),
318 Base::GetRawStorage());
321 V8_INLINE void ClearFromGC()
const { Base::ClearFromGC(); }
323 V8_INLINE T* GetFromGC()
const {
return Get(); }
327 template <
typename U>
329 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
330 typename CheckingPolicy1,
typename StorageType1>
335template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
336 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
337 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
338 typename StorageType>
340 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
341 StorageType>& member1,
342 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
343 StorageType>& member2) {
344 if constexpr (internal::IsDecayedSameV<T1, T2>) {
346 return member1.GetRawStorage() == member2.GetRawStorage();
348 static_assert(internal::IsStrictlyBaseOfV<T1, T2> ||
349 internal::IsStrictlyBaseOfV<T2, T1>);
351 return member1.Get() == member2.Get();
355template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
356 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
357 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
358 typename StorageType>
360 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
361 StorageType>& member1,
362 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
363 StorageType>& member2) {
364 return !(member1 == member2);
368template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
369 typename CheckingPolicy,
typename StorageType,
typename U>
371 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
372 StorageType>& member,
375 static_assert(!internal::IsDecayedSameV<void, U>);
377 if constexpr (internal::IsDecayedSameV<T, U>) {
379 return member.GetRawStorage() == StorageType(raw);
380 }
else if constexpr (internal::IsStrictlyBaseOfV<T, U>) {
382 return member.GetRawStorage() == StorageType(
static_cast<T*
>(raw));
385 return member.Get() == raw;
389template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
390 typename CheckingPolicy,
typename StorageType,
typename U>
392 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
393 StorageType>& member,
395 return !(member == raw);
398template <
typename T,
typename U,
typename WeaknessTag,
399 typename WriteBarrierPolicy,
typename CheckingPolicy,
400 typename StorageType>
402 T* raw,
const BasicMember<U, WeaknessTag, WriteBarrierPolicy,
403 CheckingPolicy, StorageType>& member) {
404 return member == raw;
407template <
typename T,
typename U,
typename WeaknessTag,
408 typename WriteBarrierPolicy,
typename CheckingPolicy,
409 typename StorageType>
411 T* raw,
const BasicMember<U, WeaknessTag, WriteBarrierPolicy,
412 CheckingPolicy, StorageType>& member) {
413 return !(raw == member);
417template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
418 typename CheckingPolicy,
typename StorageType>
420 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
421 StorageType>& member,
423 return member.GetRawStorage().IsSentinel();
426template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
427 typename CheckingPolicy,
typename StorageType>
429 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
430 StorageType>& member,
432 return !(member == s);
435template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
436 typename CheckingPolicy,
typename StorageType>
439 CheckingPolicy, StorageType>& member) {
443template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
444 typename CheckingPolicy,
typename StorageType>
447 CheckingPolicy, StorageType>& member) {
448 return !(s == member);
452template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
453 typename CheckingPolicy,
typename StorageType>
455 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
456 StorageType>& member,
458 return !
static_cast<bool>(member);
461template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
462 typename CheckingPolicy,
typename StorageType>
464 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
465 StorageType>& member,
467 return !(member == n);
470template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
471 typename CheckingPolicy,
typename StorageType>
473 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
474 CheckingPolicy, StorageType>& member) {
478template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
479 typename CheckingPolicy,
typename StorageType>
481 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
482 CheckingPolicy, StorageType>& member) {
483 return !(n == member);
487template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
488 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
489 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
490 typename StorageType>
492 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
493 StorageType>& member1,
494 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
495 StorageType>& member2) {
497 internal::IsDecayedSameV<T1, T2>,
498 "Comparison works only for same pointer type modulo cv-qualifiers");
499 return member1.GetRawStorage() < member2.GetRawStorage();
502template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
503 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
504 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
505 typename StorageType>
507 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
508 StorageType>& member1,
509 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
510 StorageType>& member2) {
512 internal::IsDecayedSameV<T1, T2>,
513 "Comparison works only for same pointer type modulo cv-qualifiers");
514 return member1.GetRawStorage() <= member2.GetRawStorage();
517template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
518 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
519 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
520 typename StorageType>
522 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
523 StorageType>& member1,
524 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
525 StorageType>& member2) {
527 internal::IsDecayedSameV<T1, T2>,
528 "Comparison works only for same pointer type modulo cv-qualifiers");
529 return member1.GetRawStorage() > member2.GetRawStorage();
532template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
533 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
534 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
535 typename StorageType>
537 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
538 StorageType>& member1,
539 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
540 StorageType>& member2) {
542 internal::IsDecayedSameV<T1, T2>,
543 "Comparison works only for same pointer type modulo cv-qualifiers");
544 return member1.GetRawStorage() >= member2.GetRawStorage();
547template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy,
548 typename StorageType>
550 CheckingPolicy, StorageType>>
600#if defined(CPPGC_POINTER_COMPRESSION)
617static constexpr size_t kSizeOfMember =
sizeof(
Member<Dummy>);
618static constexpr size_t kSizeOfUncompressedMember =
620#if defined(CPPGC_POINTER_COMPRESSION)
621static constexpr size_t kSizeofCompressedMember =
622 sizeof(subtle::CompressedMember<Dummy>);
V8_INLINE BasicMember & operator=(BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &&other) noexcept
V8_INLINE BasicMember(T &raw)
V8_INLINE T * operator->() const
typename Base::RawStorage RawStorage
V8_INLINE constexpr BasicMember()=default
V8_INLINE BasicMember & operator=(T *other)
V8_INLINE BasicMember & operator=(const BasicPersistent< U, PersistentWeaknessPolicy, PersistentLocationPolicy, PersistentCheckingPolicy > &other)
V8_INLINE V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T *Get() const
V8_INLINE BasicMember(BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &&other) noexcept
V8_INLINE BasicMember(T &raw, AtomicInitializerTag atomic)
V8_INLINE RawStorage GetRawStorage() const
V8_INLINE void Swap(BasicMember< T, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
V8_INLINE BasicMember(const BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
V8_INLINE T & operator*() const
V8_INLINE BasicMember & operator=(const BasicMember &other)
V8_INLINE BasicMember(T *raw, AtomicInitializerTag atomic)
V8_INLINE const T ** GetSlotForTesting() const
V8_INLINE BasicMember & operator=(const BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
V8_INLINE BasicMember & operator=(std::nullptr_t)
V8_INLINE constexpr BasicMember(std::nullptr_t)
V8_INLINE BasicMember(BasicMember &&other) noexcept
V8_INLINE BasicMember & operator=(BasicMember &&other) noexcept
V8_INLINE BasicMember(std::nullptr_t, AtomicInitializerTag atomic)
V8_INLINE BasicMember(SentinelPointer s, AtomicInitializerTag atomic)
typename Base::AtomicInitializerTag AtomicInitializerTag
V8_INLINE BasicMember(T *raw)
V8_INLINE BasicMember & operator=(SentinelPointer s)
V8_INLINE BasicMember(const BasicMember &other)
V8_INLINE BasicMember(SentinelPointer s)
V8_INLINE BasicMember(const BasicPersistent< U, PersistentWeaknessPolicy, PersistentLocationPolicy, PersistentCheckingPolicy > &p)
V8_INLINE MemberBase(std::nullptr_t)
V8_INLINE MemberBase(const void *value)
V8_INLINE const void * GetRawAtomic() const
V8_INLINE RawStorage GetRawStorage() const
V8_INLINE const void * GetRaw() const
V8_INLINE void SetRawStorageAtomic(RawStorage other)
V8_INLINE void SetRaw(void *value)
V8_INLINE MemberBase(const void *value, AtomicInitializerTag)
V8_INLINE void ClearFromGC() const
V8_INLINE MemberBase()=default
V8_INLINE const void ** GetRawSlot() const
V8_INLINE bool IsCleared() const
V8_INLINE MemberBase(SentinelPointer s)
V8_INLINE void SetRawAtomic(const void *value)
V8_INLINE MemberBase(RawStorage raw)
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)
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)
V8_INLINE bool operator<=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
DisabledCheckingPolicy DefaultMemberCheckingPolicy
V8_INLINE bool operator>=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)