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<internal::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<internal::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<internal::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<internal::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 (internal::IsDecayedSameV<T, U>) {
186 return operator=(other.GetRawStorage());
188 static_assert(internal::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 (internal::IsDecayedSameV<T, U>) {
209 operator=(other.GetRawStorage());
211 static_assert(internal::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()));
283 return reinterpret_cast<const T**
>(Base::GetRawSlot());
287 return Base::GetRawStorage();
292 InitializingWriteBarrier();
296 V8_INLINE BasicMember& operator=(RawStorage other) {
297 Base::SetRawStorageAtomic(other);
298 AssigningWriteBarrier();
303 V8_INLINE const T* GetRawAtomic()
const {
304 return static_cast<const T*
>(Base::GetRawAtomic());
307 V8_INLINE void InitializingWriteBarrier(T* value)
const {
308 WriteBarrierPolicy::InitializingBarrier(Base::GetRawSlot(), value);
310 V8_INLINE void InitializingWriteBarrier()
const {
311 WriteBarrierPolicy::InitializingBarrier(Base::GetRawSlot(),
312 Base::GetRawStorage());
314 V8_INLINE void AssigningWriteBarrier(T* value)
const {
315 WriteBarrierPolicy::template AssigningBarrier<
316 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(), value);
318 V8_INLINE void AssigningWriteBarrier()
const {
319 WriteBarrierPolicy::template AssigningBarrier<
320 StorageType::kWriteBarrierSlotType>(Base::GetRawSlot(),
321 Base::GetRawStorage());
324 CheckingPolicy::template CheckPointer<T>(value);
327 CheckingPolicy::template CheckPointer<T>(Base::GetRawStorage());
330 V8_INLINE void ClearFromGC()
const { Base::ClearFromGC(); }
332 V8_INLINE T* GetFromGC()
const {
return Get(); }
336 template <
typename U>
338 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
339 typename CheckingPolicy1,
typename StorageType1>
344template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
345 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
346 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
347 typename StorageType>
349 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
350 StorageType>& member1,
351 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
352 StorageType>& member2) {
353 if constexpr (internal::IsDecayedSameV<T1, T2>) {
355 return member1.GetRawStorage() == member2.GetRawStorage();
357 static_assert(internal::IsStrictlyBaseOfV<T1, T2> ||
358 internal::IsStrictlyBaseOfV<T2, T1>);
360 return member1.Get() == member2.Get();
364template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
365 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
366 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
367 typename StorageType>
369 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
370 StorageType>& member1,
371 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
372 StorageType>& member2) {
373 return !(member1 == member2);
377template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
378 typename CheckingPolicy,
typename StorageType,
typename U>
380 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
381 StorageType>& member,
384 static_assert(!internal::IsDecayedSameV<void, U>);
386 if constexpr (internal::IsDecayedSameV<T, U>) {
388 return member.GetRawStorage() == StorageType(raw);
389 }
else if constexpr (internal::IsStrictlyBaseOfV<T, U>) {
391 return member.GetRawStorage() == StorageType(
static_cast<T*
>(raw));
394 return member.Get() == raw;
398template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
399 typename CheckingPolicy,
typename StorageType,
typename U>
401 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
402 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 member == raw;
416template <
typename T,
typename U,
typename WeaknessTag,
417 typename WriteBarrierPolicy,
typename CheckingPolicy,
418 typename StorageType>
420 T* raw,
const BasicMember<U, WeaknessTag, WriteBarrierPolicy,
421 CheckingPolicy, StorageType>& member) {
422 return !(raw == member);
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.GetRawStorage().IsSentinel();
435template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
436 typename CheckingPolicy,
typename StorageType>
438 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
439 StorageType>& member,
441 return !(member == s);
444template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
445 typename CheckingPolicy,
typename StorageType>
448 CheckingPolicy, StorageType>& member) {
452template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
453 typename CheckingPolicy,
typename StorageType>
456 CheckingPolicy, StorageType>& member) {
457 return !(s == 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 !
static_cast<bool>(member);
470template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
471 typename CheckingPolicy,
typename StorageType>
473 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
474 StorageType>& member,
476 return !(member == n);
479template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
480 typename CheckingPolicy,
typename StorageType>
482 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
483 CheckingPolicy, StorageType>& member) {
487template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
488 typename CheckingPolicy,
typename StorageType>
490 std::nullptr_t n,
const BasicMember<T, WeaknessTag, WriteBarrierPolicy,
491 CheckingPolicy, StorageType>& member) {
492 return !(n == member);
496template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
497 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
498 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
499 typename StorageType>
501 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
502 StorageType>& member1,
503 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
504 StorageType>& member2) {
506 internal::IsDecayedSameV<T1, T2>,
507 "Comparison works only for same pointer type modulo cv-qualifiers");
508 return member1.GetRawStorage() < member2.GetRawStorage();
511template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
512 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
513 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
514 typename StorageType>
516 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
517 StorageType>& member1,
518 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
519 StorageType>& member2) {
521 internal::IsDecayedSameV<T1, T2>,
522 "Comparison works only for same pointer type modulo cv-qualifiers");
523 return member1.GetRawStorage() <= member2.GetRawStorage();
526template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
527 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
528 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
529 typename StorageType>
531 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
532 StorageType>& member1,
533 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
534 StorageType>& member2) {
536 internal::IsDecayedSameV<T1, T2>,
537 "Comparison works only for same pointer type modulo cv-qualifiers");
538 return member1.GetRawStorage() > member2.GetRawStorage();
541template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
542 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
543 typename WriteBarrierPolicy2,
typename CheckingPolicy2,
544 typename StorageType>
546 const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1,
547 StorageType>& member1,
548 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2,
549 StorageType>& member2) {
551 internal::IsDecayedSameV<T1, T2>,
552 "Comparison works only for same pointer type modulo cv-qualifiers");
553 return member1.GetRawStorage() >= member2.GetRawStorage();
556template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy,
557 typename StorageType>
559 CheckingPolicy, StorageType>>
609#if defined(CPPGC_POINTER_COMPRESSION)
626static constexpr size_t kSizeOfMember =
sizeof(
Member<Dummy>);
627static constexpr size_t kSizeOfUncompressedMember =
629#if defined(CPPGC_POINTER_COMPRESSION)
630static constexpr size_t kSizeofCompressedMember =
631 sizeof(subtle::CompressedMember<Dummy>);
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:282
BasicMember(SentinelPointer s, AtomicInitializerTag atomic)
Definition: member.h:100
RawStorage GetRawStorage() const
Definition: member.h:286
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:276
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:203
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:515
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:530
bool operator==(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:348
bool operator>=(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:545
bool operator<(const BasicMember< T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1, StorageType > &member1, const BasicMember< T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2, StorageType > &member2)
Definition: member.h:500
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:29
Definition: pointer-policies.h:108
Definition: sentinel-pointer.h:17
#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