| |
| |
| |
|
|
| #ifndef INCLUDE_V8_INTERNAL_H_ |
| #define INCLUDE_V8_INTERNAL_H_ |
|
|
| #include <stddef.h> |
| #include <stdint.h> |
| #include <string.h> |
|
|
| #include <atomic> |
| #include <type_traits> |
|
|
| #include "v8-version.h" |
| #include "v8config.h" |
|
|
| namespace v8 { |
|
|
| class Array; |
| class Context; |
| class Data; |
| class Isolate; |
|
|
| namespace internal { |
|
|
| class Isolate; |
|
|
| typedef uintptr_t Address; |
| static constexpr Address kNullAddress = 0; |
|
|
| constexpr int KB = 1024; |
| constexpr int MB = KB * 1024; |
| constexpr int GB = MB * 1024; |
| #ifdef V8_TARGET_ARCH_X64 |
| constexpr size_t TB = size_t{GB} * 1024; |
| #endif |
|
|
| |
| |
| |
| const int kApiSystemPointerSize = sizeof(void*); |
| const int kApiDoubleSize = sizeof(double); |
| const int kApiInt32Size = sizeof(int32_t); |
| const int kApiInt64Size = sizeof(int64_t); |
| const int kApiSizetSize = sizeof(size_t); |
|
|
| |
| const int kHeapObjectTag = 1; |
| const int kWeakHeapObjectTag = 3; |
| const int kHeapObjectTagSize = 2; |
| const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| const intptr_t kHeapObjectReferenceTagMask = 1 << (kHeapObjectTagSize - 1); |
|
|
| |
| |
| |
| const int kForwardingTag = 0; |
| const int kForwardingTagSize = 2; |
| const intptr_t kForwardingTagMask = (1 << kForwardingTagSize) - 1; |
|
|
| |
| const int kSmiTag = 0; |
| const int kSmiTagSize = 1; |
| const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
|
|
| template <size_t tagged_ptr_size> |
| struct SmiTagging; |
|
|
| constexpr intptr_t kIntptrAllBitsSet = intptr_t{-1}; |
| constexpr uintptr_t kUintptrAllBitsSet = |
| static_cast<uintptr_t>(kIntptrAllBitsSet); |
|
|
| |
| template <> |
| struct SmiTagging<4> { |
| enum { kSmiShiftSize = 0, kSmiValueSize = 31 }; |
|
|
| static constexpr intptr_t kSmiMinValue = |
| static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1)); |
| static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1); |
|
|
| V8_INLINE static int SmiToInt(Address value) { |
| int shift_bits = kSmiTagSize + kSmiShiftSize; |
| |
| return static_cast<int32_t>(static_cast<uint32_t>(value)) >> shift_bits; |
| } |
| V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { |
| |
| |
| |
| return (static_cast<uintptr_t>(value) - |
| static_cast<uintptr_t>(kSmiMinValue)) <= |
| (static_cast<uintptr_t>(kSmiMaxValue) - |
| static_cast<uintptr_t>(kSmiMinValue)); |
| } |
| }; |
|
|
| |
| template <> |
| struct SmiTagging<8> { |
| enum { kSmiShiftSize = 31, kSmiValueSize = 32 }; |
|
|
| static constexpr intptr_t kSmiMinValue = |
| static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1)); |
| static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1); |
|
|
| V8_INLINE static int SmiToInt(Address value) { |
| int shift_bits = kSmiTagSize + kSmiShiftSize; |
| |
| return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits); |
| } |
| V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { |
| |
| return (value == static_cast<int32_t>(value)); |
| } |
| }; |
|
|
| #ifdef V8_COMPRESS_POINTERS |
| |
| |
| constexpr size_t kPtrComprCageReservationSize = size_t{1} << 32; |
| constexpr size_t kPtrComprCageBaseAlignment = size_t{1} << 32; |
|
|
| static_assert( |
| kApiSystemPointerSize == kApiInt64Size, |
| "Pointer compression can be enabled only for 64-bit architectures"); |
| const int kApiTaggedSize = kApiInt32Size; |
| #else |
| const int kApiTaggedSize = kApiSystemPointerSize; |
| #endif |
|
|
| constexpr bool PointerCompressionIsEnabled() { |
| return kApiTaggedSize != kApiSystemPointerSize; |
| } |
|
|
| #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH |
| using PlatformSmiTagging = SmiTagging<kApiInt32Size>; |
| #else |
| using PlatformSmiTagging = SmiTagging<kApiTaggedSize>; |
| #endif |
|
|
| |
| |
| const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| const int kSmiMinValue = static_cast<int>(PlatformSmiTagging::kSmiMinValue); |
| const int kSmiMaxValue = static_cast<int>(PlatformSmiTagging::kSmiMaxValue); |
| constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; } |
| constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; } |
| constexpr bool Is64() { return kApiSystemPointerSize == sizeof(int64_t); } |
|
|
| V8_INLINE static constexpr Address IntToSmi(int value) { |
| return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) | |
| kSmiTag; |
| } |
|
|
| |
| |
| |
| constexpr bool SandboxIsEnabled() { |
| #ifdef V8_ENABLE_SANDBOX |
| return true; |
| #else |
| return false; |
| #endif |
| } |
|
|
| |
| |
| using SandboxedPointer_t = Address; |
|
|
| #ifdef V8_ENABLE_SANDBOX |
|
|
| |
| #ifdef V8_TARGET_OS_ANDROID |
| |
| |
| |
| constexpr size_t kSandboxSizeLog2 = 37; |
| #else |
| |
| constexpr size_t kSandboxSizeLog2 = 40; |
| #endif |
| constexpr size_t kSandboxSize = 1ULL << kSandboxSizeLog2; |
|
|
| |
| |
| |
| |
| |
| constexpr size_t kSandboxAlignment = kPtrComprCageBaseAlignment; |
|
|
| |
| |
| |
| |
| constexpr uint64_t kSandboxedPointerShift = 64 - kSandboxSizeLog2; |
|
|
| |
| |
| |
| constexpr size_t kSandboxGuardRegionSize = 32ULL * GB; |
|
|
| static_assert((kSandboxGuardRegionSize % kSandboxAlignment) == 0, |
| "The size of the guard regions around the sandbox must be a " |
| "multiple of its required alignment."); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| constexpr size_t kSandboxMinimumReservationSize = 8ULL * GB; |
|
|
| static_assert(kSandboxMinimumReservationSize > kPtrComprCageReservationSize, |
| "The minimum reservation size for a sandbox must be larger than " |
| "the pointer compression cage contained within it."); |
|
|
| |
| |
| |
| |
| constexpr size_t kMaxSafeBufferSizeForSandbox = 32ULL * GB - 1; |
| static_assert(kMaxSafeBufferSizeForSandbox <= kSandboxGuardRegionSize, |
| "The maximum allowed buffer size must not be larger than the " |
| "sandbox's guard regions"); |
|
|
| constexpr size_t kBoundedSizeShift = 29; |
| static_assert(1ULL << (64 - kBoundedSizeShift) == |
| kMaxSafeBufferSizeForSandbox + 1, |
| "The maximum size of a BoundedSize must be synchronized with the " |
| "kMaxSafeBufferSizeForSandbox"); |
|
|
| #endif |
|
|
| #ifdef V8_COMPRESS_POINTERS |
|
|
| #ifdef V8_TARGET_OS_ANDROID |
| |
| |
| |
| |
| |
| static const size_t kExternalPointerTableReservationSize = 512 * MB; |
|
|
| |
| |
| |
| static const uint32_t kExternalPointerIndexShift = 6; |
| #else |
| static const size_t kExternalPointerTableReservationSize = 1024 * MB; |
| static const uint32_t kExternalPointerIndexShift = 5; |
| #endif |
|
|
| |
| static const size_t kMaxExternalPointers = |
| kExternalPointerTableReservationSize / kApiSystemPointerSize; |
| static_assert((1 << (32 - kExternalPointerIndexShift)) == kMaxExternalPointers, |
| "kExternalPointerTableReservationSize and " |
| "kExternalPointerIndexShift don't match"); |
|
|
| #else |
|
|
| |
| static const size_t kMaxExternalPointers = 0; |
|
|
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| |
| using ExternalPointerHandle = uint32_t; |
|
|
| |
| |
| |
| #ifdef V8_ENABLE_SANDBOX |
| using ExternalPointer_t = ExternalPointerHandle; |
| #else |
| using ExternalPointer_t = Address; |
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| constexpr uint64_t kExternalPointerMarkBit = 1ULL << 62; |
| constexpr uint64_t kExternalPointerTagMask = 0x40ff000000000000; |
| constexpr uint64_t kExternalPointerTagShift = 48; |
|
|
| |
| |
| |
| |
| constexpr uint64_t kAllExternalPointerTypeTags[] = { |
| 0b00001111, 0b00010111, 0b00011011, 0b00011101, 0b00011110, 0b00100111, |
| 0b00101011, 0b00101101, 0b00101110, 0b00110011, 0b00110101, 0b00110110, |
| 0b00111001, 0b00111010, 0b00111100, 0b01000111, 0b01001011, 0b01001101, |
| 0b01001110, 0b01010011, 0b01010101, 0b01010110, 0b01011001, 0b01011010, |
| 0b01011100, 0b01100011, 0b01100101, 0b01100110, 0b01101001, 0b01101010, |
| 0b01101100, 0b01110001, 0b01110010, 0b01110100, 0b01111000, 0b10000111, |
| 0b10001011, 0b10001101, 0b10001110, 0b10010011, 0b10010101, 0b10010110, |
| 0b10011001, 0b10011010, 0b10011100, 0b10100011, 0b10100101, 0b10100110, |
| 0b10101001, 0b10101010, 0b10101100, 0b10110001, 0b10110010, 0b10110100, |
| 0b10111000, 0b11000011, 0b11000101, 0b11000110, 0b11001001, 0b11001010, |
| 0b11001100, 0b11010001, 0b11010010, 0b11010100, 0b11011000, 0b11100001, |
| 0b11100010, 0b11100100, 0b11101000, 0b11110000}; |
|
|
| #define TAG(i) \ |
| ((kAllExternalPointerTypeTags[i] << kExternalPointerTagShift) | \ |
| kExternalPointerMarkBit) |
|
|
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| #define SHARED_EXTERNAL_POINTER_TAGS(V) \ |
| V(kFirstSharedTag, TAG(0)) \ |
| V(kWaiterQueueNodeTag, TAG(0)) \ |
| V(kExternalStringResourceTag, TAG(1)) \ |
| V(kExternalStringResourceDataTag, TAG(2)) \ |
| V(kLastSharedTag, TAG(2)) |
|
|
| |
| |
| #define PER_ISOLATE_EXTERNAL_POINTER_TAGS(V) \ |
| V(kForeignForeignAddressTag, TAG(10)) \ |
| V(kNativeContextMicrotaskQueueTag, TAG(11)) \ |
| V(kEmbedderDataSlotPayloadTag, TAG(12)) \ |
| \ |
| \ |
| \ |
| V(kExternalObjectValueTag, TAG(13)) \ |
| V(kCallHandlerInfoCallbackTag, TAG(14)) \ |
| V(kAccessorInfoGetterTag, TAG(15)) \ |
| V(kAccessorInfoSetterTag, TAG(16)) \ |
| V(kWasmInternalFunctionCallTargetTag, TAG(17)) \ |
| V(kWasmTypeInfoNativeTypeTag, TAG(18)) \ |
| V(kWasmExportedFunctionDataSignatureTag, TAG(19)) \ |
| V(kWasmContinuationJmpbufTag, TAG(20)) \ |
| V(kArrayBufferExtensionTag, TAG(21)) |
|
|
| |
| #define ALL_EXTERNAL_POINTER_TAGS(V) \ |
| SHARED_EXTERNAL_POINTER_TAGS(V) \ |
| PER_ISOLATE_EXTERNAL_POINTER_TAGS(V) |
|
|
| #define EXTERNAL_POINTER_TAG_ENUM(Name, Tag) Name = Tag, |
| #define MAKE_TAG(HasMarkBit, TypeTag) \ |
| ((static_cast<uint64_t>(TypeTag) << kExternalPointerTagShift) | \ |
| (HasMarkBit ? kExternalPointerMarkBit : 0)) |
| enum ExternalPointerTag : uint64_t { |
| |
| kExternalPointerNullTag = MAKE_TAG(0, 0b00000000), |
| |
| kAnyExternalPointerTag = MAKE_TAG(1, 0b11111111), |
| |
| |
| |
| kExternalPointerFreeEntryTag = MAKE_TAG(0, 0b11111111), |
| |
| kExternalPointerEvacuationEntryTag = MAKE_TAG(1, 0b11100111), |
|
|
| ALL_EXTERNAL_POINTER_TAGS(EXTERNAL_POINTER_TAG_ENUM) |
| }; |
|
|
| #undef MAKE_TAG |
| #undef TAG |
| #undef EXTERNAL_POINTER_TAG_ENUM |
|
|
| |
|
|
| |
| |
| V8_INLINE static constexpr bool IsSharedExternalPointerType( |
| ExternalPointerTag tag) { |
| return tag >= kFirstSharedTag && tag <= kLastSharedTag; |
| } |
|
|
| |
| #define CHECK_SHARED_EXTERNAL_POINTER_TAGS(Tag, ...) \ |
| static_assert(IsSharedExternalPointerType(Tag)); |
| #define CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS(Tag, ...) \ |
| static_assert(!IsSharedExternalPointerType(Tag)); |
|
|
| SHARED_EXTERNAL_POINTER_TAGS(CHECK_SHARED_EXTERNAL_POINTER_TAGS) |
| PER_ISOLATE_EXTERNAL_POINTER_TAGS(CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS) |
|
|
| #undef CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS |
| #undef CHECK_SHARED_EXTERNAL_POINTER_TAGS |
|
|
| #undef SHARED_EXTERNAL_POINTER_TAGS |
| #undef EXTERNAL_POINTER_TAGS |
|
|
| |
| |
| V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj); |
|
|
| |
| |
| |
| V8_EXPORT bool ShouldThrowOnError(internal::Isolate* isolate); |
| |
| |
| |
| |
| |
| class Internals { |
| #ifdef V8_MAP_PACKING |
| V8_INLINE static constexpr Address UnpackMapWord(Address mapword) { |
| |
| return mapword ^ kMapWordXorMask; |
| } |
| #endif |
|
|
| public: |
| |
| |
| static const int kHeapObjectMapOffset = 0; |
| static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size; |
| static const int kStringResourceOffset = |
| 1 * kApiTaggedSize + 2 * kApiInt32Size; |
|
|
| static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize; |
| static const int kJSObjectHeaderSize = 3 * kApiTaggedSize; |
| static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize; |
| static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize; |
| static const int kEmbedderDataSlotSize = kApiSystemPointerSize; |
| #ifdef V8_ENABLE_SANDBOX |
| static const int kEmbedderDataSlotExternalPointerOffset = kApiTaggedSize; |
| #else |
| static const int kEmbedderDataSlotExternalPointerOffset = 0; |
| #endif |
| static const int kNativeContextEmbedderDataOffset = 6 * kApiTaggedSize; |
| static const int kStringRepresentationAndEncodingMask = 0x0f; |
| static const int kStringEncodingMask = 0x8; |
| static const int kExternalTwoByteRepresentationTag = 0x02; |
| static const int kExternalOneByteRepresentationTag = 0x0a; |
|
|
| static const uint32_t kNumIsolateDataSlots = 4; |
| static const int kStackGuardSize = 7 * kApiSystemPointerSize; |
| static const int kBuiltinTier0EntryTableSize = 7 * kApiSystemPointerSize; |
| static const int kBuiltinTier0TableSize = 7 * kApiSystemPointerSize; |
| static const int kLinearAllocationAreaSize = 3 * kApiSystemPointerSize; |
| static const int kThreadLocalTopSize = 25 * kApiSystemPointerSize; |
|
|
| |
| static const int kExternalPointerTableBufferOffset = 0; |
| static const int kExternalPointerTableSize = 4 * kApiSystemPointerSize; |
|
|
| |
| static const int kIsolateCageBaseOffset = 0; |
| static const int kIsolateStackGuardOffset = |
| kIsolateCageBaseOffset + kApiSystemPointerSize; |
| static const int kVariousBooleanFlagsOffset = |
| kIsolateStackGuardOffset + kStackGuardSize; |
| static const int kBuiltinTier0EntryTableOffset = |
| kVariousBooleanFlagsOffset + 8; |
| static const int kBuiltinTier0TableOffset = |
| kBuiltinTier0EntryTableOffset + kBuiltinTier0EntryTableSize; |
| static const int kNewAllocationInfoOffset = |
| kBuiltinTier0TableOffset + kBuiltinTier0TableSize; |
| static const int kOldAllocationInfoOffset = |
| kNewAllocationInfoOffset + kLinearAllocationAreaSize; |
| static const int kIsolateFastCCallCallerFpOffset = |
| kOldAllocationInfoOffset + kLinearAllocationAreaSize; |
| static const int kIsolateFastCCallCallerPcOffset = |
| kIsolateFastCCallCallerFpOffset + kApiSystemPointerSize; |
| static const int kIsolateFastApiCallTargetOffset = |
| kIsolateFastCCallCallerPcOffset + kApiSystemPointerSize; |
| static const int kIsolateLongTaskStatsCounterOffset = |
| kIsolateFastApiCallTargetOffset + kApiSystemPointerSize; |
| static const int kIsolateThreadLocalTopOffset = |
| kIsolateLongTaskStatsCounterOffset + kApiSizetSize; |
| static const int kIsolateEmbedderDataOffset = |
| kIsolateThreadLocalTopOffset + kThreadLocalTopSize; |
| #ifdef V8_COMPRESS_POINTERS |
| static const int kIsolateExternalPointerTableOffset = |
| kIsolateEmbedderDataOffset + kNumIsolateDataSlots * kApiSystemPointerSize; |
| static const int kIsolateSharedExternalPointerTableAddressOffset = |
| kIsolateExternalPointerTableOffset + kExternalPointerTableSize; |
| static const int kIsolateRootsOffset = |
| kIsolateSharedExternalPointerTableAddressOffset + kApiSystemPointerSize; |
| #else |
| static const int kIsolateRootsOffset = |
| kIsolateEmbedderDataOffset + kNumIsolateDataSlots * kApiSystemPointerSize; |
| #endif |
|
|
| #if V8_STATIC_ROOTS_BOOL |
|
|
| |
| #define EXPORTED_STATIC_ROOTS_PTR_LIST(V) \ |
| V(UndefinedValue) \ |
| V(NullValue) \ |
| V(TrueValue) \ |
| V(FalseValue) \ |
| V(EmptyString) \ |
| V(TheHoleValue) |
|
|
| using Tagged_t = uint32_t; |
| struct StaticReadOnlyRoot { |
| #define DEF_ROOT(name) V8_EXPORT static const Tagged_t k##name; |
| EXPORTED_STATIC_ROOTS_PTR_LIST(DEF_ROOT) |
| #undef DEF_ROOT |
|
|
| V8_EXPORT static const Tagged_t kFirstStringMap; |
| V8_EXPORT static const Tagged_t kLastStringMap; |
| }; |
|
|
| #endif |
|
|
| static const int kUndefinedValueRootIndex = 4; |
| static const int kTheHoleValueRootIndex = 5; |
| static const int kNullValueRootIndex = 6; |
| static const int kTrueValueRootIndex = 7; |
| static const int kFalseValueRootIndex = 8; |
| static const int kEmptyStringRootIndex = 9; |
|
|
| static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; |
| static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; |
| static const int kNodeStateMask = 0x3; |
| static const int kNodeStateIsWeakValue = 2; |
|
|
| static const int kTracedNodeClassIdOffset = kApiSystemPointerSize; |
|
|
| static const int kFirstNonstringType = 0x80; |
| static const int kOddballType = 0x83; |
| static const int kForeignType = 0xcc; |
| static const int kJSSpecialApiObjectType = 0x410; |
| static const int kJSObjectType = 0x421; |
| static const int kFirstJSApiObjectType = 0x422; |
| static const int kLastJSApiObjectType = 0x80A; |
|
|
| static const int kUndefinedOddballKind = 5; |
| static const int kNullOddballKind = 3; |
|
|
| |
| |
| static const int kThrowOnError = 0; |
| static const int kDontThrow = 1; |
| static const int kInferShouldThrowMode = 2; |
|
|
| |
| |
| static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024; |
|
|
| #ifdef V8_MAP_PACKING |
| static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48; |
| |
| static const uintptr_t kMapWordSignature = 0b10; |
| |
| |
| |
| |
| static const int kMapWordXorMask = 0b11; |
| #endif |
|
|
| V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); |
| V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { |
| #ifdef V8_ENABLE_CHECKS |
| CheckInitializedImpl(isolate); |
| #endif |
| } |
|
|
| V8_INLINE static bool HasHeapObjectTag(Address value) { |
| return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag); |
| } |
|
|
| V8_INLINE static int SmiValue(Address value) { |
| return PlatformSmiTagging::SmiToInt(value); |
| } |
|
|
| V8_INLINE static constexpr Address IntToSmi(int value) { |
| return internal::IntToSmi(value); |
| } |
|
|
| V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { |
| return PlatformSmiTagging::IsValidSmi(value); |
| } |
|
|
| #if V8_STATIC_ROOTS_BOOL |
| V8_INLINE static bool is_identical(Address obj, Tagged_t constant) { |
| return static_cast<Tagged_t>(obj) == constant; |
| } |
|
|
| V8_INLINE static bool CheckInstanceMapRange(Address obj, Tagged_t first_map, |
| Tagged_t last_map) { |
| auto map = ReadRawField<Tagged_t>(obj, kHeapObjectMapOffset); |
| #ifdef V8_MAP_PACKING |
| map = UnpackMapWord(map); |
| #endif |
| return map >= first_map && map <= last_map; |
| } |
| #endif |
|
|
| V8_INLINE static int GetInstanceType(Address obj) { |
| Address map = ReadTaggedPointerField(obj, kHeapObjectMapOffset); |
| #ifdef V8_MAP_PACKING |
| map = UnpackMapWord(map); |
| #endif |
| return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset); |
| } |
|
|
| V8_INLINE static int GetOddballKind(Address obj) { |
| return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset)); |
| } |
|
|
| V8_INLINE static bool IsExternalTwoByteString(int instance_type) { |
| int representation = (instance_type & kStringRepresentationAndEncodingMask); |
| return representation == kExternalTwoByteRepresentationTag; |
| } |
|
|
| V8_INLINE static constexpr bool CanHaveInternalField(int instance_type) { |
| static_assert(kJSObjectType + 1 == kFirstJSApiObjectType); |
| static_assert(kJSObjectType < kLastJSApiObjectType); |
| static_assert(kFirstJSApiObjectType < kLastJSApiObjectType); |
| |
| return instance_type == kJSSpecialApiObjectType || |
| |
| (static_cast<unsigned>(static_cast<unsigned>(instance_type) - |
| static_cast<unsigned>(kJSObjectType)) <= |
| static_cast<unsigned>(kLastJSApiObjectType - kJSObjectType)); |
| } |
|
|
| V8_INLINE static uint8_t GetNodeFlag(Address* obj, int shift) { |
| uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| return *addr & static_cast<uint8_t>(1U << shift); |
| } |
|
|
| V8_INLINE static void UpdateNodeFlag(Address* obj, bool value, int shift) { |
| uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| uint8_t mask = static_cast<uint8_t>(1U << shift); |
| *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift)); |
| } |
|
|
| V8_INLINE static uint8_t GetNodeState(Address* obj) { |
| uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| return *addr & kNodeStateMask; |
| } |
|
|
| V8_INLINE static void UpdateNodeState(Address* obj, uint8_t value) { |
| uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
| *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); |
| } |
|
|
| V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot, |
| void* data) { |
| Address addr = reinterpret_cast<Address>(isolate) + |
| kIsolateEmbedderDataOffset + slot * kApiSystemPointerSize; |
| *reinterpret_cast<void**>(addr) = data; |
| } |
|
|
| V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate, |
| uint32_t slot) { |
| Address addr = reinterpret_cast<Address>(isolate) + |
| kIsolateEmbedderDataOffset + slot * kApiSystemPointerSize; |
| return *reinterpret_cast<void* const*>(addr); |
| } |
|
|
| V8_INLINE static void IncrementLongTasksStatsCounter(v8::Isolate* isolate) { |
| Address addr = |
| reinterpret_cast<Address>(isolate) + kIsolateLongTaskStatsCounterOffset; |
| ++(*reinterpret_cast<size_t*>(addr)); |
| } |
|
|
| V8_INLINE static Address* GetRootSlot(v8::Isolate* isolate, int index) { |
| Address addr = reinterpret_cast<Address>(isolate) + kIsolateRootsOffset + |
| index * kApiSystemPointerSize; |
| return reinterpret_cast<Address*>(addr); |
| } |
|
|
| V8_INLINE static Address GetRoot(v8::Isolate* isolate, int index) { |
| #if V8_STATIC_ROOTS_BOOL |
| Address base = *reinterpret_cast<Address*>( |
| reinterpret_cast<uintptr_t>(isolate) + kIsolateCageBaseOffset); |
| switch (index) { |
| #define DECOMPRESS_ROOT(name) \ |
| case k##name##RootIndex: \ |
| return base + StaticReadOnlyRoot::k##name; |
| EXPORTED_STATIC_ROOTS_PTR_LIST(DECOMPRESS_ROOT) |
| #undef DECOMPRESS_ROOT |
| default: |
| break; |
| } |
| #undef EXPORTED_STATIC_ROOTS_PTR_LIST |
| #endif |
| return *GetRootSlot(isolate, index); |
| } |
|
|
| #ifdef V8_ENABLE_SANDBOX |
| V8_INLINE static Address* GetExternalPointerTableBase(v8::Isolate* isolate) { |
| Address addr = reinterpret_cast<Address>(isolate) + |
| kIsolateExternalPointerTableOffset + |
| kExternalPointerTableBufferOffset; |
| return *reinterpret_cast<Address**>(addr); |
| } |
|
|
| V8_INLINE static Address* GetSharedExternalPointerTableBase( |
| v8::Isolate* isolate) { |
| Address addr = reinterpret_cast<Address>(isolate) + |
| kIsolateSharedExternalPointerTableAddressOffset; |
| addr = *reinterpret_cast<Address*>(addr); |
| addr += kExternalPointerTableBufferOffset; |
| return *reinterpret_cast<Address**>(addr); |
| } |
| #endif |
|
|
| template <typename T> |
| V8_INLINE static T ReadRawField(Address heap_object_ptr, int offset) { |
| Address addr = heap_object_ptr + offset - kHeapObjectTag; |
| #ifdef V8_COMPRESS_POINTERS |
| if (sizeof(T) > kApiTaggedSize) { |
| |
| |
| |
| |
| T r; |
| memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T)); |
| return r; |
| } |
| #endif |
| return *reinterpret_cast<const T*>(addr); |
| } |
|
|
| V8_INLINE static Address ReadTaggedPointerField(Address heap_object_ptr, |
| int offset) { |
| #ifdef V8_COMPRESS_POINTERS |
| uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset); |
| Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr); |
| return base + static_cast<Address>(static_cast<uintptr_t>(value)); |
| #else |
| return ReadRawField<Address>(heap_object_ptr, offset); |
| #endif |
| } |
|
|
| V8_INLINE static Address ReadTaggedSignedField(Address heap_object_ptr, |
| int offset) { |
| #ifdef V8_COMPRESS_POINTERS |
| uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset); |
| return static_cast<Address>(static_cast<uintptr_t>(value)); |
| #else |
| return ReadRawField<Address>(heap_object_ptr, offset); |
| #endif |
| } |
|
|
| V8_INLINE static v8::Isolate* GetIsolateForSandbox(Address obj) { |
| #ifdef V8_ENABLE_SANDBOX |
| return reinterpret_cast<v8::Isolate*>( |
| internal::IsolateFromNeverReadOnlySpaceObject(obj)); |
| #else |
| |
| return nullptr; |
| #endif |
| } |
|
|
| template <ExternalPointerTag tag> |
| V8_INLINE static Address ReadExternalPointerField(v8::Isolate* isolate, |
| Address heap_object_ptr, |
| int offset) { |
| #ifdef V8_ENABLE_SANDBOX |
| static_assert(tag != kExternalPointerNullTag); |
| |
| |
| Address* table = IsSharedExternalPointerType(tag) |
| ? GetSharedExternalPointerTableBase(isolate) |
| : GetExternalPointerTableBase(isolate); |
| internal::ExternalPointerHandle handle = |
| ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset); |
| uint32_t index = handle >> kExternalPointerIndexShift; |
| std::atomic<Address>* ptr = |
| reinterpret_cast<std::atomic<Address>*>(&table[index]); |
| Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed); |
| return entry & ~tag; |
| #else |
| return ReadRawField<Address>(heap_object_ptr, offset); |
| #endif |
| } |
|
|
| #ifdef V8_COMPRESS_POINTERS |
| V8_INLINE static Address GetPtrComprCageBaseFromOnHeapAddress(Address addr) { |
| return addr & -static_cast<intptr_t>(kPtrComprCageBaseAlignment); |
| } |
|
|
| V8_INLINE static Address DecompressTaggedField(Address heap_object_ptr, |
| uint32_t value) { |
| Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr); |
| return base + static_cast<Address>(static_cast<uintptr_t>(value)); |
| } |
|
|
| #endif |
| }; |
|
|
| |
| |
| template <bool PerformCheck> |
| struct CastCheck { |
| template <class T> |
| static void Perform(T* data); |
| }; |
|
|
| template <> |
| template <class T> |
| void CastCheck<true>::Perform(T* data) { |
| T::Cast(data); |
| } |
|
|
| template <> |
| template <class T> |
| void CastCheck<false>::Perform(T* data) {} |
|
|
| template <class T> |
| V8_INLINE void PerformCastCheck(T* data) { |
| CastCheck<std::is_base_of<Data, T>::value && |
| !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data); |
| } |
|
|
| |
| |
| class BackingStoreBase {}; |
|
|
| |
| |
| constexpr int kGarbageCollectionReasonMaxValue = 27; |
|
|
| |
| class ValueHelper final { |
| public: |
| #ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING |
| static constexpr Address kLocalTaggedNullAddress = 1; |
|
|
| template <typename T> |
| static constexpr T* EmptyValue() { |
| return reinterpret_cast<T*>(kLocalTaggedNullAddress); |
| } |
|
|
| template <typename T> |
| V8_INLINE static Address ValueAsAddress(const T* value) { |
| return reinterpret_cast<Address>(value); |
| } |
|
|
| template <typename T, typename S> |
| V8_INLINE static T* SlotAsValue(S* slot) { |
| return *reinterpret_cast<T**>(slot); |
| } |
|
|
| template <typename T> |
| V8_INLINE static T* ValueAsSlot(T* const& value) { |
| return reinterpret_cast<T*>(const_cast<T**>(&value)); |
| } |
|
|
| #else |
|
|
| template <typename T> |
| static constexpr T* EmptyValue() { |
| return nullptr; |
| } |
|
|
| template <typename T> |
| V8_INLINE static Address ValueAsAddress(const T* value) { |
| return *reinterpret_cast<const Address*>(value); |
| } |
|
|
| template <typename T, typename S> |
| V8_INLINE static T* SlotAsValue(S* slot) { |
| return reinterpret_cast<T*>(slot); |
| } |
|
|
| template <typename T> |
| V8_INLINE static T* ValueAsSlot(T* const& value) { |
| return value; |
| } |
|
|
| #endif |
| }; |
|
|
| } |
| } |
|
|
| #endif |
|
|