@@ -33,13 +33,21 @@ const int kApiSystemPointerSize = sizeof(void*);
33
33
const int kApiDoubleSize = sizeof (double );
34
34
const int kApiInt32Size = sizeof (int32_t );
35
35
const int kApiInt64Size = sizeof (int64_t );
36
+ const int kApiSizetSize = sizeof (size_t );
36
37
37
38
// Tag information for HeapObject.
38
39
const int kHeapObjectTag = 1 ;
39
40
const int kWeakHeapObjectTag = 3 ;
40
41
const int kHeapObjectTagSize = 2 ;
41
42
const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize ) - 1 ;
42
43
44
+ // Tag information for fowarding pointers stored in object headers.
45
+ // 0b00 at the lowest 2 bits in the header indicates that the map word is a
46
+ // forwarding pointer.
47
+ const int kForwardingTag = 0 ;
48
+ const int kForwardingTagSize = 2 ;
49
+ const intptr_t kForwardingTagMask = (1 << kForwardingTagSize ) - 1 ;
50
+
43
51
// Tag information for Smi.
44
52
const int kSmiTag = 0 ;
45
53
const int kSmiTagSize = 1 ;
@@ -120,23 +128,28 @@ constexpr bool HeapSandboxIsEnabled() {
120
128
121
129
using ExternalPointer_t = Address;
122
130
123
- // If the heap sandbox is enabled, these tag values will be XORed with the
131
+ // If the heap sandbox is enabled, these tag values will be ORed with the
124
132
// 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 ),
133
+ // the wrong type. When a pointer is loaded, it is ANDed with the inverse of the
134
+ // expected type's tag. The tags are constructed in a way that guarantees that a
135
+ // failed type check will result in one or more of the top bits of the pointer
136
+ // to be set, rendering the pointer inacessible. This construction allows
137
+ // performing the type check and removing GC marking bits from the pointer at
138
+ // the same time.
139
+ enum ExternalPointerTag : uint64_t {
140
+ kExternalPointerNullTag = 0x0000000000000000 ,
141
+ kArrayBufferBackingStoreTag = 0x00ff000000000000 , // 0b000000011111111
142
+ kTypedArrayExternalPointerTag = 0x017f000000000000 , // 0b000000101111111
143
+ kDataViewDataPointerTag = 0x01bf000000000000 , // 0b000000110111111
144
+ kExternalStringResourceTag = 0x01df000000000000 , // 0b000000111011111
145
+ kExternalStringResourceDataTag = 0x01ef000000000000 , // 0b000000111101111
146
+ kForeignForeignAddressTag = 0x01f7000000000000 , // 0b000000111110111
147
+ kNativeContextMicrotaskQueueTag = 0x01fb000000000000 , // 0b000000111111011
148
+ kEmbedderDataSlotPayloadTag = 0x01fd000000000000 , // 0b000000111111101
138
149
};
139
150
151
+ constexpr uint64_t kExternalPointerTagMask = 0xffff000000000000 ;
152
+
140
153
#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
141
154
using PlatformSmiTagging = SmiTagging<kApiInt32Size >;
142
155
#else
@@ -177,6 +190,14 @@ V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
177
190
* depend on functions and constants defined here.
178
191
*/
179
192
class Internals {
193
+ #ifdef V8_MAP_PACKING
194
+ V8_INLINE static constexpr internal::Address UnpackMapWord (
195
+ internal::Address mapword) {
196
+ // TODO(wenyuzhao): Clear header metadata.
197
+ return mapword ^ kMapWordXorMask ;
198
+ }
199
+ #endif
200
+
180
201
public:
181
202
// These values match non-compiler-dependent values defined within
182
203
// the implementation of v8.
@@ -207,8 +228,14 @@ class Internals {
207
228
kNumIsolateDataSlots * kApiSystemPointerSize ;
208
229
static const int kIsolateFastCCallCallerPcOffset =
209
230
kIsolateFastCCallCallerFpOffset + kApiSystemPointerSize ;
210
- static const int kIsolateStackGuardOffset =
231
+ static const int kIsolateFastApiCallTargetOffset =
211
232
kIsolateFastCCallCallerPcOffset + kApiSystemPointerSize ;
233
+ static const int kIsolateCageBaseOffset =
234
+ kIsolateFastApiCallTargetOffset + kApiSystemPointerSize ;
235
+ static const int kIsolateLongTaskStatsCounterOffset =
236
+ kIsolateCageBaseOffset + kApiSystemPointerSize ;
237
+ static const int kIsolateStackGuardOffset =
238
+ kIsolateLongTaskStatsCounterOffset + kApiSizetSize ;
212
239
static const int kIsolateRootsOffset =
213
240
kIsolateStackGuardOffset + 7 * kApiSystemPointerSize ;
214
241
@@ -251,6 +278,17 @@ class Internals {
251
278
// incremental GC once the external memory reaches this limit.
252
279
static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024 ;
253
280
281
+ #ifdef V8_MAP_PACKING
282
+ static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48 ;
283
+ // The lowest two bits of mapwords are always `0b10`
284
+ static const uintptr_t kMapWordSignature = 0b10 ;
285
+ // XORing a (non-compressed) map with this mask ensures that the two
286
+ // low-order bits are 0b10. The 0 at the end makes this look like a Smi,
287
+ // although real Smis have all lower 32 bits unset. We only rely on these
288
+ // values passing as Smis in very few places.
289
+ static const int kMapWordXorMask = 0b11 ;
290
+ #endif
291
+
254
292
V8_EXPORT static void CheckInitializedImpl (v8::Isolate* isolate);
255
293
V8_INLINE static void CheckInitialized (v8::Isolate* isolate) {
256
294
#ifdef V8_ENABLE_CHECKS
@@ -277,6 +315,9 @@ class Internals {
277
315
V8_INLINE static int GetInstanceType (const internal::Address obj) {
278
316
typedef internal::Address A;
279
317
A map = ReadTaggedPointerField (obj, kHeapObjectMapOffset );
318
+ #ifdef V8_MAP_PACKING
319
+ map = UnpackMapWord (map);
320
+ #endif
280
321
return ReadRawField<uint16_t >(map, kMapInstanceTypeOffset );
281
322
}
282
323
@@ -327,6 +368,12 @@ class Internals {
327
368
return *reinterpret_cast <void * const *>(addr);
328
369
}
329
370
371
+ V8_INLINE static void IncrementLongTasksStatsCounter (v8::Isolate* isolate) {
372
+ internal::Address addr = reinterpret_cast <internal::Address>(isolate) +
373
+ kIsolateLongTaskStatsCounterOffset ;
374
+ ++(*reinterpret_cast <size_t *>(addr));
375
+ }
376
+
330
377
V8_INLINE static internal::Address* GetRoot (v8::Isolate* isolate, int index) {
331
378
internal::Address addr = reinterpret_cast <internal::Address>(isolate) +
332
379
kIsolateRootsOffset +
@@ -356,8 +403,9 @@ class Internals {
356
403
internal::Address heap_object_ptr, int offset) {
357
404
#ifdef V8_COMPRESS_POINTERS
358
405
uint32_t value = ReadRawField<uint32_t >(heap_object_ptr, offset);
359
- internal::Address root = GetRootFromOnHeapAddress (heap_object_ptr);
360
- return root + static_cast <internal::Address>(static_cast <uintptr_t >(value));
406
+ internal::Address base =
407
+ GetPtrComprCageBaseFromOnHeapAddress (heap_object_ptr);
408
+ return base + static_cast <internal::Address>(static_cast <uintptr_t >(value));
361
409
#else
362
410
return ReadRawField<internal::Address>(heap_object_ptr, offset);
363
411
#endif
@@ -409,18 +457,19 @@ class Internals {
409
457
410
458
#ifdef V8_COMPRESS_POINTERS
411
459
// See v8:7703 or src/ptr-compr.* for details about pointer compression.
412
- static constexpr size_t kPtrComprHeapReservationSize = size_t {1 } << 32 ;
413
- static constexpr size_t kPtrComprIsolateRootAlignment = size_t {1 } << 32 ;
460
+ static constexpr size_t kPtrComprCageReservationSize = size_t {1 } << 32 ;
461
+ static constexpr size_t kPtrComprCageBaseAlignment = size_t {1 } << 32 ;
414
462
415
- V8_INLINE static internal::Address GetRootFromOnHeapAddress (
463
+ V8_INLINE static internal::Address GetPtrComprCageBaseFromOnHeapAddress (
416
464
internal::Address addr) {
417
- return addr & -static_cast <intptr_t >(kPtrComprIsolateRootAlignment );
465
+ return addr & -static_cast <intptr_t >(kPtrComprCageBaseAlignment );
418
466
}
419
467
420
468
V8_INLINE static internal::Address DecompressTaggedAnyField (
421
469
internal::Address heap_object_ptr, uint32_t value) {
422
- internal::Address root = GetRootFromOnHeapAddress (heap_object_ptr);
423
- return root + static_cast <internal::Address>(static_cast <uintptr_t >(value));
470
+ internal::Address base =
471
+ GetPtrComprCageBaseFromOnHeapAddress (heap_object_ptr);
472
+ return base + static_cast <internal::Address>(static_cast <uintptr_t >(value));
424
473
}
425
474
426
475
#endif // V8_COMPRESS_POINTERS
0 commit comments