5#ifndef V8_HEAP_HEAP_INL_H_
6#define V8_HEAP_HEAP_INL_H_
53 }
else if (Heap::InFromPage(heap_obj)) {
63bool Heap::IsMainThread()
const {
71#define ROOT_ACCESSOR(Type, name, CamelName) \
72 Tagged<Type> Heap::name() { \
73 return Cast<Type>(Tagged<Object>(roots_table()[RootIndex::k##CamelName])); \
83#define STATIC_ROOTS_FAILED_MSG \
84 "Read-only heap layout changed. Run `tools/dev/gen-static-roots.py` to " \
85 "update static-roots.h."
86#if V8_STATIC_ROOTS_BOOL
89#define DCHECK_STATIC_ROOT(obj, name) \
90 if constexpr (RootsTable::IsReadOnly(RootIndex::k##name) && \
91 RootIndex::k##name != RootIndex::kException) { \
92 DCHECK_WITH_MSG(V8HeapCompressionScheme::CompressObject(obj.ptr()) == \
93 StaticReadOnlyRootsPointerTable[static_cast<size_t>( \
94 RootIndex::k##name)], \
95 STATIC_ROOTS_FAILED_MSG); \
98#define DCHECK_STATIC_ROOT(obj, name)
101#define ROOT_ACCESSOR(type, name, CamelName) \
102 void Heap::set_##name(Tagged<type> value) { \
105 DCHECK_IMPLIES(deserialization_complete(), \
106 !RootsTable::IsImmortalImmovable(RootIndex::k##CamelName)); \
107 if constexpr (RootsTable::IsImmortalImmovable(RootIndex::k##CamelName)) { \
112 DCHECK(IsImmovable(Cast<HeapObject>(Cast<Object>(value)))); \
114 DCHECK_STATIC_ROOT(value, CamelName); \
115 roots_table()[RootIndex::k##CamelName] = value.ptr(); \
119#undef CHECK_STATIC_ROOT
120#undef STATIC_ROOTS_FAILED_MSG
123 roots_table()[RootIndex::kMaterializedObjects] = objects.ptr();
127 roots_table()[RootIndex::kScriptList] = value.ptr();
131 roots_table()[RootIndex::kMessageListeners] = value.ptr();
135 DCHECK(IsObjectHashTable(hash_table) || IsUndefined(hash_table,
isolate()));
136 roots_table()[RootIndex::kFunctionsMarkedForManualOptimization] =
140#if V8_ENABLE_WEBASSEMBLY
141void Heap::SetWasmCanonicalRttsAndJSToWasmWrappers(
143 set_wasm_canonical_rtts(rtts);
144 set_js_to_wasm_wrappers(js_to_wasm_wrappers);
156Address* Heap::NewSpaceAllocationTopAddress() {
158 ?
isolate()->isolate_data()->new_allocation_info_.top_address()
162Address* Heap::NewSpaceAllocationLimitAddress() {
164 ?
isolate()->isolate_data()->new_allocation_info_.limit_address()
168Address* Heap::OldSpaceAllocationTopAddress() {
169 return allocator()->old_space_allocator()->allocation_top_address();
172Address* Heap::OldSpaceAllocationLimitAddress() {
173 return allocator()->old_space_allocator()->allocation_limit_address();
210 DCHECK(IsExternalString(
string));
211 DCHECK(!IsThinString(
string));
216 DCHECK(IsExternalString(
string));
219 page->DecrementExternalBackingStoreBytes(
221 ext_string->ExternalPayloadSize());
222 ext_string->DisposeResource(
isolate());
227 ? allocator()->new_space_allocator()->top()
233 ? allocator()->new_space_allocator()->limit()
300 Address addr =
object.address();
304 return allocator()->new_space_allocator()->IsPendingAllocation(addr);
308 return allocator()->old_space_allocator()->IsPendingAllocation(addr);
312 return allocator()->code_space_allocator()->IsPendingAllocation(addr);
316 return allocator()->trusted_space_allocator()->IsPendingAllocation(addr);
347 StdoutStream{} <<
"Pending allocation: " << std::hex <<
"0x" <<
object.ptr()
358 std::optional<base::MutexGuard> guard;
367 DCHECK(IsExternalString(
string));
382uint32_t Heap::GetNextTemplateSerialNumber() {
383 uint32_t next_serial_number =
384 static_cast<uint32_t
>(next_template_serial_number().value());
386 ++next_serial_number;
393 set_next_template_serial_number(
Smi::FromInt(next_serial_number));
394 return next_serial_number;
397int Heap::MaxNumberToStringCacheSize()
const {
402 number_string_cache_size =
404 std::min(
static_cast<size_t>(0x4000), number_string_cache_size));
407 return static_cast<int>(number_string_cache_size * 2);
413 std::memory_order_relaxed);
421 std::memory_order_relaxed);
#define SLOW_DCHECK(condition)
AlwaysAllocateScopeForTesting(Heap *heap)
AlwaysAllocateScope(Heap *heap)
AllocationSpace identity() const
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult AllocateRaw(int size_in_bytes, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
V8_WARN_UNUSED_RESULT V8_INLINE Tagged< HeapObject > AllocateRawWith(int size, AllocationType allocation, AllocationOrigin origin=AllocationOrigin::kRuntime, AllocationAlignment alignment=kTaggedAligned)
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
bool Contains(Tagged< String > string)
std::vector< TaggedBase > old_strings_
std::vector< TaggedBase > young_strings_
void AddString(Tagged< String > string)
ExternalStringTable external_string_table_
std::atomic< uint64_t > backing_store_bytes_
NewSpace * new_space() const
ExternalMemoryAccounting external_memory_
int ignore_local_gc_requests_depth_
std::atomic< size_t > always_allocate_scope_count_
static const int kInitialNumberStringCacheSize
V8_INLINE RootsTable & roots_table()
size_t max_semi_space_size_
std::unique_ptr< CodeRange > code_range_
OldSpace * old_space() const
static bool InFromPage(Tagged< Object > object)
bool IsPendingAllocation(Tagged< HeapObject > object)
int max_regular_code_object_size_
static bool InToPage(Tagged< Object > object)
Isolate * isolate() const
HeapAllocator * heap_allocator_
bool deserialization_complete() const
bool IsPendingAllocationInternal(Tagged< HeapObject > object)
IgnoreLocalGCRequests(Heap *heap)
bool is_shared_space_isolate() const
static Isolate * FromHeap(const Heap *heap)
Address pending_object() const
base::Mutex * pending_allocation_mutex()
bool IsForwardingAddress() const
Tagged< HeapObject > ToForwardingAddress(Tagged< HeapObject > map_word_host)
static constexpr int MaxRegularCodeObjectSize()
V8_INLINE MemoryChunkMetadata * Metadata()
static V8_INLINE MemoryChunk * FromHeapObject(Tagged< HeapObject > object)
V8_INLINE bool InReadOnlySpace() const
static V8_INLINE PageMetadata * FromHeapObject(Tagged< HeapObject > o)
static PagedNewSpace * From(NewSpace *space)
bool Contains(Address a) const
V8_INLINE Tagged< Boolean > boolean_value(bool value) const
static SemiSpaceNewSpace * From(NewSpace *space)
static constexpr Tagged< Smi > FromInt(int value)
static constexpr int kMaxValue
static StickySpace * From(OldSpace *space)
V8_INLINE constexpr StorageType ptr() const
bool GetHeapObject(Tagged< HeapObject > *result) const
static const int kUninitializedSerialNumber
static const int kFirstNonUniqueSerialNumber
static ThreadId Current()
DeclarationScope * scope_
#define ROOT_ACCESSOR(Type, name, CamelName)
ZoneVector< RpoNumber > & result
void CheckedDecrement(std::atomic< T > *number, T amount, std::memory_order order=std::memory_order_seq_cst)
void CheckedIncrement(std::atomic< T > *number, T amount, std::memory_order order=std::memory_order_seq_cst)
static V8_INLINE bool HasWeakHeapObjectTag(const Tagged< Object > value)
constexpr int kTaggedSize
constexpr int kMaxRegularHeapObjectSize
void CopyTagged(Address dst, const Address src, size_t num_tagged)
@ SHARED_TRUSTED_LO_SPACE
Tagged< T > ForwardingAddress(Tagged< T > heap_obj)
V8_INLINE constexpr bool IsHeapObject(TaggedImpl< kRefType, StorageType > obj)
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)
static constexpr RelaxedLoadTag kRelaxedLoad
#define MUTABLE_ROOT_LIST(V)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
constexpr bool IsAligned(T value, U alignment)