v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
slots-inl.h
Go to the documentation of this file.
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 V8_OBJECTS_SLOTS_INL_H_
6#define V8_OBJECTS_SLOTS_INL_H_
7
8#include "src/objects/slots.h"
9// Include the non-inl header before the rest of the headers.
10
11#include "include/v8-internal.h"
13#include "src/common/globals.h"
17#include "src/objects/map.h"
19#include "src/objects/objects.h"
20#include "src/objects/tagged.h"
24#include "src/utils/memcopy.h"
25
26namespace v8 {
27namespace internal {
28
29//
30// FullObjectSlot implementation.
31//
32
34 : SlotBase(reinterpret_cast<Address>(&object->ptr_)) {}
35
37 return load_map().ptr() == raw_value;
38}
39
43
47
48Tagged<Object> FullObjectSlot::load() const { return **this; }
49
51 return load();
52}
53
55 *location() = value.ptr();
56}
57
59#ifdef V8_MAP_PACKING
60 *location() = MapWord::Pack(map.ptr());
61#else
62 store(map);
63#endif
64}
65
67#ifdef V8_MAP_PACKING
68 return UncheckedCast<Map>(Tagged<Object>(MapWord::Unpack(*location())));
69#else
71#endif
72}
73
77
81
85
89
93
94// static
99
103
107
114
121
122//
123// FullMaybeObjectSlot implementation.
124//
125
129
131
133 PtrComprCageBase cage_base) const {
134 return **this;
138 *location() = value.ptr();
139}
140
144
149
153
154// static
159
163
169
170//
171// FullHeapObjectSlot implementation.
172//
173
177
179 PtrComprCageBase cage_base) const {
180 return **this;
181}
182
184 *location() = value.ptr();
185}
186
192
194 *location() = value.ptr();
195}
196
198#ifdef V8_ENABLE_SANDBOX
199 Relaxed_StoreHandle(kNullExternalPointerHandle);
200#else
202#endif // V8_ENABLE_SANDBOX
203}
204
206 Tagged<HeapObject> host, Address value,
207 ExternalPointerTag tag) {
208#ifdef V8_ENABLE_SANDBOX
209 ExternalPointerTable& table = isolate.GetExternalPointerTableFor(tag);
210 ExternalPointerHandle handle = table.AllocateAndInitializeEntry(
211 isolate.GetExternalPointerTableSpaceFor(tag, host.address()), value, tag);
212 // Use a Release_Store to ensure that the store of the pointer into the
213 // table is not reordered after the store of the handle. Otherwise, other
214 // threads may access an uninitialized table entry and crash.
215 Release_StoreHandle(handle);
216#else
217 store(isolate, value, tag);
218#endif // V8_ENABLE_SANDBOX
219}
220
221#ifdef V8_COMPRESS_POINTERS
222ExternalPointerHandle ExternalPointerSlot::Relaxed_LoadHandle() const {
223 return base::AsAtomic32::Relaxed_Load(handle_location());
224}
225
226void ExternalPointerSlot::Relaxed_StoreHandle(
228 return base::AsAtomic32::Relaxed_Store(handle_location(), handle);
229}
230
231void ExternalPointerSlot::Release_StoreHandle(
233 return base::AsAtomic32::Release_Store(handle_location(), handle);
234}
235#endif // V8_COMPRESS_POINTERS
236
238#ifdef V8_ENABLE_SANDBOX
239 const ExternalPointerTable& table =
240 isolate.GetExternalPointerTableFor(tag_range_);
241 ExternalPointerHandle handle = Relaxed_LoadHandle();
242 return table.Get(handle, tag_range_);
243#else
245#endif // V8_ENABLE_SANDBOX
246}
247
249 ExternalPointerTag tag) {
250#ifdef V8_ENABLE_SANDBOX
251 DCHECK(tag_range_.Contains(tag));
252 ExternalPointerTable& table = isolate.GetExternalPointerTableFor(tag);
253 ExternalPointerHandle handle = Relaxed_LoadHandle();
254 table.Set(handle, value, tag);
255#else
257#endif // V8_ENABLE_SANDBOX
258}
259
262 const DisallowGarbageCollection& no_gc) {
263#ifdef V8_ENABLE_SANDBOX
264 ExternalPointerHandle content = Relaxed_LoadHandle();
265 Relaxed_StoreHandle(kNullExternalPointerHandle);
266#else
269#endif
270 return content;
271}
272
275 const DisallowGarbageCollection& no_gc) {
276#ifdef V8_ENABLE_SANDBOX
277 return Relaxed_StoreHandle(content);
278#else
280#endif
281}
282
284 const DisallowGarbageCollection& no_gc, uint32_t index) {
285#ifdef V8_ENABLE_SANDBOX
286 static_assert(sizeof(ExternalPointerHandle) == sizeof(uint32_t));
287 Relaxed_StoreHandle(index);
288#else
289 WriteMaybeUnalignedValue<Address>(address(), static_cast<Address>(index));
290#endif
291}
292
294 const DisallowGarbageCollection& no_gc) {
295#ifdef V8_ENABLE_SANDBOX
296 static_assert(sizeof(ExternalPointerHandle) == sizeof(uint32_t));
297 return Relaxed_LoadHandle();
298#else
299 return static_cast<uint32_t>(ReadMaybeUnalignedValue<Address>(address()));
300#endif
301}
302
303#ifdef V8_COMPRESS_POINTERS
304CppHeapPointerHandle CppHeapPointerSlot::Relaxed_LoadHandle() const {
306}
307
308void CppHeapPointerSlot::Relaxed_StoreHandle(
311}
312
313void CppHeapPointerSlot::Release_StoreHandle(
316}
317#endif // V8_COMPRESS_POINTERS
318
320 CppHeapPointerTagRange tag_range) const {
321#ifdef V8_COMPRESS_POINTERS
322 const CppHeapPointerTable& table = isolate.GetCppHeapPointerTable();
323 CppHeapPointerHandle handle = Relaxed_LoadHandle();
324 return table.Get(handle, tag_range);
325#else // !V8_COMPRESS_POINTERS
327#endif // !V8_COMPRESS_POINTERS
328}
329
331 Address value, CppHeapPointerTag tag) const {
332#ifdef V8_COMPRESS_POINTERS
333 CppHeapPointerTable& table = isolate.GetCppHeapPointerTable();
334 CppHeapPointerHandle handle = Relaxed_LoadHandle();
335 table.Set(handle, value, tag);
336#else // !V8_COMPRESS_POINTERS
338#endif // !V8_COMPRESS_POINTERS
339}
340
342#ifdef V8_COMPRESS_POINTERS
344#else // !V8_COMPRESS_POINTERS
346#endif // !V8_COMPRESS_POINTERS
347}
348
352
356
362
368
374
376 Tagged<ExposedTrustedObject> value) const {
377#ifdef V8_ENABLE_SANDBOX
379 ExposedTrustedObject::kSelfIndirectPointerOffset);
382#else
383 UNREACHABLE();
384#endif // V8_ENABLE_SANDBOX
385}
386
388 Tagged<ExposedTrustedObject> value) const {
389#ifdef V8_ENABLE_SANDBOX
391 ExposedTrustedObject::kSelfIndirectPointerOffset);
393#else
394 UNREACHABLE();
395#endif // V8_ENABLE_SANDBOX
396}
397
401
405
410
415
419
420template <IndirectPointerSlot::TagCheckStrictness allow_unpublished>
423#ifdef V8_ENABLE_SANDBOX
424 // TODO(saelo) Maybe come up with a different entry encoding scheme that
425 // returns Smi::zero for kNullCodePointerHandle?
426 if (!handle) return Smi::zero();
427
428 // Resolve the handle. The tag implies the pointer table to use.
429 if (tag_ == kUnknownIndirectPointerTag) {
430 // In this case we have to rely on the handle marking to determine which
431 // pointer table to use.
433 return ResolveCodePointerHandle(handle);
434 } else {
435 return ResolveTrustedPointerHandle<allow_unpublished>(handle, isolate);
436 }
437 } else if (tag_ == kCodeIndirectPointerTag) {
438 return ResolveCodePointerHandle(handle);
439 } else {
440 return ResolveTrustedPointerHandle<allow_unpublished>(handle, isolate);
441 }
442#else
443 UNREACHABLE();
444#endif // V8_ENABLE_SANDBOX
445}
446
447#ifdef V8_ENABLE_SANDBOX
448template <IndirectPointerSlot::TagCheckStrictness allow_unpublished>
449Tagged<Object> IndirectPointerSlot::ResolveTrustedPointerHandle(
452 const TrustedPointerTable& table = isolate.GetTrustedPointerTableFor(tag_);
453 if constexpr (allow_unpublished == kAllowUnpublishedEntries) {
454 return Tagged<Object>(table.GetMaybeUnpublished(handle, tag_));
455 }
456 return Tagged<Object>(table.Get(handle, tag_));
457}
458
459Tagged<Object> IndirectPointerSlot::ResolveCodePointerHandle(
462 Address addr =
463 IsolateGroup::current()->code_pointer_table()->GetCodeObject(handle);
464 return Tagged<Object>(addr);
465}
466#endif // V8_ENABLE_SANDBOX
467
468template <typename SlotT>
470 jit_allocation_.WriteHeaderSlot(this->address(), value, kRelaxedStore);
471}
472
473//
474// Utils.
475//
476
477// Copies tagged words from |src| to |dst|. The data spans must not overlap.
478// |src| and |dst| must be kTaggedSize-aligned.
479inline void CopyTagged(Address dst, const Address src, size_t num_tagged) {
480 static const size_t kBlockCopyLimit = 16;
481 CopyImpl<kBlockCopyLimit>(reinterpret_cast<Tagged_t*>(dst),
482 reinterpret_cast<const Tagged_t*>(src), num_tagged);
483}
484
485// Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
487 size_t counter) {
488#ifdef V8_COMPRESS_POINTERS
489 // CompressAny since many callers pass values which are not valid objects.
490 Tagged_t raw_value = V8HeapCompressionScheme::CompressAny(value.ptr());
491 MemsetUint32(start, raw_value, counter);
492#else
493 Address raw_value = value.ptr();
494 MemsetPointer(start, raw_value, counter);
495#endif
496}
497
498// Sets |counter| number of kTaggedSize-sized values starting at |start| slot.
499template <typename T>
501 size_t counter) {
502 MemsetTagged(start.location(), value, counter);
503}
504
505// Sets |counter| number of kSystemPointerSize-sized values starting at |start|
506// slot.
508 size_t counter) {
509 MemsetPointer(start.location(), value.ptr(), counter);
510}
511
512} // namespace internal
513} // namespace v8
514
515#endif // V8_OBJECTS_SLOTS_INL_H_
static T Relaxed_CompareAndSwap(T *addr, typename std::remove_reference< T >::type old_value, typename std::remove_reference< T >::type new_value)
static void Release_Store(T *addr, typename std::remove_reference< T >::type new_value)
static T Acquire_Load(T *addr)
static void Relaxed_Store(T *addr, typename std::remove_reference< T >::type new_value)
static T Release_CompareAndSwap(T *addr, typename std::remove_reference< T >::type old_value, typename std::remove_reference< T >::type new_value)
static T Relaxed_Load(T *addr)
Address try_load(IsolateForPointerCompression isolate, CppHeapPointerTagRange tag_range) const
Definition slots-inl.h:319
void store(IsolateForPointerCompression isolate, Address value, CppHeapPointerTag tag) const
Definition slots-inl.h:330
void init(IsolateForSandbox isolate, Tagged< HeapObject > host, Address value, ExternalPointerTag tag)
Definition slots-inl.h:205
uint32_t GetContentAsIndexAfterDeserialization(const DisallowGarbageCollection &no_gc)
Definition slots-inl.h:293
ExternalPointer_t RawContent
Definition slots.h:396
RawContent GetAndClearContentForSerialization(const DisallowGarbageCollection &no_gc)
Definition slots-inl.h:261
void ReplaceContentWithIndexForSerialization(const DisallowGarbageCollection &no_gc, uint32_t index)
Definition slots-inl.h:283
Address load(IsolateForSandbox isolate)
Definition slots-inl.h:237
void RestoreContentAfterSerialization(RawContent content, const DisallowGarbageCollection &no_gc)
Definition slots-inl.h:273
void store(IsolateForSandbox isolate, Address value, ExternalPointerTag tag)
Definition slots-inl.h:248
void store(Tagged< HeapObjectReference > value) const
Definition slots-inl.h:183
Tagged< HeapObjectReference > operator*() const
Definition slots-inl.h:174
Tagged< HeapObject > ToHeapObject() const
Definition slots-inl.h:187
void StoreHeapObject(Tagged< HeapObject > value) const
Definition slots-inl.h:193
Tagged< HeapObjectReference > load(PtrComprCageBase cage_base) const
Definition slots-inl.h:178
static Tagged< Object > RawToTagged(PtrComprCageBase cage_base, Address raw)
Definition slots-inl.h:155
Tagged< MaybeObject > Relaxed_Load() const
Definition slots-inl.h:141
void Relaxed_Store(Tagged< MaybeObject > value) const
Definition slots-inl.h:160
Tagged< MaybeObject > load() const
Definition slots-inl.h:130
Tagged< MaybeObject > operator*() const
Definition slots-inl.h:126
void store(Tagged< MaybeObject > value) const
Definition slots-inl.h:137
void Release_CompareAndSwap(Tagged< MaybeObject > old, Tagged< MaybeObject > target) const
Definition slots-inl.h:164
static Tagged< Object > RawToTagged(PtrComprCageBase cage_base, Address raw)
Definition slots-inl.h:95
void Relaxed_Store(Tagged< Object > value) const
Definition slots-inl.h:100
Tagged< Object > load() const
Definition slots-inl.h:48
Tagged< Object > Relaxed_Load() const
Definition slots-inl.h:82
Tagged< Object > operator*() const
Definition slots-inl.h:44
bool contains_map_value(Address raw_value) const
Definition slots-inl.h:36
Tagged< Map > load_map() const
Definition slots-inl.h:66
void store(Tagged< Object > value) const
Definition slots-inl.h:54
void store_map(Tagged< Map > map) const
Definition slots-inl.h:58
Tagged< Object > Acquire_Load() const
Definition slots-inl.h:74
Tagged< Object > Relaxed_CompareAndSwap(Tagged< Object > old, Tagged< Object > target) const
Definition slots-inl.h:108
bool Relaxed_ContainsMapValue(Address raw_value) const
Definition slots-inl.h:40
Tagged< Object > Release_CompareAndSwap(Tagged< Object > old, Tagged< Object > target) const
Definition slots-inl.h:115
Address Relaxed_Load_Raw() const
Definition slots-inl.h:90
void Release_Store(Tagged< Object > value) const
Definition slots-inl.h:104
Tagged< Object > Relaxed_Load_AllowUnpublished(IsolateForSandbox isolate) const
Definition slots-inl.h:363
IndirectPointerHandle Acquire_LoadHandle() const
Definition slots-inl.h:402
void Release_StoreHandle(IndirectPointerHandle handle) const
Definition slots-inl.h:411
Tagged< Object > load(IsolateForSandbox isolate) const
Definition slots-inl.h:349
IndirectPointerHandle Relaxed_LoadHandle() const
Definition slots-inl.h:398
Tagged< Object > Relaxed_Load(IsolateForSandbox isolate) const
Definition slots-inl.h:357
void Relaxed_StoreHandle(IndirectPointerHandle handle) const
Definition slots-inl.h:406
void Relaxed_Store(Tagged< ExposedTrustedObject > value) const
Definition slots-inl.h:375
Tagged< Object > Acquire_Load(IsolateForSandbox isolate) const
Definition slots-inl.h:369
void Release_Store(Tagged< ExposedTrustedObject > value) const
Definition slots-inl.h:387
Tagged< Object > ResolveHandle(IndirectPointerHandle handle, IsolateForSandbox isolate) const
Definition slots-inl.h:421
void store(Tagged< ExposedTrustedObject > value) const
Definition slots-inl.h:353
static IsolateGroup * current()
static constexpr Tagged< Smi > zero()
Definition smi.h:99
V8_INLINE constexpr StorageType ptr() const
static V8_INLINE constexpr Tagged_t CompressAny(Address tagged)
typename SlotT::TObject TObject
Definition slots.h:563
void Relaxed_Store(TObject value) const
Definition slots-inl.h:469
Node ** ptr_
#define HAS_STRONG_HEAP_OBJECT_TAG(value)
Definition globals.h:1774
int start
ZoneVector< RpoNumber > & result
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
void CopyTagged(Address dst, const Address src, size_t num_tagged)
Definition slots-inl.h:479
Tagged(T object) -> Tagged< T >
static void WriteMaybeUnalignedValue(Address p, V value)
Definition ptr-compr.h:225
void CopyImpl(T *dst_ptr, const T *src_ptr, size_t count)
Definition memcopy.h:227
void MemsetTagged(Tagged_t *start, Tagged< MaybeObject > value, size_t counter)
Definition slots-inl.h:486
Address Tagged_t
Definition globals.h:547
Handle< To > UncheckedCast(Handle< From > value)
Definition handles-inl.h:55
uint32_t IndirectPointerHandle
constexpr ExternalPointerHandle kNullExternalPointerHandle
constexpr IndirectPointerHandle kNullIndirectPointerHandle
uint32_t ExternalPointerHandle
uint32_t CppHeapPointerHandle
static V ReadMaybeUnalignedValue(Address p)
Definition ptr-compr.h:207
static constexpr Address kNullAddress
Definition v8-internal.h:53
constexpr CppHeapPointerHandle kNullCppHeapPointerHandle
void MemsetPointer(FullObjectSlot start, Tagged< Object > value, size_t counter)
Definition slots-inl.h:507
constexpr uint32_t kCodePointerHandleMarker
void MemsetUint32(uint32_t *dest, uint32_t value, size_t counter)
Definition memcopy.h:267
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
static constexpr RelaxedStoreTag kRelaxedStore
Definition globals.h:2911
CppHeapPointerTag
Definition v8-sandbox.h:28
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482