diff options
author | Michaël Zasso <targos@protonmail.com> | 2022-04-12 11:10:15 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2022-04-12 22:08:39 +0200 |
commit | fd4f80ce54d7f7b7503e0999f6a9d293d493846d (patch) | |
tree | 00fba34b8aabeb481c7128fccee635719ee44a3b /deps/v8/src/objects/embedder-data-slot-inl.h | |
parent | 73d53fe9f56d7ce5de4b9c9ad5257dc601bbce14 (diff) | |
download | node-new-fd4f80ce54d7f7b7503e0999f6a9d293d493846d.tar.gz |
deps: update V8 to 10.1.124.6
PR-URL: https://github.com/nodejs/node/pull/42657
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Diffstat (limited to 'deps/v8/src/objects/embedder-data-slot-inl.h')
-rw-r--r-- | deps/v8/src/objects/embedder-data-slot-inl.h | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/deps/v8/src/objects/embedder-data-slot-inl.h b/deps/v8/src/objects/embedder-data-slot-inl.h index 983a0b0ad4..e4d63e5b32 100644 --- a/deps/v8/src/objects/embedder-data-slot-inl.h +++ b/deps/v8/src/objects/embedder-data-slot-inl.h @@ -5,13 +5,14 @@ #ifndef V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_ #define V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_ -#include "src/objects/embedder-data-slot.h" - #include "src/base/memory.h" +#include "src/common/globals.h" #include "src/heap/heap-write-barrier-inl.h" #include "src/objects/embedder-data-array.h" +#include "src/objects/embedder-data-slot.h" #include "src/objects/js-objects-inl.h" #include "src/objects/objects-inl.h" +#include "src/sandbox/external-pointer-inl.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" @@ -27,16 +28,17 @@ EmbedderDataSlot::EmbedderDataSlot(JSObject object, int embedder_field_index) : SlotBase(FIELD_ADDR( object, object.GetEmbedderFieldOffset(embedder_field_index))) {} -void EmbedderDataSlot::AllocateExternalPointerEntry(Isolate* isolate) { -#ifdef V8_HEAP_SANDBOX - // TODO(v8:10391, saelo): Use InitExternalPointerField() once - // ExternalPointer_t is 4-bytes. - uint32_t index = isolate->external_pointer_table().allocate(); - // Object slots don't support storing raw values, so we just "reinterpret - // cast" the index value to Object. - Object index_as_object(index); - ObjectSlot(address() + kRawPayloadOffset).Relaxed_Store(index_as_object); - ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(Smi::zero()); +EmbedderDataSlot::EmbedderDataSlot(const EmbedderDataSlotSnapshot& snapshot) + : SlotBase(reinterpret_cast<Address>(&snapshot)) {} + +void EmbedderDataSlot::Initialize(Object initial_value) { + // TODO(v8) initialize the slot with Smi::zero() instead. This'll also + // guarantee that we don't need a write barrier. + DCHECK(initial_value.IsSmi() || + ReadOnlyHeap::Contains(HeapObject::cast(initial_value))); + ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(initial_value); +#ifdef V8_COMPRESS_POINTERS + ObjectSlot(address() + kRawPayloadOffset).Relaxed_Store(Smi::zero()); #endif } @@ -74,8 +76,7 @@ void EmbedderDataSlot::store_tagged(JSObject object, int embedder_field_index, .Relaxed_Store(value); WRITE_BARRIER(object, slot_offset + kTaggedPayloadOffset, value); #ifdef V8_COMPRESS_POINTERS - // See gc_safe_store() for the reasons behind two stores and why the second is - // only done if !V8_HEAP_SANDBOX_BOOL + // See gc_safe_store() for the reasons behind two stores. ObjectSlot(FIELD_ADDR(object, slot_offset + kRawPayloadOffset)) .Relaxed_Store(Smi::zero()); #endif @@ -87,12 +88,14 @@ bool EmbedderDataSlot::ToAlignedPointer(Isolate* isolate, // are accessed this way only from the main thread via API during "mutator" // phase which is propely synched with GC (concurrent marker may still look // at the tagged part of the embedder slot but read-only access is ok). - Address raw_value; -#ifdef V8_HEAP_SANDBOX - uint32_t index = base::Memory<uint32_t>(address() + kRawPayloadOffset); - raw_value = isolate->external_pointer_table().get(index) & - ~kEmbedderDataSlotPayloadTag; +#ifdef V8_SANDBOXED_EXTERNAL_POINTERS + // The raw part must always contain a valid external pointer table index. + *out_pointer = reinterpret_cast<void*>( + ReadExternalPointerField(address() + kExternalPointerOffset, isolate, + kEmbedderDataSlotPayloadTag)); + return true; #else + Address raw_value; if (COMPRESS_POINTERS_BOOL) { // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size // fields (external pointers, doubles and BigInt data) are only kTaggedSize @@ -102,46 +105,25 @@ bool EmbedderDataSlot::ToAlignedPointer(Isolate* isolate, } else { raw_value = *location(); } -#endif *out_pointer = reinterpret_cast<void*>(raw_value); return HAS_SMI_TAG(raw_value); -} - -bool EmbedderDataSlot::ToAlignedPointerSafe(Isolate* isolate, - void** out_pointer) const { -#ifdef V8_HEAP_SANDBOX - uint32_t index = base::Memory<uint32_t>(address() + kRawPayloadOffset); - Address raw_value; - if (isolate->external_pointer_table().is_valid_index(index)) { - raw_value = isolate->external_pointer_table().get(index) & - ~kEmbedderDataSlotPayloadTag; - *out_pointer = reinterpret_cast<void*>(raw_value); - return true; - } - return false; -#else - return ToAlignedPointer(isolate, out_pointer); -#endif // V8_HEAP_SANDBOX +#endif // V8_SANDBOXED_EXTERNAL_POINTERS } bool EmbedderDataSlot::store_aligned_pointer(Isolate* isolate, void* ptr) { Address value = reinterpret_cast<Address>(ptr); if (!HAS_SMI_TAG(value)) return false; -#ifdef V8_HEAP_SANDBOX - if (V8_HEAP_SANDBOX_BOOL) { - AllocateExternalPointerEntry(isolate); - // Raw payload contains the table index. Object slots don't support loading - // of raw values, so we just "reinterpret cast" Object value to index. - Object index_as_object = - ObjectSlot(address() + kRawPayloadOffset).Relaxed_Load(); - uint32_t index = static_cast<uint32_t>(index_as_object.ptr()); - isolate->external_pointer_table().set(index, - value | kEmbedderDataSlotPayloadTag); - return true; - } -#endif +#ifdef V8_SANDBOXED_EXTERNAL_POINTERS + DCHECK_EQ(0, value & kExternalPointerTagMask); + // This also mark the entry as alive until the next GC. + InitExternalPointerField(address() + kExternalPointerOffset, isolate, value, + kEmbedderDataSlotPayloadTag); + ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(Smi::zero()); + return true; +#else gc_safe_store(isolate, value); return true; +#endif // V8_SANDBOXED_EXTERNAL_POINTERS } EmbedderDataSlot::RawData EmbedderDataSlot::load_raw( @@ -190,6 +172,36 @@ void EmbedderDataSlot::gc_safe_store(Isolate* isolate, Address value) { #endif } +// static +void EmbedderDataSlot::PopulateEmbedderDataSnapshot( + Map map, JSObject js_object, int entry_index, + EmbedderDataSlotSnapshot& snapshot) { +#ifdef V8_COMPRESS_POINTERS + STATIC_ASSERT(sizeof(EmbedderDataSlotSnapshot) == sizeof(AtomicTagged_t) * 2); +#else // !V8_COMPRESS_POINTERS + STATIC_ASSERT(sizeof(EmbedderDataSlotSnapshot) == sizeof(AtomicTagged_t)); +#endif // !V8_COMPRESS_POINTERS + STATIC_ASSERT(sizeof(EmbedderDataSlotSnapshot) == kEmbedderDataSlotSize); + + const Address field_base = + FIELD_ADDR(js_object, js_object.GetEmbedderFieldOffset(entry_index)); + +#if defined(V8_TARGET_BIG_ENDIAN) && defined(V8_COMPRESS_POINTERS) + const int index = 1; +#else + const int index = 0; +#endif + + reinterpret_cast<AtomicTagged_t*>(&snapshot)[index] = + AsAtomicTagged::Relaxed_Load( + reinterpret_cast<AtomicTagged_t*>(field_base + kTaggedPayloadOffset)); +#ifdef V8_COMPRESS_POINTERS + reinterpret_cast<AtomicTagged_t*>(&snapshot)[1 - index] = + AsAtomicTagged::Relaxed_Load( + reinterpret_cast<AtomicTagged_t*>(field_base + kRawPayloadOffset)); +#endif // V8_COMPRESS_POINTERS +} + } // namespace internal } // namespace v8 |