48 page->list_node().Initialize();
49 CHECK(page->IsLivenessClear());
63 page->ClearLiveness();
75 const size_t quarantined_pages =
78 const int pages_available_for_allocation =
81 pages_available_for_allocation;
119 if (new_page ==
nullptr) {
126 static_cast<int>(new_page->
area_size()));
134 size_t uncommitted_physical_memory = 0;
135 while (num_pages > 0) {
138 uncommitted_physical_memory += last->CommittedPhysicalMemory();
147 const auto to_space_flags =
149 heap()->incremental_marking()->marking_mode()) |
153 page->set_owner(
this);
169 if (page->prev_page()) {
179 type, page->ExternalBackingStoreBytes(type));
192 std::swap(from->memory_chunk_list_, to->memory_chunk_list_);
193 std::swap(from->current_page_, to->current_page_);
196 const size_t tmp = from->external_backing_store_bytes_[
index].load(
197 std::memory_order_relaxed);
198 from->external_backing_store_bytes_[
index].store(
199 to->external_backing_store_bytes_[index].load(
200 std::memory_order_relaxed),
201 std::memory_order_relaxed);
202 to->external_backing_store_bytes_[
index].store(
203 tmp, std::memory_order_relaxed);
205 std::swap(from->committed_physical_memory_, to->committed_physical_memory_);
208 size_t to_commited = to->committed_.load();
209 to->committed_.store(from->committed_.load());
210 from->committed_.store(to_commited);
212 std::swap(from->quarantined_pages_count_, to->quarantined_pages_count_);
217 from->FixPagesFlags();
250 heap()->IsNewSpaceAllowedToGrowAboveTargetCapacity());
275 const size_t added_pages = page->active_system_pages()->Add(
294void SemiSpace::Print() {}
298void SemiSpace::VerifyPageMetadata()
const {
300 size_t external_backing_store_bytes[
static_cast<int>(
303 size_t actual_pages = 0;
304 size_t computed_committed_physical_memory = 0;
306 for (
const PageMetadata* page : *
this) {
307 const MemoryChunk* chunk = page->Chunk();
309 CHECK(chunk->InNewSpace());
315 CHECK(!chunk->IsQuarantined());
316 if (!is_from_space) {
319 if (page->heap()->incremental_marking()->IsMarking()) {
320 CHECK(page->heap()->incremental_marking()->IsMajorMarking());
333 external_backing_store_bytes[
index] +=
334 page->ExternalBackingStoreBytes(type);
337 computed_committed_physical_memory += page->CommittedPhysicalMemory();
340 page->list_node().prev()->list_node().next() == page);
348 CHECK_EQ(external_backing_store_bytes[index],
364 if (page == end_page) {
367 while (page != end_page) {
368 page = page->next_page();
391 page->set_owner(
this);
406 DCHECK(page->Chunk()->InYoungGeneration());
417 size_t initial_semispace_capacity,
418 size_t min_semispace_capacity,
419 size_t max_semispace_capacity)
423 minimum_capacity_(min_semispace_capacity),
424 maximum_capacity_(max_semispace_capacity),
425 target_capacity_(initial_semispace_capacity) {
436 heap()->safepoint()->AssertActive();
456 current_page = current_page->
next_page();
465 for (; current_page != age_mark_page;
466 current_page = current_page->
next_page()) {
509std::optional<std::pair<Address, Address>>
515 return Allocate(size_in_bytes, alignment);
524 parked_size = it->first;
526 int filler_size = Heap::GetFillToAlign(
start, alignment);
527 if (size_in_bytes + filler_size <= parked_size) {
560void SemiSpaceNewSpace::Verify(
Isolate* isolate,
562 VerifyObjects(isolate, visitor);
573void SemiSpaceNewSpace::VerifyObjects(
Isolate* isolate,
574 SpaceVerificationVisitor* visitor)
const {
575 size_t external_space_bytes[
static_cast<int>(
577 PtrComprCageBase cage_base(isolate);
580 visitor->VerifyPage(page);
582 Address current_address = page->area_start();
589 int size =
object->Size(cage_base);
591 visitor->VerifyObject(
object);
593 if (IsExternalString(
object, cage_base)) {
595 size_t string_size = external_string->ExternalPayloadSize();
596 external_space_bytes[
static_cast<int>(
603 visitor->VerifyPageDone(page);
614 if (!
v8_flags.concurrent_array_buffer_sweeping) {
615 size_t bytes =
heap()->array_buffer_sweeper()->young().BytesSlow();
632 heap()->CreateFillerObjectAt(page->area_start(),
633 static_cast<int>(page->area_size()));
646 for (
PageMetadata* page = *(++it); page !=
nullptr; page = *(++it)) {
647 heap()->CreateFillerObjectAt(page->area_start(),
648 static_cast<int>(page->area_size()));
698 size_t current_size =
Size();
719 DCHECK(p->IsLivenessClear());
725 DCHECK(!
heap()->allocator()->new_space_allocator()->IsLabValid());
746 page->HighWaterMark() - page->area_start(),
752 DCHECK(!page->Chunk()->IsToPage());
753 DCHECK(page->Chunk()->IsFromPage());
769 int filler_size = Heap::GetFillToAlign(top, alignment);
770 int aligned_size_in_bytes = size_in_bytes + filler_size;
772 if (top + aligned_size_in_bytes <= high) {
774 return std::pair(top, high);
777 int remaining_in_page =
static_cast<int>(high -
top);
778 heap()->CreateFillerObjectAt(top, remaining_in_page);
783 if (
v8_flags.allocation_buffer_parking &&
784 heap()->gc_state() == Heap::NOT_IN_GC &&
799 if (
v8_flags.allocation_buffer_parking &&
833 size_t initial_capacity,
837 FreeList::CreateFreeListForNewSpace(),
839 min_capacity_(min_capacity),
840 max_capacity_(max_capacity),
841 target_capacity_(initial_capacity) {
859 page->ResetAllocationStatistics();
861 page->ClearLiveness();
862 page->AllocateFreeListCategories();
863 page->InitializeFreeListCategories();
864 page->list_node().Initialize();
870 heap()->safepoint()->AssertActive();
935 heap()->
isolate()->root(RootIndex::kFreeSpaceMap).ptr());
944 return page->AllocatedLabSize() <=
947 v8_flags.minor_ms_page_promotion_max_lab_threshold / 100);
959void PagedSpaceForNewSpace::Verify(
Isolate* isolate,
961 PagedSpaceBase::Verify(isolate, visitor);
966 return sum + page->AllocatedLabSize();
969 std::accumulate(
begin(),
end(), 0, sum_allocated_labs));
977 size_t min_capacity,
size_t max_capacity)
979 paged_space_(
heap, initial_capacity, min_capacity, max_capacity) {}
static void Relaxed_Store(T *addr, typename std::remove_reference< T >::type new_value)
static bool HasLazyCommits()
void AccountCommitted(size_t bytes)
void AccountUncommitted(size_t bytes)
virtual size_t CommittedMemory() const
static Tagged< HeapObject > FromAddress(Address address)
MemoryAllocator * memory_allocator()
SemiSpaceNewSpace * semi_space_new_space() const
Isolate * isolate() const
const IsolateData * isolate_data() const
static V8_INLINE intptr_t GetCommitPageSizeBits()
V8_EXPORT_PRIVATE void Free(MemoryAllocator::FreeMode mode, MutablePageMetadata *chunk)
static V8_INLINE intptr_t GetCommitPageSize()
static constexpr size_t AllocatableMemoryInMemoryChunk(AllocationSpace space)
static constexpr size_t AllocatableMemoryInDataPage()
void InitializationMemoryFence()
@ POINTERS_FROM_HERE_ARE_INTERESTING
@ NEW_SPACE_BELOW_AGE_MARK
@ POINTERS_TO_HERE_ARE_INTERESTING
V8_INLINE void SetFlagNonExecutable(Flag flag)
V8_INLINE bool IsFlagSet(Flag flag) const
V8_INLINE Address address() const
V8_INLINE void SetFlagsNonExecutable(MainThreadFlags flags, MainThreadFlags mask=kAllFlagsMask)
V8_INLINE MemoryChunkMetadata * Metadata()
size_t Offset(Address addr) const
V8_INLINE bool InYoungGeneration() const
bool IsQuarantined() const
V8_INLINE void ClearFlagNonExecutable(Flag flag)
static MainThreadFlags YoungGenerationPageFlags(MarkingMode marking_mode)
static V8_INLINE constexpr bool IsAligned(Address address)
static const int kPageSize
V8_EXPORT_PRIVATE size_t CommittedPhysicalMemory() const
virtual void RemovePage(PageMetadata *page)=0
static const int kAllocationBufferParkingThreshold
void PromotePageToOldSpace(PageMetadata *page, FreeMode free_mode)
PageMetadata * prev_page()
PageMetadata * next_page()
static PageMetadata * ConvertNewToOld(PageMetadata *old_page, FreeMode free_mode)
static V8_INLINE PageMetadata * FromAllocationAreaAddress(Address address)
static PageMetadata * cast(MemoryChunkMetadata *metadata)
static bool IsAlignedToPageSize(Address addr)
static V8_INLINE PageMetadata * FromAddress(Address addr)
AllocatorPolicy * CreateAllocatorPolicy(MainAllocator *allocator) final
PagedNewSpace(Heap *heap, size_t initial_capacity, size_t min_capacity, size_t max_capacity)
PagedSpaceForNewSpace paged_space_
int CountTotalPages() const
virtual void RemovePage(PageMetadata *page)
virtual size_t AddPage(PageMetadata *page)
bool TryExpand(LocalHeap *local_heap, AllocationOrigin origin)
void ReleasePageImpl(PageMetadata *page, MemoryAllocator::FreeMode free_mode)
size_t Available() const override
size_t Size() const override
PageMetadata * last_lab_page_
bool StartShrinking(size_t new_target_capacity)
PagedSpaceForNewSpace(Heap *heap, size_t initial_capacity, size_t min_capacity, size_t max_capacity)
const size_t max_capacity_
bool IsPromotionCandidate(const MutablePageMetadata *page) const
bool ShouldReleaseEmptyPage() const
size_t MaximumCapacity() const
void Grow(size_t new_capacity)
void GrowToMaximumCapacityForTesting()
void RemovePage(PageMetadata *page) final
size_t Available() const final
void AllocatePageUpToCapacityForTesting()
const size_t min_capacity_
size_t AddPage(PageMetadata *page) final
PageMetadata * InitializePage(MutablePageMetadata *chunk) final
void ReleasePage(PageMetadata *page) final
size_t AllocatedSinceLastGC() const
size_t TotalCapacity() const
SemiSpaceNewSpace(Heap *heap, size_t initial_semispace_capacity, size_t min_semispace_capacity_, size_t max_semispace_capacity)
bool AddParkedAllocationBuffer(int size_in_bytes, AllocationAlignment alignment)
ParkedAllocationBuffersVector parked_allocation_buffers_
size_t size_after_last_gc_
V8_INLINE void IncrementAllocationTop(Address new_top)
void MoveQuarantinedPage(MemoryChunk *chunk)
bool IsFromSpaceCommitted() const
friend class SemiSpaceNewSpaceAllocatorPolicy
bool ContainsSlow(Address a) const final
void GarbageCollectionEpilogue() final
void GarbageCollectionPrologue() final
std::pair< int, Address > ParkedAllocationBuffer
size_t QuarantinedSize() const
void SetAllocationTop(Address top)
friend class SemiSpaceObjectIterator
V8_INLINE void DecrementAllocationTop(Address new_top)
size_t Available() const final
void Shrink(size_t new_capacity)
bool ShouldPageBePromoted(const MemoryChunk *chunk) const
void MakeAllPagesInFromSpaceIterable()
size_t Capacity() const final
size_t AllocatedSinceLastGC() const final
size_t CommittedMemory() const final
std::optional< std::pair< Address, Address > > AllocateOnNewPageBeyondCapacity(int size_in_bytes, AllocationAlignment alignment)
size_t Size() const final
size_t ExternalBackingStoreBytes(ExternalBackingStoreType type) const final
void FillCurrentPageForTesting()
void ResetParkedAllocationBuffers()
void MakeUnusedPagesInToSpaceIterable()
void SetAgeMarkAndBelowAgeMarkPageFlags()
std::optional< std::pair< Address, Address > > Allocate(int size_in_bytes, AllocationAlignment alignment)
std::unique_ptr< ObjectIterator > GetObjectIterator(Heap *heap) final
void GrowToMaximumCapacityForTesting() final
void Free(Address start, Address end)
const size_t minimum_capacity_
void ResetAllocationTopToCurrentPageStart()
AllocatorPolicy * CreateAllocatorPolicy(MainAllocator *allocator) final
void Grow(size_t new_capacity) final
Address allocation_top() const
void RemovePage(PageMetadata *page) final
const size_t maximum_capacity_
size_t CommittedPhysicalMemory() const final
PageMetadata * first_page() final
bool IsPromotionCandidate(const MutablePageMetadata *page) const final
int GetSpaceRemainingOnCurrentPageForTesting()
void MakeIterable() override
bool AdvancePage(size_t target_capacity)
V8_EXPORT_PRIVATE ~SemiSpace()
size_t current_capacity() const
static void Swap(SemiSpace *from, SemiSpace *to)
SemiSpace(Heap *heap, SemiSpaceId semispace)
PageMetadata * last_page() final
size_t quarantined_pages_count_
void RewindPages(int num_pages)
void IncrementCommittedPhysicalMemory(size_t increment_value)
void AddRangeToActiveSystemPages(Address start, Address end)
PageMetadata * current_page() const
void DecrementCommittedPhysicalMemory(size_t decrement_value)
size_t CommittedPhysicalMemory() const final
void RemovePage(PageMetadata *page)
std::unique_ptr< ObjectIterator > GetObjectIterator(Heap *heap) final
void MovePageToTheEnd(PageMetadata *page)
PageMetadata * current_page_
void MoveQuarantinedPage(MemoryChunk *chunk)
bool ContainsSlow(Address a) const
PageMetadata * first_page() final
size_t committed_physical_memory_
void ShrinkCapacityTo(size_t capacity)
PageMetadata * InitializePage(MutablePageMetadata *chunk) final
Address page_high() const
static void AssertValidRange(Address from, Address to)
virtual size_t ExternalBackingStoreBytes(ExternalBackingStoreType type) const
void DecrementExternalBackingStoreBytes(ExternalBackingStoreType type, size_t amount)
heap::List< MutablePageMetadata > memory_chunk_list_
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
void ZapBlock(Address start, size_t size, uintptr_t zap_value)
Tagged(T object) -> Tagged< T >
kInterpreterTrampolineOffset Tagged< HeapObject >
void ForAll(Callback callback)
V8_EXPORT_PRIVATE FlagValues v8_flags
static constexpr Address kNullAddress
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK_SEMISPACE_ALLOCATION_TOP(top, space)
#define DCHECK_LE(v1, v2)
#define CHECK_IMPLIES(lhs, rhs)
#define DCHECK_NOT_NULL(val)
#define CHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
constexpr bool IsAligned(T value, U alignment)