v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
cppheap-pointer-inl.h
Go to the documentation of this file.
1// Copyright 2024 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_SANDBOX_CPPHEAP_POINTER_INL_H_
6#define V8_SANDBOX_CPPHEAP_POINTER_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "include/v8-internal.h"
15#include "src/sandbox/isolate.h"
16
17namespace v8::internal {
18
19// TODO(saelo): consider passing a CppHeapPointerTagRange as template parameter
20// once C++20 is supported everywhere.
21template <CppHeapPointerTag lower_bound, CppHeapPointerTag upper_bound>
23 Address field_address, IsolateForPointerCompression isolate) {
24 CppHeapPointerSlot slot(field_address);
25 CppHeapPointerTagRange tag_range(lower_bound, upper_bound);
26#ifdef V8_COMPRESS_POINTERS
27 // Handles may be written to objects from other threads so the handle needs
28 // to be loaded atomically. We assume that the load from the table cannot
29 // be reordered before the load of the handle due to the data dependency
30 // between the two loads and therefore use relaxed memory ordering, but
31 // technically we should use memory_order_consume here.
32 CppHeapPointerHandle handle = slot.Relaxed_LoadHandle();
33 return isolate.GetCppHeapPointerTable().Get(handle, tag_range);
34#else // !V8_COMPRESS_POINTERS
35 return slot.try_load(isolate, tag_range);
36#endif // !V8_COMPRESS_POINTERS
37}
38
41 CppHeapPointerTagRange tag_range) {
42 CppHeapPointerSlot slot(field_address);
43#ifdef V8_COMPRESS_POINTERS
44 // Handles may be written to objects from other threads so the handle needs
45 // to be loaded atomically. We assume that the load from the table cannot
46 // be reordered before the load of the handle due to the data dependency
47 // between the two loads and therefore use relaxed memory ordering, but
48 // technically we should use memory_order_consume here.
49 CppHeapPointerHandle handle = slot.Relaxed_LoadHandle();
50 return isolate.GetCppHeapPointerTable().Get(handle, tag_range);
51#else // !V8_COMPRESS_POINTERS
52 return slot.try_load(isolate, tag_range);
53#endif // !V8_COMPRESS_POINTERS
54}
55
56template <CppHeapPointerTag tag>
58 Address field_address, IsolateForPointerCompression isolate,
59 Address value) {
60 CppHeapPointerSlot slot(field_address);
61#ifdef V8_COMPRESS_POINTERS
62 static_assert(tag != CppHeapPointerTag::kNullTag);
63 // See comment above for why this uses a Relaxed_Load and Release_Store.
64 CppHeapPointerTable& table = isolate.GetCppHeapPointerTable();
65 const CppHeapPointerHandle handle = slot.Relaxed_LoadHandle();
67 // Field has not been initialized yet.
68 const CppHeapPointerHandle new_handle = table.AllocateAndInitializeEntry(
69 isolate.GetCppHeapPointerTableSpace(), value, tag);
70 slot.Release_StoreHandle(new_handle);
71 } else {
72 table.Set(handle, value, tag);
73 }
74#else // !V8_COMPRESS_POINTERS
75 slot.store(isolate, value, tag);
76#endif // !V8_COMPRESS_POINTERS
77}
78
80 Address field_address, IsolateForPointerCompression isolate, Address value,
82 CppHeapPointerSlot slot(field_address);
83#ifdef V8_COMPRESS_POINTERS
85 // See comment above for why this uses a Relaxed_Load and Release_Store.
86 CppHeapPointerTable& table = isolate.GetCppHeapPointerTable();
87 const CppHeapPointerHandle handle = slot.Relaxed_LoadHandle();
89 // Field has not been initialized yet.
90 const CppHeapPointerHandle new_handle = table.AllocateAndInitializeEntry(
91 isolate.GetCppHeapPointerTableSpace(), value, tag);
92 slot.Release_StoreHandle(new_handle);
93 } else {
94 table.Set(handle, value, tag);
95 }
96#else // !V8_COMPRESS_POINTERS
97 slot.store(isolate, value, tag);
98#endif // !V8_COMPRESS_POINTERS
99}
100
101} // namespace v8::internal
102
103#endif // V8_SANDBOX_CPPHEAP_POINTER_INL_H_
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
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
V8_INLINE Address ReadCppHeapPointerField(Address field_address, IsolateForPointerCompression isolate)
V8_INLINE void WriteLazilyInitializedCppHeapPointerField(Address field_address, IsolateForPointerCompression isolate, Address value)
uint32_t CppHeapPointerHandle
constexpr CppHeapPointerHandle kNullCppHeapPointerHandle
CppHeapPointerTag
Definition v8-sandbox.h:28
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define V8_INLINE
Definition v8config.h:500