5#ifndef INCLUDE_CPPGC_MEMBER_H_
6#define INCLUDE_CPPGC_MEMBER_H_
31template <
typename StorageType>
49 return reinterpret_cast<const void**
>(
const_cast<MemberBase*
>(
this));
59 reinterpret_cast<std::atomic<RawStorage>&
>(raw_).store(
60 other, std::memory_order_relaxed);
68 friend class MemberDebugHelper;
74template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
75 typename CheckingPolicy,
typename StorageType>
77 private CheckingPolicy {
88 InitializingWriteBarrier(raw);
99 :
Base(nullptr, atomic) {}
103 :
Base(raw, atomic) {
104 InitializingWriteBarrier(raw);
117 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
118 typename OtherCheckingPolicy,
119 std::enable_if_t<IsDecayedSameV<T, U>>* =
nullptr>
121 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
122 OtherCheckingPolicy, StorageType>& other)
125 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
126 typename OtherCheckingPolicy,
127 std::enable_if_t<IsStrictlyBaseOfV<T, U>>* =
nullptr>
129 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
130 OtherCheckingPolicy, StorageType>& other)
142 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
143 typename OtherCheckingPolicy,
144 std::enable_if_t<IsDecayedSameV<T, U>>* =
nullptr>
146 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
147 StorageType>&& other) noexcept
152 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
153 typename OtherCheckingPolicy,
154 std::enable_if_t<IsStrictlyBaseOfV<T, U>>* =
nullptr>
156 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
157 StorageType>&& other) noexcept
163 template <
typename U,
typename PersistentWeaknessPolicy,
164 typename PersistentLocationPolicy,
165 typename PersistentCheckingPolicy,
166 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
168 PersistentLocationPolicy,
169 PersistentCheckingPolicy>& p)
180 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
181 typename OtherCheckingPolicy>
183 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
184 OtherCheckingPolicy, StorageType>& other) {
185 if constexpr (IsDecayedSameV<T, U>) {
186 return operator=(other.GetRawStorage());
188 static_assert(IsStrictlyBaseOfV<T, U>);
189 return operator=(other.Get());
195 operator=(other.GetRawStorage());
203 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
204 typename OtherCheckingPolicy>
206 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy,
207 StorageType>&& other)
noexcept {
208 if constexpr (IsDecayedSameV<T, U>) {
209 operator=(other.GetRawStorage());
211 static_assert(IsStrictlyBaseOfV<T, U>);
212 operator=(other.Get());
219 template <
typename U,
typename PersistentWeaknessPolicy,
220 typename PersistentLocationPolicy,
221 typename PersistentCheckingPolicy,
222 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
225 PersistentLocationPolicy, PersistentCheckingPolicy>&
227 return operator=(other.Get());
231 Base::SetRawAtomic(other);
232 AssigningWriteBarrier(other);
242 Base::SetRawAtomic(s);
246 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
247 typename OtherCheckingPolicy>
249 OtherCheckingPolicy, StorageType>& other) {
250 auto tmp = GetRawStorage();
255 V8_INLINE explicit operator bool()
const {
return !Base::IsCleared(); }
269 return static_cast<T*
>(
const_cast<void*
>(Base::GetRaw()));
281 return reinterpret_cast<const T**
>(Base::GetRawSlot());
288 InitializingWriteBarrier();
292 V8_INLINE BasicMember& operator=(RawStorage other) {
293 Base::SetRawStorageAtomic(other);
294 AssigningWriteBarrier();
299 V8_INLINE const T* GetRawAtomic()
const {
300 return static_cast<const T*
>(Base::GetRawAtomic());
303 V8_INLINE void InitializingWriteBarrier(T* value)
const {
304 WriteBarrierPolicy::InitializingBarrier(Base::GetRawSlot(), value);
306 V8_INLINE void InitializingWriteBarrier()
const {
307 WriteBarrierPolicy::InitializingBarrier(Base::GetRawSlot(),
308 Base::GetRawStorage());
310 V8_INLINE void AssigningWriteBarrier(T* value)
const {
311 WriteBarrierPolicy::template AssigningBarrier<
312 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(), value);
314 V8_INLINE void AssigningWriteBarrier()
const {
315 WriteBarrierPolicy::template AssigningBarrier<
316 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(),
317 Base::GetRawStorage());
320 CheckingPolicy::template CheckPointer<T>(value);
323 CheckingPolicy::template CheckPointer<T>(Base::GetRawStorage());
326 V8_INLINE void ClearFromGC()
const { Base::ClearFromGC(); }
328 V8_INLINE T* GetFromGC()
const {
return Get(); }
332 template <
typename U>
334 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
335 typename CheckingPolicy1,
typename StorageType1>
340template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
341 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
342 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
343 typename StorageType>
345 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
346 StorageType>& member1,
347 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
348 StorageType>& member2) {
349 if constexpr (IsDecayedSameV<T1, T2>) {
351 return member1.GetRawStorage() == member2.GetRawStorage();
353 static_assert(IsStrictlyBaseOfV<T1, T2> || IsStrictlyBaseOfV<T2, T1>);
355 return member1.Get() == member2.Get();
359template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
360 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
361 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
362 typename StorageType>
364 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
365 StorageType>& member1,
366 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
367 StorageType>& member2) {
368 return !(member1 == member2);
372template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
373 typename CheckingPolicy,
typename StorageType,
typename U>
375 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
376 StorageType>& member,
379 static_assert(!IsDecayedSameV<void, U>);
381 if constexpr (IsDecayedSameV<T, U>) {
383 return member.GetRawStorage() == StorageType(raw);
384 }
else if constexpr (IsStrictlyBaseOfV<T, U>) {
386 return member.GetRawStorage() == StorageType(
static_cast<T*
>(raw));
389 return member.Get() == raw;
393template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
394 typename CheckingPolicy,
typename StorageType,
typename U>
396 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
397 StorageType>& member,
399 return !(member == raw);
402template <
typename T,
typename U,
typename WeaknessTag,
403 typename WriteBarrierPolicy,
typename CheckingPolicy,
404 typename StorageType>
406 T* raw,
const BasicMember<U, WeaknessTag, WriteBarrierPolicy,
407 CheckingPolicy, StorageType>& member) {
408 return member == raw;
411template <
typename T,
typename U,
typename WeaknessTag,
412 typename WriteBarrierPolicy,
typename CheckingPolicy,
413 typename StorageType>
415 T* raw,
const BasicMember<U, WeaknessTag, WriteBarrierPolicy,
416 CheckingPolicy, StorageType>& member) {
417 return !(raw == member);
421template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
422 typename CheckingPolicy,
typename StorageType>
424 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
425 StorageType>& member,
427 return member.GetRawStorage().IsSentinel();
430template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
431 typename CheckingPolicy,
typename StorageType>
433 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
434 StorageType>& member,
436 return !(member == s);
439template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
440 typename CheckingPolicy,
typename StorageType>
443 CheckingPolicy, StorageType>& member) {
447template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
448 typename CheckingPolicy,
typename StorageType>
451 CheckingPolicy, StorageType>& member) {
452 return !(s == member);
456template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
457 typename CheckingPolicy,
typename StorageType>
459 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
460 StorageType>& member,
462 return !
static_cast<bool>(member);
465template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
466 typename CheckingPolicy,
typename StorageType>
468 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
469 StorageType>& member,
471 return !(member == n);
474template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
475 typename CheckingPolicy,
typename StorageType>
477 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
478 CheckingPolicy, StorageType>& member) {
482template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
483 typename CheckingPolicy,
typename StorageType>
485 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
486 CheckingPolicy, StorageType>& member) {
487 return !(n == member);
491template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
492 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
493 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
494 typename StorageType>
496 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
497 StorageType>& member1,
498 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
499 StorageType>& member2) {
501 IsDecayedSameV<T1, T2>,
502 "Comparison works only for same pointer type modulo cv-qualifiers");
503 return member1.GetRawStorage() < member2.GetRawStorage();
506template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
507 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
508 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
509 typename StorageType>
511 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
512 StorageType>& member1,
513 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
514 StorageType>& member2) {
516 IsDecayedSameV<T1, T2>,
517 "Comparison works only for same pointer type modulo cv-qualifiers");
518 return member1.GetRawStorage() <= member2.GetRawStorage();
521template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
522 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
523 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
524 typename StorageType>
526 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
527 StorageType>& member1,
528 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
529 StorageType>& member2) {
531 IsDecayedSameV<T1, T2>,
532 "Comparison works only for same pointer type modulo cv-qualifiers");
533 return member1.GetRawStorage() > member2.GetRawStorage();
536template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
537 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
538 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
539 typename StorageType>
541 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
542 StorageType>& member1,
543 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
544 StorageType>& member2) {
546 IsDecayedSameV<T1, T2>,
547 "Comparison works only for same pointer type modulo cv-qualifiers");
548 return member1.GetRawStorage() >= member2.GetRawStorage();
551template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy,
552 typename StorageType>
554 StorageType>> : std::true_type {};
603#if defined(CPPGC_POINTER_COMPRESSION)
620static constexpr size_t kSizeOfMember =
sizeof(
Member<Dummy>);
621static constexpr size_t kSizeOfUncompressedMember =
623#if defined(CPPGC_POINTER_COMPRESSION)
624static constexpr size_t kSizeofCompressedMember =
625 sizeof(subtle::CompressedMember<Dummy>);
642template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
643 typename CheckingPolicy,
typename StorageType,
644 template <
typename>
typename TQ,
template <
typename>
typename UQ>
645struct std::basic_common_reference<
646 cppgc::internal::BasicMember<T, WeaknessTag, WriteBarrierPolicy,
647 CheckingPolicy, StorageType>,
652template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
653 typename CheckingPolicy,
typename StorageType,
654 template <
typename>
typename TQ,
template <
typename>
typename UQ>
655struct std::basic_common_reference<
658 CheckingPolicy, StorageType>,
BasicMember & operator=(const BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
Definition: member.h:182
T PointeeType
Definition: member.h:81
BasicMember & operator=(BasicMember &&other) noexcept
Definition: member.h:194
T & operator*() const
Definition: member.h:258
BasicMember(SentinelPointer s)
Definition: member.h:86
BasicMember(T *raw)
Definition: member.h:87
BasicMember & operator=(T *other)
Definition: member.h:230
void Clear()
Definition: member.h:272
T * operator->() const
Definition: member.h:257
constexpr BasicMember()=default
BasicMember & operator=(const BasicMember &other)
Definition: member.h:173
const T ** GetSlotForTesting() const
Definition: member.h:280
BasicMember(SentinelPointer s, AtomicInitializerTag atomic)
Definition: member.h:100
RawStorage GetRawStorage() const
Definition: member.h:284
BasicMember & operator=(BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &&other) noexcept
Definition: member.h:205
BasicMember(const BasicPersistent< U, PersistentWeaknessPolicy, PersistentLocationPolicy, PersistentCheckingPolicy > &p)
Definition: member.h:167
BasicMember(T &raw)
Definition: member.h:91
BasicMember(T *raw, AtomicInitializerTag atomic)
Definition: member.h:102
BasicMember(const BasicMember &other)
Definition: member.h:111
BasicMember & operator=(std::nullptr_t)
Definition: member.h:237
BasicMember(const BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
Definition: member.h:120
T * Release()
Definition: member.h:274
void Swap(BasicMember< T, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &other)
Definition: member.h:248
typename Base::RawStorage RawStorage
Definition: member.h:82
BasicMember(T &raw, AtomicInitializerTag atomic)
Definition: member.h:107
BasicMember(BasicMember &&other) noexcept
Definition: member.h:134
constexpr BasicMember(std::nullptr_t)
Definition: member.h:85
BasicMember(BasicMember< U, OtherWeaknessTag, OtherBarrierPolicy, OtherCheckingPolicy, StorageType > &&other) noexcept
Definition: member.h:145
BasicMember & operator=(const BasicPersistent< U, PersistentWeaknessPolicy, PersistentLocationPolicy, PersistentCheckingPolicy > &other)
Definition: member.h:223
BasicMember & operator=(SentinelPointer s)
Definition: member.h:241
typename Base::AtomicInitializerTag AtomicInitializerTag
Definition: member.h:97
BasicMember(std::nullptr_t, AtomicInitializerTag atomic)
Definition: member.h:98
Definition: persistent.h:54
MemberBase(RawStorage raw)
Definition: member.h:44
MemberBase(SentinelPointer s)
Definition: member.h:46
const void * GetRawAtomic() const
Definition: member.h:54
void SetRawStorageAtomic(RawStorage other)
Definition: member.h:58
MemberBase(std::nullptr_t)
Definition: member.h:45
void SetRaw(void *value)
Definition: member.h:52
MemberBase(const void *value)
Definition: member.h:40
MemberBase(const void *value, AtomicInitializerTag)
Definition: member.h:41
const void * GetRaw() const
Definition: member.h:51
bool IsCleared() const
Definition: member.h:63
void SetRawAtomic(const void *value)
Definition: member.h:55
StorageType RawStorage
Definition: member.h:34
void ClearFromGC() const
Definition: member.h:65
RawStorage GetRawStorage() const
Definition: member.h:57
const void ** GetRawSlot() const
Definition: member.h:48
Definition: member-storage.h:192
Definition: heap-consistency.h:28
bool operator<=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:510
bool operator!=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:363
bool operator>(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:525
bool operator==(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:344
bool operator>=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:540
bool operator<(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:495
DisabledCheckingPolicy DefaultMemberCheckingPolicy
Definition: pointer-policies.h:196
Definition: allocation.h:38
Definition: trace-trait.h:105
Definition: pointer-policies.h:30
Definition: type-traits.h:30
Definition: pointer-policies.h:108
Definition: sentinel-pointer.h:17
T * type
Definition: member.h:660
T * type
Definition: member.h:649
#define V8_INLINE
Definition: v8config.h:499
#define V8_CLANG_NO_SANITIZE(what)
defined(V8_TRIVIAL_ABI)
Definition: v8config.h:754
#define V8_TRIVIAL_ABI
Definition: v8config.h:743