5 #ifndef INCLUDE_V8_INTERNAL_H_ 6 #define INCLUDE_V8_INTERNAL_H_ 10 #include <type_traits> 12 #include "v8-version.h" 25 typedef uintptr_t Address;
26 static const Address kNullAddress = 0;
31 const int kApiSystemPointerSize =
sizeof(
void*);
32 const int kApiTaggedSize = kApiSystemPointerSize;
33 const int kApiDoubleSize =
sizeof(double);
34 const int kApiInt32Size =
sizeof(int32_t);
35 const int kApiInt64Size =
sizeof(int64_t);
38 const int kHeapObjectTag = 1;
39 const int kWeakHeapObjectTag = 3;
40 const int kHeapObjectTagSize = 2;
41 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
44 const int kSmiTag = 0;
45 const int kSmiTagSize = 1;
46 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
48 template <
size_t tagged_ptr_size>
54 enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
55 V8_INLINE
static int SmiToInt(
const internal::Address value) {
56 int shift_bits = kSmiTagSize + kSmiShiftSize;
58 return static_cast<int>(static_cast<intptr_t>(value)) >> shift_bits;
60 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
72 return static_cast<uintptr_t>(value) + 0x40000000U < 0x80000000U;
79 enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
80 V8_INLINE
static int SmiToInt(
const internal::Address value) {
81 int shift_bits = kSmiTagSize + kSmiShiftSize;
83 return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
85 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
87 return (value == static_cast<int32_t>(value));
91 #ifdef V8_COMPRESS_POINTERS 93 kApiSystemPointerSize == kApiInt64Size,
94 "Pointer compression can be enabled only for 64-bit architectures");
97 #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH 103 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
104 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
105 const int kSmiMinValue = (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
106 const int kSmiMaxValue = -(kSmiMinValue + 1);
107 constexpr
bool SmiValuesAre31Bits() {
return kSmiValueSize == 31; }
108 constexpr
bool SmiValuesAre32Bits() {
return kSmiValueSize == 32; }
110 V8_INLINE
static constexpr internal::Address IntToSmi(
int value) {
111 return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
124 static const int kHeapObjectMapOffset = 0;
125 static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size;
126 static const int kStringResourceOffset =
127 1 * kApiTaggedSize + 2 * kApiInt32Size;
129 static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
130 static const int kForeignAddressOffset = kApiTaggedSize;
131 static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
132 static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
133 static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
134 static const int kEmbedderDataSlotSize =
135 #ifdef V8_COMPRESS_POINTERS 138 kApiSystemPointerSize;
139 static const int kNativeContextEmbedderDataOffset = 7 * kApiTaggedSize;
140 static const int kFullStringRepresentationMask = 0x0f;
141 static const int kStringEncodingMask = 0x8;
142 static const int kExternalTwoByteRepresentationTag = 0x02;
143 static const int kExternalOneByteRepresentationTag = 0x0a;
145 static const uint32_t kNumIsolateDataSlots = 4;
147 static const int kIsolateEmbedderDataOffset = 0;
148 static const int kExternalMemoryOffset =
149 kNumIsolateDataSlots * kApiSystemPointerSize;
150 static const int kExternalMemoryLimitOffset =
151 kExternalMemoryOffset + kApiInt64Size;
152 static const int kExternalMemoryAtLastMarkCompactOffset =
153 kExternalMemoryLimitOffset + kApiInt64Size;
154 static const int kIsolateRootsOffset =
155 kExternalMemoryAtLastMarkCompactOffset + kApiInt64Size;
157 static const int kUndefinedValueRootIndex = 4;
158 static const int kTheHoleValueRootIndex = 5;
159 static const int kNullValueRootIndex = 6;
160 static const int kTrueValueRootIndex = 7;
161 static const int kFalseValueRootIndex = 8;
162 static const int kEmptyStringRootIndex = 9;
164 static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize;
165 static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
166 static const int kNodeStateMask = 0x7;
167 static const int kNodeStateIsWeakValue = 2;
168 static const int kNodeStateIsPendingValue = 3;
169 static const int kNodeStateIsNearDeathValue = 4;
170 static const int kNodeIsIndependentShift = 3;
171 static const int kNodeIsActiveShift = 4;
173 static const int kFirstNonstringType = 0x40;
174 static const int kOddballType = 0x43;
175 static const int kForeignType = 0x47;
176 static const int kJSSpecialApiObjectType = 0x410;
177 static const int kJSApiObjectType = 0x420;
178 static const int kJSObjectType = 0x421;
180 static const int kUndefinedOddballKind = 5;
181 static const int kNullOddballKind = 3;
185 static const int kThrowOnError = 0;
186 static const int kDontThrow = 1;
187 static const int kInferShouldThrowMode = 2;
191 static constexpr
int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
193 V8_EXPORT
static void CheckInitializedImpl(
v8::Isolate* isolate);
194 V8_INLINE
static void CheckInitialized(
v8::Isolate* isolate) {
195 #ifdef V8_ENABLE_CHECKS 196 CheckInitializedImpl(isolate);
200 V8_INLINE
static bool HasHeapObjectTag(
const internal::Address value) {
201 return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
204 V8_INLINE
static int SmiValue(
const internal::Address value) {
205 return PlatformSmiTagging::SmiToInt(value);
208 V8_INLINE
static constexpr internal::Address IntToSmi(
int value) {
209 return internal::IntToSmi(value);
212 V8_INLINE
static constexpr
bool IsValidSmi(intptr_t value) {
213 return PlatformSmiTagging::IsValidSmi(value);
216 V8_INLINE
static int GetInstanceType(
const internal::Address obj) {
217 typedef internal::Address A;
218 A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset);
219 return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
222 V8_INLINE
static int GetOddballKind(
const internal::Address obj) {
223 return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset));
226 V8_INLINE
static bool IsExternalTwoByteString(
int instance_type) {
227 int representation = (instance_type & kFullStringRepresentationMask);
228 return representation == kExternalTwoByteRepresentationTag;
231 V8_INLINE
static uint8_t GetNodeFlag(internal::Address* obj,
int shift) {
232 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
233 return *addr & static_cast<uint8_t>(1U << shift);
236 V8_INLINE
static void UpdateNodeFlag(internal::Address* obj,
bool value,
238 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
239 uint8_t mask = static_cast<uint8_t>(1U << shift);
240 *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
243 V8_INLINE
static uint8_t GetNodeState(internal::Address* obj) {
244 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
245 return *addr & kNodeStateMask;
248 V8_INLINE
static void UpdateNodeState(internal::Address* obj, uint8_t value) {
249 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
250 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
253 V8_INLINE
static void SetEmbedderData(
v8::Isolate* isolate, uint32_t slot,
255 internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
256 kIsolateEmbedderDataOffset +
257 slot * kApiSystemPointerSize;
258 *reinterpret_cast<void**>(addr) = data;
261 V8_INLINE
static void* GetEmbedderData(
const v8::Isolate* isolate,
263 internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
264 kIsolateEmbedderDataOffset +
265 slot * kApiSystemPointerSize;
266 return *reinterpret_cast<void* const*>(addr);
269 V8_INLINE
static internal::Address* GetRoot(
v8::Isolate* isolate,
int index) {
270 internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
271 kIsolateRootsOffset +
272 index * kApiSystemPointerSize;
273 return reinterpret_cast<internal::Address*>(addr);
276 template <
typename T>
277 V8_INLINE
static T ReadRawField(internal::Address heap_object_ptr,
279 internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
280 return *reinterpret_cast<const T*>(addr);
283 V8_INLINE
static internal::Address ReadTaggedPointerField(
284 internal::Address heap_object_ptr,
int offset) {
285 #ifdef V8_COMPRESS_POINTERS 286 int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
287 internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
288 return root + static_cast<internal::Address>(static_cast<intptr_t>(value));
290 return ReadRawField<internal::Address>(heap_object_ptr, offset);
294 V8_INLINE
static internal::Address ReadTaggedSignedField(
295 internal::Address heap_object_ptr,
int offset) {
296 #ifdef V8_COMPRESS_POINTERS 297 int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
298 return static_cast<internal::Address>(static_cast<intptr_t>(value));
300 return ReadRawField<internal::Address>(heap_object_ptr, offset);
304 V8_INLINE
static internal::Address ReadTaggedAnyField(
305 internal::Address heap_object_ptr,
int offset) {
306 #ifdef V8_COMPRESS_POINTERS 307 int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
308 internal::Address root_mask = static_cast<internal::Address>(
309 -static_cast<intptr_t>(value & kSmiTagMask));
310 internal::Address root_or_zero =
311 root_mask & GetRootFromOnHeapAddress(heap_object_ptr);
312 return root_or_zero +
313 static_cast<internal::Address>(static_cast<intptr_t>(value));
315 return ReadRawField<internal::Address>(heap_object_ptr, offset);
319 #ifdef V8_COMPRESS_POINTERS 320 static constexpr
size_t kPtrComprHeapReservationSize =
size_t{1} << 32;
321 static constexpr
size_t kPtrComprIsolateRootBias =
322 kPtrComprHeapReservationSize / 2;
323 static constexpr
size_t kPtrComprIsolateRootAlignment =
size_t{1} << 32;
325 V8_INLINE
static internal::Address GetRootFromOnHeapAddress(
326 internal::Address addr) {
327 return (addr + kPtrComprIsolateRootBias) &
328 -static_cast<intptr_t>(kPtrComprIsolateRootAlignment);
333 template <
typename T>
334 V8_INLINE
static T ReadEmbedderData(
const v8::Context* context,
int index) {
335 typedef internal::Address A;
337 A ctx = *reinterpret_cast<const A*>(context);
339 I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
341 I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
342 return I::ReadRawField<T>(embedder_data, value_offset);
344 #endif // V8_COMPRESS_POINTERS 349 template <
bool PerformCheck>
352 static void Perform(T* data);
363 void CastCheck<false>::Perform(T* data) {}
366 V8_INLINE
void PerformCastCheck(T* data) {
367 CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
372 V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
377 V8_EXPORT
bool ShouldThrowOnError(v8::internal::Isolate* isolate);
382 #endif // INCLUDE_V8_INTERNAL_H_ Definition: v8-internal.h:120
Definition: v8-internal.h:49
Definition: v8-internal.h:15
Definition: v8-internal.h:350