aha-libv8-node 16.0.0.0-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/libv8-node/.location.yml +1 -0
- data/ext/libv8-node/location.rb +76 -0
- data/ext/libv8-node/paths.rb +30 -0
- data/lib/libv8-node.rb +1 -0
- data/lib/libv8/node.rb +11 -0
- data/lib/libv8/node/version.rb +7 -0
- data/vendor/v8/include/cppgc/allocation.h +229 -0
- data/vendor/v8/include/cppgc/common.h +29 -0
- data/vendor/v8/include/cppgc/cross-thread-persistent.h +345 -0
- data/vendor/v8/include/cppgc/custom-space.h +97 -0
- data/vendor/v8/include/cppgc/default-platform.h +75 -0
- data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
- data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
- data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
- data/vendor/v8/include/cppgc/heap-state.h +59 -0
- data/vendor/v8/include/cppgc/heap-statistics.h +110 -0
- data/vendor/v8/include/cppgc/heap.h +199 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
- data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
- data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +68 -0
- data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
- data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
- data/vendor/v8/include/cppgc/internal/gc-info.h +47 -0
- data/vendor/v8/include/cppgc/internal/logging.h +50 -0
- data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +132 -0
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +143 -0
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
- data/vendor/v8/include/cppgc/internal/write-barrier.h +390 -0
- data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
- data/vendor/v8/include/cppgc/macros.h +26 -0
- data/vendor/v8/include/cppgc/member.h +271 -0
- data/vendor/v8/include/cppgc/name-provider.h +65 -0
- data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
- data/vendor/v8/include/cppgc/persistent.h +365 -0
- data/vendor/v8/include/cppgc/platform.h +151 -0
- data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
- data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
- data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
- data/vendor/v8/include/cppgc/source-location.h +91 -0
- data/vendor/v8/include/cppgc/testing.h +50 -0
- data/vendor/v8/include/cppgc/trace-trait.h +116 -0
- data/vendor/v8/include/cppgc/type-traits.h +228 -0
- data/vendor/v8/include/cppgc/visitor.h +340 -0
- data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
- data/vendor/v8/include/libplatform/libplatform.h +117 -0
- data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
- data/vendor/v8/include/v8-cppgc.h +278 -0
- data/vendor/v8/include/v8-fast-api-calls.h +419 -0
- data/vendor/v8/include/v8-inspector-protocol.h +13 -0
- data/vendor/v8/include/v8-inspector.h +336 -0
- data/vendor/v8/include/v8-internal.h +462 -0
- data/vendor/v8/include/v8-metrics.h +189 -0
- data/vendor/v8/include/v8-platform.h +710 -0
- data/vendor/v8/include/v8-profiler.h +1116 -0
- data/vendor/v8/include/v8-unwinder-state.h +30 -0
- data/vendor/v8/include/v8-util.h +652 -0
- data/vendor/v8/include/v8-value-serializer-version.h +24 -0
- data/vendor/v8/include/v8-version-string.h +38 -0
- data/vendor/v8/include/v8-version.h +20 -0
- data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
- data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
- data/vendor/v8/include/v8.h +12479 -0
- data/vendor/v8/include/v8config.h +521 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
- metadata +137 -0
@@ -0,0 +1,462 @@
|
|
1
|
+
// Copyright 2018 the V8 project authors. All rights reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
3
|
+
// found in the LICENSE file.
|
4
|
+
|
5
|
+
#ifndef INCLUDE_V8_INTERNAL_H_
|
6
|
+
#define INCLUDE_V8_INTERNAL_H_
|
7
|
+
|
8
|
+
#include <stddef.h>
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <type_traits>
|
12
|
+
|
13
|
+
#include "v8-version.h" // NOLINT(build/include_directory)
|
14
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
15
|
+
|
16
|
+
namespace v8 {
|
17
|
+
|
18
|
+
class Context;
|
19
|
+
class Data;
|
20
|
+
class Isolate;
|
21
|
+
|
22
|
+
namespace internal {
|
23
|
+
|
24
|
+
class Isolate;
|
25
|
+
|
26
|
+
typedef uintptr_t Address;
|
27
|
+
static const Address kNullAddress = 0;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Configuration of tagging scheme.
|
31
|
+
*/
|
32
|
+
const int kApiSystemPointerSize = sizeof(void*);
|
33
|
+
const int kApiDoubleSize = sizeof(double);
|
34
|
+
const int kApiInt32Size = sizeof(int32_t);
|
35
|
+
const int kApiInt64Size = sizeof(int64_t);
|
36
|
+
|
37
|
+
// Tag information for HeapObject.
|
38
|
+
const int kHeapObjectTag = 1;
|
39
|
+
const int kWeakHeapObjectTag = 3;
|
40
|
+
const int kHeapObjectTagSize = 2;
|
41
|
+
const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
|
42
|
+
|
43
|
+
// Tag information for Smi.
|
44
|
+
const int kSmiTag = 0;
|
45
|
+
const int kSmiTagSize = 1;
|
46
|
+
const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
|
47
|
+
|
48
|
+
template <size_t tagged_ptr_size>
|
49
|
+
struct SmiTagging;
|
50
|
+
|
51
|
+
constexpr intptr_t kIntptrAllBitsSet = intptr_t{-1};
|
52
|
+
constexpr uintptr_t kUintptrAllBitsSet =
|
53
|
+
static_cast<uintptr_t>(kIntptrAllBitsSet);
|
54
|
+
|
55
|
+
// Smi constants for systems where tagged pointer is a 32-bit value.
|
56
|
+
template <>
|
57
|
+
struct SmiTagging<4> {
|
58
|
+
enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
|
59
|
+
|
60
|
+
static constexpr intptr_t kSmiMinValue =
|
61
|
+
static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
|
62
|
+
static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
|
63
|
+
|
64
|
+
V8_INLINE static int SmiToInt(const internal::Address value) {
|
65
|
+
int shift_bits = kSmiTagSize + kSmiShiftSize;
|
66
|
+
// Truncate and shift down (requires >> to be sign extending).
|
67
|
+
return static_cast<int32_t>(static_cast<uint32_t>(value)) >> shift_bits;
|
68
|
+
}
|
69
|
+
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
|
70
|
+
// Is value in range [kSmiMinValue, kSmiMaxValue].
|
71
|
+
// Use unsigned operations in order to avoid undefined behaviour in case of
|
72
|
+
// signed integer overflow.
|
73
|
+
return (static_cast<uintptr_t>(value) -
|
74
|
+
static_cast<uintptr_t>(kSmiMinValue)) <=
|
75
|
+
(static_cast<uintptr_t>(kSmiMaxValue) -
|
76
|
+
static_cast<uintptr_t>(kSmiMinValue));
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
// Smi constants for systems where tagged pointer is a 64-bit value.
|
81
|
+
template <>
|
82
|
+
struct SmiTagging<8> {
|
83
|
+
enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
|
84
|
+
|
85
|
+
static constexpr intptr_t kSmiMinValue =
|
86
|
+
static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
|
87
|
+
static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
|
88
|
+
|
89
|
+
V8_INLINE static int SmiToInt(const internal::Address value) {
|
90
|
+
int shift_bits = kSmiTagSize + kSmiShiftSize;
|
91
|
+
// Shift down and throw away top 32 bits.
|
92
|
+
return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
|
93
|
+
}
|
94
|
+
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
|
95
|
+
// To be representable as a long smi, the value must be a 32-bit integer.
|
96
|
+
return (value == static_cast<int32_t>(value));
|
97
|
+
}
|
98
|
+
};
|
99
|
+
|
100
|
+
#ifdef V8_COMPRESS_POINTERS
|
101
|
+
static_assert(
|
102
|
+
kApiSystemPointerSize == kApiInt64Size,
|
103
|
+
"Pointer compression can be enabled only for 64-bit architectures");
|
104
|
+
const int kApiTaggedSize = kApiInt32Size;
|
105
|
+
#else
|
106
|
+
const int kApiTaggedSize = kApiSystemPointerSize;
|
107
|
+
#endif
|
108
|
+
|
109
|
+
constexpr bool PointerCompressionIsEnabled() {
|
110
|
+
return kApiTaggedSize != kApiSystemPointerSize;
|
111
|
+
}
|
112
|
+
|
113
|
+
constexpr bool HeapSandboxIsEnabled() {
|
114
|
+
#ifdef V8_HEAP_SANDBOX
|
115
|
+
return true;
|
116
|
+
#else
|
117
|
+
return false;
|
118
|
+
#endif
|
119
|
+
}
|
120
|
+
|
121
|
+
using ExternalPointer_t = Address;
|
122
|
+
|
123
|
+
// If the heap sandbox is enabled, these tag values will be XORed with the
|
124
|
+
// external pointers in the external pointer table to prevent use of pointers of
|
125
|
+
// the wrong type.
|
126
|
+
enum ExternalPointerTag : Address {
|
127
|
+
kExternalPointerNullTag = static_cast<Address>(0ULL),
|
128
|
+
kArrayBufferBackingStoreTag = static_cast<Address>(1ULL << 48),
|
129
|
+
kTypedArrayExternalPointerTag = static_cast<Address>(2ULL << 48),
|
130
|
+
kDataViewDataPointerTag = static_cast<Address>(3ULL << 48),
|
131
|
+
kExternalStringResourceTag = static_cast<Address>(4ULL << 48),
|
132
|
+
kExternalStringResourceDataTag = static_cast<Address>(5ULL << 48),
|
133
|
+
kForeignForeignAddressTag = static_cast<Address>(6ULL << 48),
|
134
|
+
kNativeContextMicrotaskQueueTag = static_cast<Address>(7ULL << 48),
|
135
|
+
// TODO(v8:10391, saelo): Currently has to be zero so that raw zero values are
|
136
|
+
// also nullptr
|
137
|
+
kEmbedderDataSlotPayloadTag = static_cast<Address>(0ULL << 48),
|
138
|
+
};
|
139
|
+
|
140
|
+
#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
|
141
|
+
using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
|
142
|
+
#else
|
143
|
+
using PlatformSmiTagging = SmiTagging<kApiTaggedSize>;
|
144
|
+
#endif
|
145
|
+
|
146
|
+
// TODO(ishell): Consinder adding kSmiShiftBits = kSmiShiftSize + kSmiTagSize
|
147
|
+
// since it's used much more often than the inividual constants.
|
148
|
+
const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
|
149
|
+
const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
|
150
|
+
const int kSmiMinValue = static_cast<int>(PlatformSmiTagging::kSmiMinValue);
|
151
|
+
const int kSmiMaxValue = static_cast<int>(PlatformSmiTagging::kSmiMaxValue);
|
152
|
+
constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
|
153
|
+
constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
|
154
|
+
|
155
|
+
V8_INLINE static constexpr internal::Address IntToSmi(int value) {
|
156
|
+
return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
|
157
|
+
kSmiTag;
|
158
|
+
}
|
159
|
+
|
160
|
+
// Converts encoded external pointer to address.
|
161
|
+
V8_EXPORT Address DecodeExternalPointerImpl(const Isolate* isolate,
|
162
|
+
ExternalPointer_t pointer,
|
163
|
+
ExternalPointerTag tag);
|
164
|
+
|
165
|
+
// {obj} must be the raw tagged pointer representation of a HeapObject
|
166
|
+
// that's guaranteed to never be in ReadOnlySpace.
|
167
|
+
V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
|
168
|
+
|
169
|
+
// Returns if we need to throw when an error occurs. This infers the language
|
170
|
+
// mode based on the current context and the closure. This returns true if the
|
171
|
+
// language mode is strict.
|
172
|
+
V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
|
173
|
+
|
174
|
+
/**
|
175
|
+
* This class exports constants and functionality from within v8 that
|
176
|
+
* is necessary to implement inline functions in the v8 api. Don't
|
177
|
+
* depend on functions and constants defined here.
|
178
|
+
*/
|
179
|
+
class Internals {
|
180
|
+
public:
|
181
|
+
// These values match non-compiler-dependent values defined within
|
182
|
+
// the implementation of v8.
|
183
|
+
static const int kHeapObjectMapOffset = 0;
|
184
|
+
static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size;
|
185
|
+
static const int kStringResourceOffset =
|
186
|
+
1 * kApiTaggedSize + 2 * kApiInt32Size;
|
187
|
+
|
188
|
+
static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
|
189
|
+
static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
|
190
|
+
static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
|
191
|
+
static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
|
192
|
+
static const int kEmbedderDataSlotSize = kApiSystemPointerSize;
|
193
|
+
#ifdef V8_HEAP_SANDBOX
|
194
|
+
static const int kEmbedderDataSlotRawPayloadOffset = kApiTaggedSize;
|
195
|
+
#endif
|
196
|
+
static const int kNativeContextEmbedderDataOffset = 6 * kApiTaggedSize;
|
197
|
+
static const int kFullStringRepresentationMask = 0x0f;
|
198
|
+
static const int kStringEncodingMask = 0x8;
|
199
|
+
static const int kExternalTwoByteRepresentationTag = 0x02;
|
200
|
+
static const int kExternalOneByteRepresentationTag = 0x0a;
|
201
|
+
|
202
|
+
static const uint32_t kNumIsolateDataSlots = 4;
|
203
|
+
|
204
|
+
// IsolateData layout guarantees.
|
205
|
+
static const int kIsolateEmbedderDataOffset = 0;
|
206
|
+
static const int kIsolateFastCCallCallerFpOffset =
|
207
|
+
kNumIsolateDataSlots * kApiSystemPointerSize;
|
208
|
+
static const int kIsolateFastCCallCallerPcOffset =
|
209
|
+
kIsolateFastCCallCallerFpOffset + kApiSystemPointerSize;
|
210
|
+
static const int kIsolateFastApiCallTargetOffset =
|
211
|
+
kIsolateFastCCallCallerPcOffset + kApiSystemPointerSize;
|
212
|
+
static const int kIsolateStackGuardOffset =
|
213
|
+
kIsolateFastApiCallTargetOffset + kApiSystemPointerSize;
|
214
|
+
static const int kIsolateRootsOffset =
|
215
|
+
kIsolateStackGuardOffset + 7 * kApiSystemPointerSize;
|
216
|
+
|
217
|
+
static const int kExternalPointerTableBufferOffset = 0;
|
218
|
+
static const int kExternalPointerTableLengthOffset =
|
219
|
+
kExternalPointerTableBufferOffset + kApiSystemPointerSize;
|
220
|
+
static const int kExternalPointerTableCapacityOffset =
|
221
|
+
kExternalPointerTableLengthOffset + kApiInt32Size;
|
222
|
+
|
223
|
+
static const int kUndefinedValueRootIndex = 4;
|
224
|
+
static const int kTheHoleValueRootIndex = 5;
|
225
|
+
static const int kNullValueRootIndex = 6;
|
226
|
+
static const int kTrueValueRootIndex = 7;
|
227
|
+
static const int kFalseValueRootIndex = 8;
|
228
|
+
static const int kEmptyStringRootIndex = 9;
|
229
|
+
|
230
|
+
static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize;
|
231
|
+
static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
|
232
|
+
static const int kNodeStateMask = 0x7;
|
233
|
+
static const int kNodeStateIsWeakValue = 2;
|
234
|
+
static const int kNodeStateIsPendingValue = 3;
|
235
|
+
|
236
|
+
static const int kFirstNonstringType = 0x40;
|
237
|
+
static const int kOddballType = 0x43;
|
238
|
+
static const int kForeignType = 0x46;
|
239
|
+
static const int kJSSpecialApiObjectType = 0x410;
|
240
|
+
static const int kJSApiObjectType = 0x420;
|
241
|
+
static const int kJSObjectType = 0x421;
|
242
|
+
|
243
|
+
static const int kUndefinedOddballKind = 5;
|
244
|
+
static const int kNullOddballKind = 3;
|
245
|
+
|
246
|
+
// Constants used by PropertyCallbackInfo to check if we should throw when an
|
247
|
+
// error occurs.
|
248
|
+
static const int kThrowOnError = 0;
|
249
|
+
static const int kDontThrow = 1;
|
250
|
+
static const int kInferShouldThrowMode = 2;
|
251
|
+
|
252
|
+
// Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
|
253
|
+
// incremental GC once the external memory reaches this limit.
|
254
|
+
static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
|
255
|
+
|
256
|
+
V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
|
257
|
+
V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
|
258
|
+
#ifdef V8_ENABLE_CHECKS
|
259
|
+
CheckInitializedImpl(isolate);
|
260
|
+
#endif
|
261
|
+
}
|
262
|
+
|
263
|
+
V8_INLINE static bool HasHeapObjectTag(const internal::Address value) {
|
264
|
+
return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
|
265
|
+
}
|
266
|
+
|
267
|
+
V8_INLINE static int SmiValue(const internal::Address value) {
|
268
|
+
return PlatformSmiTagging::SmiToInt(value);
|
269
|
+
}
|
270
|
+
|
271
|
+
V8_INLINE static constexpr internal::Address IntToSmi(int value) {
|
272
|
+
return internal::IntToSmi(value);
|
273
|
+
}
|
274
|
+
|
275
|
+
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
|
276
|
+
return PlatformSmiTagging::IsValidSmi(value);
|
277
|
+
}
|
278
|
+
|
279
|
+
V8_INLINE static int GetInstanceType(const internal::Address obj) {
|
280
|
+
typedef internal::Address A;
|
281
|
+
A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset);
|
282
|
+
return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
|
283
|
+
}
|
284
|
+
|
285
|
+
V8_INLINE static int GetOddballKind(const internal::Address obj) {
|
286
|
+
return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset));
|
287
|
+
}
|
288
|
+
|
289
|
+
V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
|
290
|
+
int representation = (instance_type & kFullStringRepresentationMask);
|
291
|
+
return representation == kExternalTwoByteRepresentationTag;
|
292
|
+
}
|
293
|
+
|
294
|
+
V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) {
|
295
|
+
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
|
296
|
+
return *addr & static_cast<uint8_t>(1U << shift);
|
297
|
+
}
|
298
|
+
|
299
|
+
V8_INLINE static void UpdateNodeFlag(internal::Address* obj, bool value,
|
300
|
+
int shift) {
|
301
|
+
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
|
302
|
+
uint8_t mask = static_cast<uint8_t>(1U << shift);
|
303
|
+
*addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
|
304
|
+
}
|
305
|
+
|
306
|
+
V8_INLINE static uint8_t GetNodeState(internal::Address* obj) {
|
307
|
+
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
|
308
|
+
return *addr & kNodeStateMask;
|
309
|
+
}
|
310
|
+
|
311
|
+
V8_INLINE static void UpdateNodeState(internal::Address* obj, uint8_t value) {
|
312
|
+
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
|
313
|
+
*addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
|
314
|
+
}
|
315
|
+
|
316
|
+
V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
|
317
|
+
void* data) {
|
318
|
+
internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
|
319
|
+
kIsolateEmbedderDataOffset +
|
320
|
+
slot * kApiSystemPointerSize;
|
321
|
+
*reinterpret_cast<void**>(addr) = data;
|
322
|
+
}
|
323
|
+
|
324
|
+
V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
|
325
|
+
uint32_t slot) {
|
326
|
+
internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
|
327
|
+
kIsolateEmbedderDataOffset +
|
328
|
+
slot * kApiSystemPointerSize;
|
329
|
+
return *reinterpret_cast<void* const*>(addr);
|
330
|
+
}
|
331
|
+
|
332
|
+
V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) {
|
333
|
+
internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
|
334
|
+
kIsolateRootsOffset +
|
335
|
+
index * kApiSystemPointerSize;
|
336
|
+
return reinterpret_cast<internal::Address*>(addr);
|
337
|
+
}
|
338
|
+
|
339
|
+
template <typename T>
|
340
|
+
V8_INLINE static T ReadRawField(internal::Address heap_object_ptr,
|
341
|
+
int offset) {
|
342
|
+
internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
|
343
|
+
#ifdef V8_COMPRESS_POINTERS
|
344
|
+
if (sizeof(T) > kApiTaggedSize) {
|
345
|
+
// TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
|
346
|
+
// fields (external pointers, doubles and BigInt data) are only
|
347
|
+
// kTaggedSize aligned so we have to use unaligned pointer friendly way of
|
348
|
+
// accessing them in order to avoid undefined behavior in C++ code.
|
349
|
+
T r;
|
350
|
+
memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
|
351
|
+
return r;
|
352
|
+
}
|
353
|
+
#endif
|
354
|
+
return *reinterpret_cast<const T*>(addr);
|
355
|
+
}
|
356
|
+
|
357
|
+
V8_INLINE static internal::Address ReadTaggedPointerField(
|
358
|
+
internal::Address heap_object_ptr, int offset) {
|
359
|
+
#ifdef V8_COMPRESS_POINTERS
|
360
|
+
uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
|
361
|
+
internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
|
362
|
+
return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
|
363
|
+
#else
|
364
|
+
return ReadRawField<internal::Address>(heap_object_ptr, offset);
|
365
|
+
#endif
|
366
|
+
}
|
367
|
+
|
368
|
+
V8_INLINE static internal::Address ReadTaggedSignedField(
|
369
|
+
internal::Address heap_object_ptr, int offset) {
|
370
|
+
#ifdef V8_COMPRESS_POINTERS
|
371
|
+
uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
|
372
|
+
return static_cast<internal::Address>(static_cast<uintptr_t>(value));
|
373
|
+
#else
|
374
|
+
return ReadRawField<internal::Address>(heap_object_ptr, offset);
|
375
|
+
#endif
|
376
|
+
}
|
377
|
+
|
378
|
+
V8_INLINE static internal::Isolate* GetIsolateForHeapSandbox(
|
379
|
+
internal::Address obj) {
|
380
|
+
#ifdef V8_HEAP_SANDBOX
|
381
|
+
return internal::IsolateFromNeverReadOnlySpaceObject(obj);
|
382
|
+
#else
|
383
|
+
// Not used in non-sandbox mode.
|
384
|
+
return nullptr;
|
385
|
+
#endif
|
386
|
+
}
|
387
|
+
|
388
|
+
V8_INLINE static Address DecodeExternalPointer(
|
389
|
+
const Isolate* isolate, ExternalPointer_t encoded_pointer,
|
390
|
+
ExternalPointerTag tag) {
|
391
|
+
#ifdef V8_HEAP_SANDBOX
|
392
|
+
return internal::DecodeExternalPointerImpl(isolate, encoded_pointer, tag);
|
393
|
+
#else
|
394
|
+
return encoded_pointer;
|
395
|
+
#endif
|
396
|
+
}
|
397
|
+
|
398
|
+
V8_INLINE static internal::Address ReadExternalPointerField(
|
399
|
+
internal::Isolate* isolate, internal::Address heap_object_ptr, int offset,
|
400
|
+
ExternalPointerTag tag) {
|
401
|
+
#ifdef V8_HEAP_SANDBOX
|
402
|
+
internal::ExternalPointer_t encoded_value =
|
403
|
+
ReadRawField<uint32_t>(heap_object_ptr, offset);
|
404
|
+
// We currently have to treat zero as nullptr in embedder slots.
|
405
|
+
return encoded_value ? DecodeExternalPointer(isolate, encoded_value, tag)
|
406
|
+
: 0;
|
407
|
+
#else
|
408
|
+
return ReadRawField<Address>(heap_object_ptr, offset);
|
409
|
+
#endif
|
410
|
+
}
|
411
|
+
|
412
|
+
#ifdef V8_COMPRESS_POINTERS
|
413
|
+
// See v8:7703 or src/ptr-compr.* for details about pointer compression.
|
414
|
+
static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32;
|
415
|
+
static constexpr size_t kPtrComprIsolateRootAlignment = size_t{1} << 32;
|
416
|
+
|
417
|
+
V8_INLINE static internal::Address GetRootFromOnHeapAddress(
|
418
|
+
internal::Address addr) {
|
419
|
+
return addr & -static_cast<intptr_t>(kPtrComprIsolateRootAlignment);
|
420
|
+
}
|
421
|
+
|
422
|
+
V8_INLINE static internal::Address DecompressTaggedAnyField(
|
423
|
+
internal::Address heap_object_ptr, uint32_t value) {
|
424
|
+
internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
|
425
|
+
return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
|
426
|
+
}
|
427
|
+
|
428
|
+
#endif // V8_COMPRESS_POINTERS
|
429
|
+
};
|
430
|
+
|
431
|
+
// Only perform cast check for types derived from v8::Data since
|
432
|
+
// other types do not implement the Cast method.
|
433
|
+
template <bool PerformCheck>
|
434
|
+
struct CastCheck {
|
435
|
+
template <class T>
|
436
|
+
static void Perform(T* data);
|
437
|
+
};
|
438
|
+
|
439
|
+
template <>
|
440
|
+
template <class T>
|
441
|
+
void CastCheck<true>::Perform(T* data) {
|
442
|
+
T::Cast(data);
|
443
|
+
}
|
444
|
+
|
445
|
+
template <>
|
446
|
+
template <class T>
|
447
|
+
void CastCheck<false>::Perform(T* data) {}
|
448
|
+
|
449
|
+
template <class T>
|
450
|
+
V8_INLINE void PerformCastCheck(T* data) {
|
451
|
+
CastCheck<std::is_base_of<Data, T>::value &&
|
452
|
+
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
|
453
|
+
}
|
454
|
+
|
455
|
+
// A base class for backing stores, which is needed due to vagaries of
|
456
|
+
// how static casts work with std::shared_ptr.
|
457
|
+
class BackingStoreBase {};
|
458
|
+
|
459
|
+
} // namespace internal
|
460
|
+
} // namespace v8
|
461
|
+
|
462
|
+
#endif // INCLUDE_V8_INTERNAL_H_
|