5#ifndef INCLUDE_V8_INTERNAL_H_
6#define INCLUDE_V8_INTERNAL_H_
30static const Address kNullAddress = 0;
32constexpr int KB = 1024;
33constexpr int MB =
KB * 1024;
34constexpr int GB =
MB * 1024;
35#ifdef V8_TARGET_ARCH_X64
36constexpr size_t TB =
size_t{
GB} * 1024;
66template <
size_t tagged_ptr_size>
85 return static_cast<int32_t>(
static_cast<uint32_t
>(value)) >> shift_bits;
91 return (
static_cast<uintptr_t
>(value) -
110 return static_cast<int>(
static_cast<intptr_t
>(value) >> shift_bits);
114 return (value ==
static_cast<int32_t>(value));
118#ifdef V8_COMPRESS_POINTERS
121constexpr size_t kPtrComprCageReservationSize =
size_t{1} << 32;
122constexpr size_t kPtrComprCageBaseAlignment =
size_t{1} << 32;
126 "Pointer compression can be enabled only for 64-bit architectures");
136#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
146const int kSmiMinValue =
static_cast<int>(PlatformSmiTagging::kSmiMinValue);
147const int kSmiMaxValue =
static_cast<int>(PlatformSmiTagging::kSmiMaxValue);
168#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
182#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
188#ifdef V8_SANDBOX_IS_AVAILABLE
191constexpr size_t kSandboxSizeLog2 = 40;
192constexpr size_t kSandboxSize = 1ULL << kSandboxSizeLog2;
199constexpr size_t kSandboxAlignment = kPtrComprCageBaseAlignment;
205constexpr uint64_t kSandboxedPointerShift = 64 - kSandboxSizeLog2;
210constexpr size_t kSandboxGuardRegionSize = 32ULL *
GB;
212static_assert((kSandboxGuardRegionSize % kSandboxAlignment) == 0,
213 "The size of the guard regions around the sandbox must be a "
214 "multiple of its required alignment.");
224constexpr size_t kSandboxMinimumSize = 32ULL *
GB;
226static_assert(kSandboxMinimumSize <= kSandboxSize,
227 "The minimal size of the sandbox must be smaller or equal to the "
240constexpr size_t kSandboxMinimumReservationSize = 8ULL *
GB;
242static_assert(kSandboxMinimumSize > kPtrComprCageReservationSize,
243 "The sandbox must be larger than the pointer compression cage "
244 "contained within it.");
245static_assert(kSandboxMinimumReservationSize > kPtrComprCageReservationSize,
246 "The minimum reservation size for a sandbox must be larger than "
247 "the pointer compression cage contained within it.");
253#ifdef V8_SANDBOXED_POINTERS
254constexpr bool kAllowBackingStoresOutsideSandbox =
false;
256constexpr bool kAllowBackingStoresOutsideSandbox =
true;
264static const size_t kExternalPointerTableReservationSize = 128 *
MB;
267static const size_t kMaxSandboxedExternalPointers =
273static const uint32_t kExternalPointerIndexShift = 8;
274static_assert((1 << (32 - kExternalPointerIndexShift)) ==
275 kMaxSandboxedExternalPointers,
276 "kExternalPointerTableReservationSize and "
277 "kExternalPointerIndexShift don't match");
298#define MAKE_TAG(v) (static_cast<uint64_t>(v) << kExternalPointerTagShift)
340 return mapword ^ kMapWordXorMask;
357#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
358 static const int kEmbedderDataSlotRawPayloadOffset =
kApiTaggedSize;
433 static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48;
435 static const uintptr_t kMapWordSignature = 0b10;
440 static const int kMapWordXorMask = 0b11;
445#ifdef V8_ENABLE_CHECKS
455 return PlatformSmiTagging::SmiToInt(value);
459 return internal::IntToSmi(value);
463 return PlatformSmiTagging::IsValidSmi(value);
470 map = UnpackMapWord(map);
486 return *addr &
static_cast<uint8_t
>(1U << shift);
492 uint8_t mask =
static_cast<uint8_t
>(1U << shift);
493 *addr =
static_cast<uint8_t
>((*addr & ~mask) | (value << shift));
503 *addr =
static_cast<uint8_t
>((*addr & ~kNodeStateMask) | value);
511 *
reinterpret_cast<void**
>(addr) = data;
519 return *
reinterpret_cast<void* const*
>(addr);
525 ++(*
reinterpret_cast<size_t*
>(addr));
535 template <
typename T>
539#ifdef V8_COMPRESS_POINTERS
546 memcpy(&r,
reinterpret_cast<void*
>(addr),
sizeof(T));
550 return *
reinterpret_cast<const T*
>(addr);
555#ifdef V8_COMPRESS_POINTERS
556 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
558 GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
561 return ReadRawField<internal::Address>(heap_object_ptr, offset);
567#ifdef V8_COMPRESS_POINTERS
568 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
571 return ReadRawField<internal::Address>(heap_object_ptr, offset);
577#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
588#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
591 return encoded_pointer;
598#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
600 ReadRawField<uint32_t>(heap_object_ptr, offset);
605 return ReadRawField<Address>(heap_object_ptr, offset);
609#ifdef V8_COMPRESS_POINTERS
612 return addr & -
static_cast<intptr_t
>(kPtrComprCageBaseAlignment);
618 GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
627template <
bool PerformCheck>
646 !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
static const int kIsolateCageBaseOffset
static V8_INLINE void UpdateNodeFlag(internal::Address *obj, bool value, int shift)
static const int kTrueValueRootIndex
static V8_INLINE constexpr internal::Address IntToSmi(int value)
static const int kInferShouldThrowMode
static V8_INLINE int SmiValue(const internal::Address value)
static const int kJSSpecialApiObjectType
static V8_INLINE void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
static const int kOddballKindOffset
static const int kFalseValueRootIndex
static V8_INLINE internal::Isolate * GetIsolateForSandbox(internal::Address obj)
static constexpr int kExternalAllocationSoftLimit
static const int kIsolateStackGuardOffset
static const int kNullValueRootIndex
static const int kIsolateFastCCallCallerPcOffset
static const int kDontThrow
static const int kEmptyStringRootIndex
static const int kExternalPointerTableFreelistHeadOffset
static const int kNativeContextEmbedderDataOffset
static V8_INLINE int GetInstanceType(const internal::Address obj)
static const int kStringRepresentationAndEncodingMask
static const int kIsolateLongTaskStatsCounterOffset
static const int kEmbedderDataArrayHeaderSize
static const int kExternalPointerTableCapacityOffset
static V8_INLINE void UpdateNodeState(internal::Address *obj, uint8_t value)
static V8_INLINE internal::Address * GetRoot(v8::Isolate *isolate, int index)
static const int kExternalTwoByteRepresentationTag
static const int kNodeStateMask
static const int kUndefinedValueRootIndex
static V8_INLINE constexpr bool IsValidSmi(intptr_t value)
static const int kThrowOnError
static const int kBuiltinTier0TableSize
static V8_INLINE void CheckInitialized(v8::Isolate *isolate)
static const uint32_t kNumIsolateDataSlots
static const int kBuiltinTier0EntryTableSize
static V8_INLINE uint8_t GetNodeFlag(internal::Address *obj, int shift)
static const int kStackGuardSize
static const int kIsolateFastApiCallTargetOffset
static V8_INLINE uint8_t GetNodeState(internal::Address *obj)
static const int kNodeFlagsOffset
static const int kLastJSApiObjectType
static const int kExternalOneByteRepresentationTag
static const int kNodeStateIsWeakValue
static V8_EXPORT void CheckInitializedImpl(v8::Isolate *isolate)
static const int kBuiltinTier0TableOffset
static const int kForeignType
static const int kNodeClassIdOffset
static const int kIsolateRootsOffset
static V8_INLINE T ReadRawField(internal::Address heap_object_ptr, int offset)
static V8_INLINE internal::Address ReadTaggedSignedField(internal::Address heap_object_ptr, int offset)
static const int kFirstJSApiObjectType
static const int kOddballType
static const int kMapInstanceTypeOffset
static const int kIsolateEmbedderDataOffset
static V8_INLINE int GetOddballKind(const internal::Address obj)
static const int kNodeStateIsPendingValue
static V8_INLINE void * GetEmbedderData(const v8::Isolate *isolate, uint32_t slot)
static V8_INLINE internal::Address ReadTaggedPointerField(internal::Address heap_object_ptr, int offset)
static V8_INLINE bool HasHeapObjectTag(const internal::Address value)
static const int kUndefinedOddballKind
static const int kEmbedderDataSlotSize
static const int kHeapObjectMapOffset
static const int kNullOddballKind
static V8_INLINE bool IsExternalTwoByteString(int instance_type)
static V8_INLINE Address DecodeExternalPointer(const Isolate *isolate, ExternalPointer_t encoded_pointer, ExternalPointerTag tag)
static const int kFirstNonstringType
static V8_INLINE internal::Address ReadExternalPointerField(internal::Isolate *isolate, internal::Address heap_object_ptr, int offset, ExternalPointerTag tag)
static const int kBuiltinTier0EntryTableOffset
static const int kStringEncodingMask
static const int kExternalPointerTableBufferOffset
static const int kJSObjectHeaderSize
static V8_INLINE void SetEmbedderData(v8::Isolate *isolate, uint32_t slot, void *data)
static const int kFixedArrayHeaderSize
static const int kJSObjectType
static const int kTheHoleValueRootIndex
static const int kStringResourceOffset
static const int kIsolateFastCCallCallerFpOffset
constexpr bool PointerCompressionIsEnabled()
Address SandboxedPointer_t
const int kApiSystemPointerSize
V8_EXPORT bool CanHaveInternalField(int instance_type)
Address ExternalPointer_t
constexpr uint64_t kExternalPointerTagShift
const intptr_t kHeapObjectTagMask
const int kHeapObjectTagSize
const intptr_t kForwardingTagMask
SmiTagging< kApiTaggedSize > PlatformSmiTagging
V8_EXPORT Address DecodeExternalPointerImpl(const Isolate *isolate, ExternalPointer_t pointer, ExternalPointerTag tag)
V8_EXPORT internal::Isolate * IsolateFromNeverReadOnlySpaceObject(Address obj)
constexpr bool SmiValuesAre32Bits()
constexpr bool SmiValuesAre31Bits()
constexpr uintptr_t kUintptrAllBitsSet
@ kExternalPointerNullTag
@ kForeignForeignAddressTag
@ kExternalPointerFreeEntryTag
@ kExternalStringResourceDataTag
@ kEmbedderDataSlotPayloadTag
@ kExternalObjectValueTag
@ kExternalStringResourceTag
@ kNativeContextMicrotaskQueueTag
constexpr uint64_t kExternalPointerTagMask
constexpr bool SandboxedExternalPointersAreEnabled()
const int kForwardingTagSize
V8_INLINE void PerformCastCheck(T *data)
constexpr bool SandboxIsEnabled()
const int kWeakHeapObjectTag
V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate *isolate)
constexpr intptr_t kIntptrAllBitsSet
const intptr_t kSmiTagMask
constexpr int kGarbageCollectionReasonMaxValue
int32_t(Local< Array > src, int32_t *dst, uint32_t max_length)
double(Local< Array > src, double *dst, uint32_t max_length)
static void Perform(T *data)
static V8_INLINE int SmiToInt(const internal::Address value)
static V8_INLINE constexpr bool IsValidSmi(intptr_t value)
static V8_INLINE int SmiToInt(const internal::Address value)
static V8_INLINE constexpr bool IsValidSmi(intptr_t value)