v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
embedder-data-array.cc
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
6
9
10namespace v8 {
11namespace internal {
12
13#ifdef V8_ENABLE_SANDBOX
14namespace {
15ExternalPointerHandle LoadExternalPointerHandle(const EmbedderDataSlot& slot) {
17 return ExternalPointerSlot(loc, kAnyExternalPointerTagRange)
18 .Relaxed_LoadHandle();
19}
20void StoreTaggedWithoutBarrier(const EmbedderDataSlot& slot,
21 Tagged<Object> value) {
23 ObjectSlot(loc).Relaxed_Store(value);
24}
25} // namespace
26#endif
27
28// static
30 Isolate* isolate, DirectHandle<EmbedderDataArray> array, int index) {
31 if (index < array->length()) return array;
32 DCHECK_LT(index, kMaxLength);
34 isolate->factory()->NewEmbedderDataArray(index + 1);
36 // Last new space allocation does not require any write barriers.
37#ifdef V8_ENABLE_SANDBOX
38 for (int i = 0; i < array->length(); i++) {
39 EmbedderDataSlot src(*array, i);
40 EmbedderDataSlot dest(*new_array, i);
41 ExternalPointerHandle src_handle = LoadExternalPointerHandle(src);
42 if (src_handle != kNullExternalPointerHandle) {
43 void* value;
44 CHECK(src.ToAlignedPointer(isolate, &value));
45 CHECK(dest.store_aligned_pointer(isolate, *new_array, value));
46 } else {
47 StoreTaggedWithoutBarrier(dest, src.load_tagged());
48 }
49 }
50#else
51 size_t size = array->length() * kEmbedderDataSlotSize;
52 MemCopy(reinterpret_cast<void*>(new_array->slots_start()),
53 reinterpret_cast<void*>(array->slots_start()), size);
54#endif // V8_ENABLE_SANDBOX
55 return new_array;
56}
57
58} // namespace internal
59} // namespace v8
static DirectHandle< EmbedderDataArray > EnsureCapacity(Isolate *isolate, DirectHandle< EmbedderDataArray > array, int index)
V8_INLINE Tagged< Object > load_tagged() const
V8_INLINE V8_WARN_UNUSED_RESULT bool store_aligned_pointer(IsolateForSandbox isolate, Tagged< HeapObject > host, void *ptr)
static constexpr int kTaggedPayloadOffset
static constexpr int kExternalPointerOffset
void Relaxed_Store(Tagged< Object > value) const
Definition slots-inl.h:100
SlotTraits::TObjectSlot ObjectSlot
Definition globals.h:1243
constexpr int kEmbedderDataSlotSize
Definition globals.h:664
constexpr ExternalPointerTagRange kAnyExternalPointerTagRange(kFirstExternalPointerTag, kLastExternalPointerTag)
constexpr ExternalPointerHandle kNullExternalPointerHandle
uint32_t ExternalPointerHandle
return value
Definition map-inl.h:893
void MemCopy(void *dest, const void *src, size_t size)
Definition memcopy.h:124
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_LT(v1, v2)
Definition logging.h:489