56 std::unique_ptr<PersistentHandles> persistent_handles =
nullptr);
62 DCHECK(AllowSafepoints::IsAllowed());
65 if (
V8_UNLIKELY(current.IsRunningWithSlowPathFlag())) {
74 if (!persistent_handles_) {
75 EnsurePersistentHandles();
77 return persistent_handles_->NewHandle(
object);
80 template <
typename T,
template <
typename>
typename HandleType>
84 return NewPersistentHandle(*
object);
89 static_assert(kTaggedCanConvertToRawObjects);
90 return NewPersistentHandle(
Tagged<T>(
object));
93 template <
typename T,
template <
typename>
typename MaybeHandleType>
95 MaybeHandleType<T> maybe_handle)
99 if (maybe_handle.ToHandle(&
handle)) {
100 return NewPersistentHandle(
handle);
105 void AttachPersistentHandles(
106 std::unique_ptr<PersistentHandles> persistent_handles);
107 std::unique_ptr<PersistentHandles> DetachPersistentHandles();
109 bool HasPersistentHandles() {
return !!persistent_handles_; }
110 bool ContainsPersistentHandle(Address* location);
111 bool ContainsLocalHandle(Address* location);
112 bool IsHandleDereferenceAllowed();
115 bool IsParked()
const;
116 bool IsRunning()
const;
126#define ROOT_ACCESSOR(type, name, CamelName) inline Tagged<type> name();
133 void FreeLinearAllocationAreas();
136 void VerifyLinearAllocationAreas()
const;
140 void MakeLinearAllocationAreasIterable();
144 void MarkLinearAllocationAreasBlack();
145 void UnmarkLinearAllocationsArea();
149 void MarkSharedLinearAllocationAreasBlack();
150 void UnmarkSharedLinearAllocationsArea();
154 void FreeLinearAllocationAreasAndResetFreeLists();
155 void FreeSharedLinearAllocationAreasAndResetFreeLists();
164 static void SetCurrent(
LocalHeap* local_heap);
167 void VerifyCurrent()
const;
177 template <HeapAllocator::AllocationRetryMode mode>
196 return is_main_thread() &&
heap_ ==
heap;
201 return heap_->deserialization_complete();
209 void AddGCEpilogueCallback(GCEpilogueCallback*
callback,
void* data,
211 GCCallbacksInSafepoint::GCType::kAll);
212 void RemoveGCEpilogueCallback(GCEpilogueCallback*
callback,
void* data);
215 void WeakenDescriptorArrays(
219 void SetUpMainThreadForTesting();
227 template <
typename Callback>
229 template <
typename Callback>
231 template <
typename Callback>
235 pthread_t thread_handle() {
return thread_handle_; }
252 constexpr bool IsRunning()
const {
return !ParkedBit::decode(raw_state_); }
255 return ThreadState(raw_state_ & ~ParkedBit::kMask);
258 constexpr bool IsParked()
const {
return ParkedBit::decode(raw_state_); }
265 return SafepointRequestedBit::decode(raw_state_);
269 return CollectionRequestedBit::decode(raw_state_);
273 return IsRunning() && (raw_state_ & (SafepointRequestedBit::kMask |
274 CollectionRequestedBit::kMask));
278 constexpr explicit ThreadState(uint8_t value) : raw_state_(value) {}
280 constexpr uint8_t
raw()
const {
return raw_state_; }
290 : raw_state_(state.raw()) {}
293 return raw_state_.compare_exchange_strong(expected.
raw_state_,
298 return raw_state_.compare_exchange_weak(expected.
raw_state_,
303 return ThreadState(raw_state_.fetch_or(ParkedBit::kMask));
307 return ThreadState(raw_state_.fetch_or(SafepointRequestedBit::kMask));
311 return ThreadState(raw_state_.fetch_and(~SafepointRequestedBit::kMask));
315 return ThreadState(raw_state_.fetch_or(CollectionRequestedBit::kMask));
319 return ThreadState(raw_state_.fetch_and(~CollectionRequestedBit::kMask));
323 return ThreadState(raw_state_.load(std::memory_order_relaxed));
331 bool IsSafeForConservativeStackScanning()
const;
334 template <
typename Callback>
338 DCHECK(AllowSafepoints::IsAllowed());
339 DCHECK(IsSafeForConservativeStackScanning());
341 if (!
state_.CompareExchangeWeak(expected, ThreadState::Parked())) {
347 DCHECK(AllowSafepoints::IsAllowed());
349 if (!
state_.CompareExchangeWeak(expected, ThreadState::Running())) {
355 void UnparkSlowPath();
356 void EnsureParkedBeforeDestruction();
357 void SafepointSlowPath();
358 void SleepInSafepoint();
359 void SleepInUnpark();
361 template <
typename Callback>
364 void EnsurePersistentHandles();
366 void InvokeGCEpilogueCallbacksInSafepoint(
373 void SetUpMarkingBarrier();
374 void SetUpSharedMarking();
383 pthread_t thread_handle_;