5 #ifndef INCLUDE_V8_INTERNAL_H_ 6 #define INCLUDE_V8_INTERNAL_H_ 10 #include <type_traits> 12 #include "v8-version.h" 24 static const Address kNullAddress = 0;
29 const int kApiSystemPointerSize =
sizeof(
void*);
30 const int kApiTaggedSize = kApiSystemPointerSize;
31 const int kApiDoubleSize =
sizeof(double);
32 const int kApiIntSize =
sizeof(
int);
33 const int kApiInt64Size =
sizeof(
int64_t);
36 const int kHeapObjectTag = 1;
37 const int kWeakHeapObjectTag = 3;
38 const int kHeapObjectTagSize = 2;
39 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
42 const int kSmiTag = 0;
43 const int kSmiTagSize = 1;
44 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
46 template <
size_t tagged_ptr_size>
52 enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
54 int shift_bits = kSmiTagSize + kSmiShiftSize;
56 return static_cast<int>(
static_cast<intptr_t
>(value)) >> shift_bits;
58 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
70 return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
77 enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
79 int shift_bits = kSmiTagSize + kSmiShiftSize;
81 return static_cast<int>(
static_cast<intptr_t
>(value) >> shift_bits);
83 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
85 return (value == static_cast<int32_t>(value));
89 #if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH) 91 kApiSystemPointerSize == kApiInt64Size,
92 "Pointer compression can be enabled only for 64-bit architectures");
98 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
99 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
100 const int kSmiMinValue = (
static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
101 const int kSmiMaxValue = -(kSmiMinValue + 1);
102 constexpr
bool SmiValuesAre31Bits() {
return kSmiValueSize == 31; }
103 constexpr
bool SmiValuesAre32Bits() {
return kSmiValueSize == 32; }
105 V8_INLINE
static constexpr internal::Address IntToSmi(
int value) {
106 return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
119 static const int kHeapObjectMapOffset = 0;
120 static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiIntSize;
121 static const int kStringResourceOffset = 1 * kApiTaggedSize + 2 * kApiIntSize;
123 static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
124 static const int kForeignAddressOffset = kApiTaggedSize;
125 static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
126 static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
127 static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
128 static const int kEmbedderDataSlotSize =
129 #ifdef V8_COMPRESS_POINTERS 132 kApiSystemPointerSize;
133 static const int kNativeContextEmbedderDataOffset = 7 * kApiTaggedSize;
134 static const int kFullStringRepresentationMask = 0x0f;
135 static const int kStringEncodingMask = 0x8;
136 static const int kExternalTwoByteRepresentationTag = 0x02;
137 static const int kExternalOneByteRepresentationTag = 0x0a;
139 static const uint32_t kNumIsolateDataSlots = 4;
141 static const int kIsolateEmbedderDataOffset = 0;
142 static const int kExternalMemoryOffset =
143 kNumIsolateDataSlots * kApiTaggedSize;
144 static const int kExternalMemoryLimitOffset =
145 kExternalMemoryOffset + kApiInt64Size;
146 static const int kExternalMemoryAtLastMarkCompactOffset =
147 kExternalMemoryLimitOffset + kApiInt64Size;
148 static const int kIsolateRootsOffset =
149 kExternalMemoryAtLastMarkCompactOffset + kApiInt64Size;
151 static const int kUndefinedValueRootIndex = 4;
152 static const int kTheHoleValueRootIndex = 5;
153 static const int kNullValueRootIndex = 6;
154 static const int kTrueValueRootIndex = 7;
155 static const int kFalseValueRootIndex = 8;
156 static const int kEmptyStringRootIndex = 9;
158 static const int kNodeClassIdOffset = 1 * kApiTaggedSize;
159 static const int kNodeFlagsOffset = 1 * kApiTaggedSize + 3;
160 static const int kNodeStateMask = 0x7;
161 static const int kNodeStateIsWeakValue = 2;
162 static const int kNodeStateIsPendingValue = 3;
163 static const int kNodeStateIsNearDeathValue = 4;
164 static const int kNodeIsIndependentShift = 3;
165 static const int kNodeIsActiveShift = 4;
167 static const int kFirstNonstringType = 0x80;
168 static const int kOddballType = 0x83;
169 static const int kForeignType = 0x87;
170 static const int kJSSpecialApiObjectType = 0x410;
171 static const int kJSApiObjectType = 0x420;
172 static const int kJSObjectType = 0x421;
174 static const int kUndefinedOddballKind = 5;
175 static const int kNullOddballKind = 3;
179 static constexpr
int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
181 V8_EXPORT
static void CheckInitializedImpl(v8::Isolate* isolate);
182 V8_INLINE
static void CheckInitialized(v8::Isolate* isolate) {
183 #ifdef V8_ENABLE_CHECKS 184 CheckInitializedImpl(isolate);
189 return (value & kHeapObjectTagMask) ==
static_cast<Address>(kHeapObjectTag);
193 return PlatformSmiTagging::SmiToInt(value);
197 return internal::IntToSmi(value);
200 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
201 return PlatformSmiTagging::IsValidSmi(value);
206 A map = ReadField<A>(obj, kHeapObjectMapOffset);
207 return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
211 return SmiValue(ReadField<internal::Address>(obj, kOddballKindOffset));
214 V8_INLINE
static bool IsExternalTwoByteString(
int instance_type) {
215 int representation = (instance_type & kFullStringRepresentationMask);
216 return representation == kExternalTwoByteRepresentationTag;
220 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + kNodeFlagsOffset;
221 return *addr &
static_cast<uint8_t
>(1U << shift);
226 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + kNodeFlagsOffset;
227 uint8_t mask =
static_cast<uint8_t
>(1U << shift);
228 *addr =
static_cast<uint8_t
>((*addr & ~mask) | (value << shift));
232 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + kNodeFlagsOffset;
233 return *addr & kNodeStateMask;
237 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + kNodeFlagsOffset;
238 *addr =
static_cast<uint8_t
>((*addr & ~kNodeStateMask) | value);
241 V8_INLINE
static void SetEmbedderData(v8::Isolate* isolate,
uint32_t slot,
244 kIsolateEmbedderDataOffset +
245 slot * kApiSystemPointerSize;
246 *
reinterpret_cast<void**
>(addr) = data;
249 V8_INLINE
static void* GetEmbedderData(
const v8::Isolate* isolate,
252 kIsolateEmbedderDataOffset +
253 slot * kApiSystemPointerSize;
254 return *
reinterpret_cast<void* const*
>(addr);
259 kIsolateRootsOffset +
260 index * kApiSystemPointerSize;
264 template <
typename T>
268 return *
reinterpret_cast<const T*
>(addr);
271 #ifndef V8_COMPRESS_POINTERS 272 template <
typename T>
273 V8_INLINE
static T ReadEmbedderData(
const v8::Context* context,
int index) {
276 A ctx = *
reinterpret_cast<const A*
>(context);
277 A embedder_data = I::ReadField<A>(ctx, I::kNativeContextEmbedderDataOffset);
279 I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
280 return I::ReadField<T>(embedder_data, value_offset);
287 template <
bool PerformCheck>
290 static void Perform(
T* data);
301 void CastCheck<false>::Perform(
T* data) {}
304 V8_INLINE
void PerformCastCheck(T* data) {
305 CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
311 #endif // INCLUDE_V8_INTERNAL_H_