v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
page-metadata.h
Go to the documentation of this file.
1// Copyright 2023 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_PAGE_METADATA_H_
6#define V8_HEAP_PAGE_METADATA_H_
7
11#include "src/heap/spaces.h"
12
13namespace v8 {
14namespace internal {
15
16class Heap;
17
18// -----------------------------------------------------------------------------
19// A page is a memory chunk of a size 256K. Large object pages may be larger.
20//
21// The only way to get a page pointer is by calling factory methods:
22// PageMetadata* p = PageMetadata::FromAddress(addr); or
23// PageMetadata* p = PageMetadata::FromAllocationAreaAddress(address);
25 public:
26 PageMetadata(Heap* heap, BaseSpace* space, size_t size, Address area_start,
27 Address area_end, VirtualMemory reservation);
28
29 // Returns the page containing a given address. The address ranges
30 // from [page_addr .. page_addr + kPageSize]. This only works if the object is
31 // in fact in a page.
34
36 return cast(MutablePageMetadata::cast(metadata));
37 }
38
40 DCHECK_IMPLIES(metadata, !metadata->Chunk()->IsLargePage());
41 return static_cast<PageMetadata*>(metadata);
42 }
43
44 // Returns the page containing the address provided. The address can
45 // potentially point righter after the page. To be also safe for tagged values
46 // we subtract a hole word. The valid address ranges from
47 // [page_addr + area_start_ .. page_addr + kPageSize + kTaggedSize].
49
50 // Checks if address1 and address2 are on the same new space page.
51 static bool OnSamePage(Address address1, Address address2) {
52 return MemoryChunk::FromAddress(address1) ==
54 }
55
56 // Checks whether an address is page aligned.
57 static bool IsAlignedToPageSize(Address addr) {
58 return MemoryChunk::IsAligned(addr);
59 }
60
62 FreeMode free_mode);
63
65 inline void MarkEvacuationCandidate();
66 inline void ClearEvacuationCandidate();
67
69 return static_cast<PageMetadata*>(list_node_.next());
70 }
72 return static_cast<PageMetadata*>(list_node_.prev());
73 }
74
75 const PageMetadata* next_page() const {
76 return static_cast<const PageMetadata*>(list_node_.next());
77 }
78 const PageMetadata* prev_page() const {
79 return static_cast<const PageMetadata*>(list_node_.prev());
80 }
81
82 template <typename Callback>
83 inline void ForAllFreeListCategories(Callback callback);
84
86
91
95
98
102
106
107 template <RememberedSetType remembered_set>
110 if (typed_slot_set != nullptr) {
112 }
113 }
114
115 template <RememberedSetType remembered_set>
117 const TypedSlotSet::FreeRangesMap& ranges) {
118#if DEBUG
120 if (typed_slot_set != nullptr) {
122 }
123#endif // DEBUG
124 }
125
126 private:
127 friend class MemoryAllocator;
128};
129
130} // namespace internal
131
132namespace base {
133// Define special hash function for page pointers, to be used with std data
134// structures, e.g. std::unordered_set<PageMetadata*, base::hash<PageMetadata*>
135template <>
136struct hash<i::PageMetadata*> : hash<i::MemoryChunkMetadata*> {};
137template <>
138struct hash<const i::PageMetadata*> : hash<const i::MemoryChunkMetadata*> {};
139} // namespace base
140
141} // namespace v8
142
143#endif // V8_HEAP_PAGE_METADATA_H_
static V8_INLINE MemoryChunk * FromAddress(Address addr)
static V8_INLINE constexpr bool IsAligned(Address address)
heap::ListNode< MutablePageMetadata > list_node_
static MutablePageMetadata * cast(MemoryChunkMetadata *metadata)
std::unique_ptr< ActiveSystemPages > active_system_pages_
PageMetadata * prev_page()
V8_EXPORT_PRIVATE size_t AvailableInFreeList()
size_t AvailableInFreeListFromAllocatedBytes()
PageMetadata * next_page()
void ForAllFreeListCategories(Callback callback)
void AssertNoTypedSlotsInFreeMemory(const TypedSlotSet::FreeRangesMap &ranges)
static PageMetadata * cast(MutablePageMetadata *metadata)
static PageMetadata * ConvertNewToOld(PageMetadata *old_page, FreeMode free_mode)
FreeListCategory * free_list_category(FreeListCategoryType type)
void ClearTypedSlotsInFreeMemory(const TypedSlotSet::FreeRangesMap &ranges)
static V8_INLINE PageMetadata * FromAllocationAreaAddress(Address address)
PageMetadata(Heap *heap, BaseSpace *space, size_t size, Address area_start, Address area_end, VirtualMemory reservation)
static PageMetadata * cast(MemoryChunkMetadata *metadata)
const PageMetadata * prev_page() const
V8_EXPORT_PRIVATE void MarkNeverAllocateForTesting()
static bool IsAlignedToPageSize(Address addr)
static V8_INLINE PageMetadata * FromHeapObject(Tagged< HeapObject > o)
static bool OnSamePage(Address address1, Address address2)
static V8_INLINE PageMetadata * FromAddress(Address addr)
void DestroyBlackArea(Address start, Address end)
const PageMetadata * next_page() const
ActiveSystemPages * active_system_pages()
V8_EXPORT_PRIVATE void CreateBlackArea(Address start, Address end)
std::map< uint32_t, uint32_t > FreeRangesMap
Definition slot-set.h:306
void ClearInvalidSlots(const FreeRangesMap &invalid_ranges)
Definition slot-set.cc:64
void AssertNoInvalidSlots(const FreeRangesMap &invalid_ranges)
Definition slot-set.cc:69
int start
int end
TNode< Object > callback
int32_t FreeListCategoryType
Definition free-list.h:37
uint32_t cast
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_INLINE
Definition v8config.h:500
wasm::ValueType type