5#ifndef INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
6#define INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
43 return reinterpret_cast<std::atomic<PersistentNode*>*
>(&
node_)->load(
44 std::memory_order_acquire);
50#if defined(__has_feature)
51#if __has_feature(address_sanitizer)
57 __atomic_store(&
node_, &value, __ATOMIC_RELEASE);
61 reinterpret_cast<std::atomic<PersistentNode*>*
>(&
node_)->
store(
62 value, std::memory_order_release);
69template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
70 typename CheckingPolicy>
71class BasicCrossThreadPersistent final :
public CrossThreadPersistentBase,
72 public LocationPolicy,
73 private WeaknessPolicy,
74 private CheckingPolicy {
76 using typename WeaknessPolicy::IsStrongPersistent;
93 this->GetPersistentRegion(old_value);
107 : LocationPolicy(loc) {}
111 : LocationPolicy(loc) {}
124 this->CheckPointer(raw);
130 template <
typename U,
typename OtherWeaknessPolicy,
131 typename OtherLocationPolicy,
typename OtherCheckingPolicy>
142 this->CheckPointer(raw);
149 template <
typename U,
typename MemberBarrierPolicy,
150 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
151 typename MemberStorageType,
152 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
155 MemberCheckingPolicy, MemberStorageType>
169 template <
typename U,
typename OtherWeaknessPolicy,
170 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
171 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
175 OtherCheckingPolicy>& other,
185 *
this = std::move(other);
195 template <
typename U,
typename OtherWeaknessPolicy,
196 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
197 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
201 OtherCheckingPolicy>& other) {
208 if (
this == &other)
return *
this;
211 PersistentBase::operator=(std::move(other));
212 LocationPolicy::operator=(std::move(other));
215 other.SetValue(
nullptr);
216 other.SetNode(
nullptr);
217 this->CheckPointer(Get());
232 template <
typename U,
typename MemberBarrierPolicy,
233 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
234 typename MemberStorageType,
235 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
238 MemberCheckingPolicy, MemberStorageType>
275 return static_cast<T*
>(
const_cast<void*
>(
GetValue()));
306 explicit operator bool()
const {
return Get(); }
315 operator T*()
const {
return Get(); }
325 template <
typename U,
typename OtherWeaknessPolicy = WeaknessPolicy,
326 typename OtherLocationPolicy = LocationPolicy,
327 typename OtherCheckingPolicy = CheckingPolicy>
331 using OtherBasicCrossThreadPersistent =
333 OtherCheckingPolicy>;
335 return OtherBasicCrossThreadPersistent(
336 typename OtherBasicCrossThreadPersistent::UnsafeCtorTag(),
337 static_cast<U*
>(Get()));
340 template <
typename U =
T,
342 U, WeaknessPolicy>::IsStrongPersistent::value>::type>
367 this->GetPersistentRegion(old_value);
368 if (
IsValid(ptr) && (®ion == &this->GetPersistentRegion(ptr))) {
370 this->CheckPointer(ptr);
383 this->CheckPointer(ptr);
391 this->GetPersistentRegion(old_value);
392 if (
IsValid(ptr) && (®ion == &this->GetPersistentRegion(ptr))) {
394 this->CheckPointer(ptr);
403 this->CheckPointer(ptr);
407 if (
IsValid(GetValueFromGC())) {
408 WeaknessPolicy::GetPersistentRegion(GetValueFromGC())
417 return static_cast<T*
>(
const_cast<void*
>(GetValueFromGC()));
423template <
typename T,
typename LocationPolicy,
typename CheckingPolicy>
426 LocationPolicy, CheckingPolicy>>
BasicCrossThreadPersistent & operator=(const BasicCrossThreadPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other)
void AssignSafe(PersistentRegionLock &, T *ptr)
BasicCrossThreadPersistent(const SourceLocation &loc=SourceLocation::Current())
V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T *Get() const
void AssignUnsafe(T *ptr)
BasicCrossThreadPersistent(const BasicCrossThreadPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > &other, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent(const BasicCrossThreadPersistent &other, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent & operator=(T *other)
BasicCrossThreadPersistent & operator=(BasicCrossThreadPersistent &&other)
~BasicCrossThreadPersistent()
static bool IsValid(const void *ptr)
BasicCrossThreadPersistent< U, internal::StrongCrossThreadPersistentPolicy > Lock() const
static void TraceAsRoot(RootVisitor &root_visitor, const void *ptr)
BasicCrossThreadPersistent(SentinelPointer s, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent(std::nullptr_t, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent(T &raw, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent< U, OtherWeaknessPolicy, OtherLocationPolicy, OtherCheckingPolicy > To() const
BasicCrossThreadPersistent(BasicCrossThreadPersistent &&other, const SourceLocation &loc=SourceLocation::Current()) noexcept
BasicCrossThreadPersistent & operator=(std::nullptr_t)
BasicCrossThreadPersistent(UnsafeCtorTag, T *raw, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent(internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > member, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent & operator=(const BasicCrossThreadPersistent &other)
BasicCrossThreadPersistent & operator=(internal::BasicMember< U, MemberBarrierPolicy, MemberWeaknessTag, MemberCheckingPolicy, MemberStorageType > member)
BasicCrossThreadPersistent(T *raw, const SourceLocation &loc=SourceLocation::Current())
BasicCrossThreadPersistent & operator=(SentinelPointer s)
PersistentNode * GetNodeFromGC() const
CrossThreadPersistentBase(const void *raw)
V8_CLANG_NO_SANITIZE("address") const void *GetValueFromGC() const
void SetNodeSafe(PersistentNode *value) const
CrossThreadPersistentBase()=default
PersistentNode * GetNodeSafe() const
const void * GetValue() const
void SetValue(const void *value)
PersistentNode * GetNode() const
void SetNode(PersistentNode *node)
void UpdateOwner(void *owner)
static void AssertLocked()
void Trace(const AnyStrongPersistentType &p)
static constexpr SourceLocation Current()
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats store(v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) DEFINE_GENERIC_IMPLICATION(trace_gc_object_stats
#define CPPGC_DCHECK(condition)
ZoneVector< RpoNumber > & result
constexpr internal::SentinelPointer kSentinelPointer
#define V8_CLANG_NO_SANITIZE(what)
defined(V8_TRIVIAL_ABI)