5#ifndef V8_HEAP_SWEEPER_H_
6#define V8_HEAP_SWEEPER_H_
11#include <unordered_map>
12#include <unordered_set>
28class MutablePageMetadata;
29class NonAtomicMarkingState;
31class LargePageMetadata;
79 uint32_t max_pages = std::numeric_limits<uint32_t>::max());
93 template <
typename ShouldYieldCallback>
95 ShouldYieldCallback should_yield_callback);
96 template <
typename ShouldYieldCallback>
98 ShouldYieldCallback should_yield_callback);
131 uint32_t max_pages = std::numeric_limits<uint32_t>::max());
169 bool is_joining_thread);
182 bool HasUnsweptPagesForMajorSweeping()
const;
200 class ConcurrentMajorSweeper;
201 class ConcurrentMinorSweeper;
203 class MajorSweeperJob;
204 class MinorSweeperJob;
209 template <
typename Callback>
228 bool should_reduce_memory);
274 template <SweepingScope scope>
345template <
typename ShouldYieldCallback>
347 ShouldYieldCallback should_yield_callback) {
355 if (should_yield_callback()) {
363template <
typename ShouldYieldCallback>
365 ShouldYieldCallback should_yield_callback) {
366 while (!should_yield_callback()) {
368 if (chunk ==
nullptr)
return true;
369 ParallelIteratePromotedPage(chunk);
bool ParallelIteratePromotedPagesImpl(ShouldYieldCallback should_yield_callback)
bool ContributeAndWaitForPromotedPagesIterationImpl(ShouldYieldCallback should_yield_callback)
void ParallelSweepPage(PageMetadata *page, AllocationSpace identity, SweepingMode sweeping_mode)
bool ParallelIteratePromotedPages()
bool ContributeAndWaitForPromotedPagesIteration()
bool ParallelSweepSpace(AllocationSpace identity, SweepingMode sweeping_mode, uint32_t max_pages=std::numeric_limits< uint32_t >::max())
LocalSweeper(Sweeper *sweeper)
void ParallelIteratePromotedPage(MutablePageMetadata *page)
const bool resume_on_exit_
SweepingState(Sweeper *sweeper)
bool should_reduce_memory_
std::atomic< bool > in_progress_
void InitializeSweeping()
uint64_t background_trace_id() const
std::vector< ConcurrentSweeper > & concurrent_sweepers()
std::vector< ConcurrentSweeper > concurrent_sweepers_
std::unique_ptr< JobHandle > job_handle_
bool should_reduce_memory() const
uint64_t trace_id() const
bool HasActiveJob() const
void StopConcurrentSweeping()
void StartConcurrentSweeping()
typename std::conditional< scope==SweepingScope::kMinor, ConcurrentMinorSweeper, ConcurrentMajorSweeper >::type ConcurrentSweeper
uint64_t background_trace_id_
typename std::conditional< scope==SweepingScope::kMinor, MinorSweeperJob, MajorSweeperJob >::type SweeperJob
bool sweeping_in_progress() const
bool sweeping_in_progress_for_space(AllocationSpace space) const
void EnsureMajorCompleted()
void InitializeMinorSweeping()
static int GetSweepSpaceIndex(AllocationSpace space)
bool AreMajorSweeperTasksRunning() const
SweptList GetAllSweptPagesSafe(PagedSpaceBase *space)
V8_EXPORT_PRIVATE void StartMajorSweeperTasks()
static constexpr int kNumberOfSweepingSpaces
PageMetadata * GetSweptPageSafe(PagedSpaceBase *space)
bool ShouldRefillFreelistForSpace(AllocationSpace space) const
bool TryRemovePromotedPageSafe(MutablePageMetadata *chunk)
base::ConditionVariable cv_page_swept_
static V8_EXPORT_PRIVATE std::optional< base::AddressRegion > ComputeDiscardMemoryArea(Address start, Address end)
static bool IsValidSweepingSpace(AllocationSpace space)
MutablePageMetadata * GetPromotedPageSafe()
void PrepareToBeSweptPage(AllocationSpace space, PageMetadata *page)
void CleanupRememberedSetEntriesForFreedMemory(Address free_start, Address free_end, PageMetadata *page, bool record_free_ranges, TypedSlotSet::FreeRangesMap *free_ranges_map, SweepingMode sweeping_mode)
void ContributeAndWaitForPromotedPagesIteration()
void AddNewSpacePage(PageMetadata *page)
uint64_t GetTraceIdForFlowEvent(GCTracer::Scope::ScopeId scope_id) const
size_t promoted_pages_for_iteration_count_
base::ConditionVariable promoted_pages_iteration_notification_variable_
bool major_sweeping_in_progress() const
void ZeroOrDiscardUnusedMemory(PageMetadata *page, Address addr, size_t size)
void StartMajorSweeping()
bool minor_sweeping_in_progress() const
void NotifyPromotedPagesIterationFinished()
void InitializeMajorSweeping()
size_t ConcurrentMinorSweepingPageCount()
NonAtomicMarkingState *const marking_state_
void ClearMarkBitsAndHandleLivenessStatistics(PageMetadata *page, size_t live_bytes)
bool TryRemoveSweepingPageSafe(AllocationSpace space, PageMetadata *page)
SweepingState< SweepingScope::kMajor > major_sweeping_state_
bool IsSweepingDoneForSpace(AllocationSpace space) const
bool ParallelSweepSpace(AllocationSpace identity, SweepingMode sweeping_mode, uint32_t max_pages=std::numeric_limits< uint32_t >::max())
size_t ConcurrentMajorSweepingPageCount()
void StartMinorSweeping()
std::atomic< bool > has_swept_pages_[kNumberOfSweepingSpaces]
void EnsurePageIsSwept(PageMetadata *page)
NonAtomicMarkingState * marking_state() const
std::atomic< size_t > iterated_promoted_pages_count_
std::atomic< bool > promoted_page_iteration_in_progress_
PageMetadata * GetSweepingPageSafe(AllocationSpace space)
V8_EXPORT_PRIVATE void StartMinorSweeperTasks()
void ForAllSweepingSpaces(Callback callback) const
void CleanupTypedSlotsInFreeMemory(PageMetadata *page, const TypedSlotSet::FreeRangesMap &free_ranges_map, SweepingMode sweeping_mode)
bool AreMinorSweeperTasksRunning() const
SweepingState< SweepingScope::kMinor > minor_sweeping_state_
std::vector< MutablePageMetadata * > sweeping_list_for_promoted_page_iteration_
size_t FreeAndProcessFreedMemory(Address free_start, Address free_end, PageMetadata *page, Space *space, FreeSpaceTreatmentMode free_space_treatment_mode, bool should_reduce_memory)
void AddSweptPage(PageMetadata *page, AllocationSpace identity)
bool IsIteratingPromotedPages() const
void SweepEmptyNewSpacePage(PageMetadata *page)
SweptList swept_list_[kNumberOfSweepingSpaces]
void NotifyPromotedPageIterationFinished(MutablePageMetadata *chunk)
void AddPageImpl(AllocationSpace space, PageMetadata *page)
void WaitForPageToBeSwept(PageMetadata *page)
void AddPromotedPage(MutablePageMetadata *chunk)
base::Mutex promoted_pages_iteration_notification_mutex_
std::atomic< bool > has_sweeping_work_[kNumberOfSweepingSpaces]
void RawSweep(PageMetadata *p, FreeSpaceTreatmentMode free_space_treatment_mode, SweepingMode sweeping_mode, bool should_reduce_memory)
SweepingList sweeping_list_[kNumberOfSweepingSpaces]
void PrepareToBeIteratedPromotedPage(PageMetadata *page)
std::vector< PageMetadata * > SweepingList
bool UsingMajorSweeperTasks() const
LocalSweeper main_thread_local_sweeper_
void EnsureMinorCompleted()
GCTracer::Scope::ScopeId GetTracingScope(AllocationSpace space, bool is_joining_thread)
std::vector< PageMetadata * > SweptList
void AddPage(AllocationSpace space, PageMetadata *page)
std::map< uint32_t, uint32_t > FreeRangesMap
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)
#define V8_EXPORT_PRIVATE