v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
compressed-slots.h
Go to the documentation of this file.
1// Copyright 2019 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_COMPRESSED_SLOTS_H_
6#define V8_OBJECTS_COMPRESSED_SLOTS_H_
7
8#include "include/v8config.h"
11#include "src/objects/slots.h"
13
14namespace v8::internal {
15
16#ifdef V8_COMPRESS_POINTERS
17
18// A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
19// holding a compressed tagged pointer (smi or heap object).
20// Its address() is the address of the slot.
21// The slot's contents can be read and written using operator* and store().
22class CompressedObjectSlot : public SlotBase<CompressedObjectSlot, Tagged_t> {
23 public:
24 using TCompressionScheme = V8HeapCompressionScheme;
25 using TObject = Tagged<Object>;
26 using THeapObjectSlot = CompressedHeapObjectSlot;
27
28 static constexpr bool kCanBeWeak = false;
29
30 CompressedObjectSlot() : SlotBase(kNullAddress) {}
31 explicit CompressedObjectSlot(Address ptr) : SlotBase(ptr) {}
32 explicit CompressedObjectSlot(Address* ptr)
33 : SlotBase(reinterpret_cast<Address>(ptr)) {}
34 inline explicit CompressedObjectSlot(Tagged<Object>* object);
35 explicit CompressedObjectSlot(Tagged<Object> const* const* ptr)
36 : SlotBase(reinterpret_cast<Address>(ptr)) {}
37 explicit CompressedObjectSlot(const TaggedMemberBase* member)
38 : SlotBase(reinterpret_cast<Address>(member->ptr_location())) {}
39 template <typename T>
40 explicit CompressedObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
41 : SlotBase(slot.address()) {}
42
43 // Compares memory representation of a value stored in the slot with given
44 // raw value without decompression.
45 inline bool contains_map_value(Address raw_value) const;
46 inline bool Relaxed_ContainsMapValue(Address raw_value) const;
47
48 // TODO(leszeks): Consider deprecating the operator* load, and always pass the
49 // Isolate.
50 inline Tagged<Object> operator*() const;
51 // TODO(saelo): it would be nice if we could have two load variants: one that
52 // takes no arguments (which should normally be used), and one that takes an
53 // Isolate* or an IsolateForSandbox to be compatible with the
54 // IndirectPointerSlot. Then, all slots that contain HeapObject references
55 // would have at least a `load(isolate)` variant, and so could that could be
56 // used in cases where only the slots content matters.
57 inline Tagged<Object> load() const;
58 inline Tagged<Object> load(PtrComprCageBase cage_base) const;
59 inline void store(Tagged<Object> value) const;
60 inline void store_map(Tagged<Map> map) const;
61
62 inline Tagged<Map> load_map() const;
63
64 inline Tagged<Object> Acquire_Load() const;
65 inline Tagged<Object> Relaxed_Load() const;
66 inline Tagged<Object> Relaxed_Load(PtrComprCageBase cage_base) const;
67 inline Tagged_t Relaxed_Load_Raw() const;
68 static inline Tagged<Object> RawToTagged(PtrComprCageBase cage_base,
69 Tagged_t raw);
70 inline void Relaxed_Store(Tagged<Object> value) const;
71 inline void Release_Store(Tagged<Object> value) const;
72 inline Tagged<Object> Release_CompareAndSwap(Tagged<Object> old,
73 Tagged<Object> target) const;
74};
75
76// A CompressedMaybeObjectSlot instance describes a kTaggedSize-sized field
77// ("slot") holding a possibly-weak compressed tagged pointer
78// (think: Tagged<MaybeObject>).
79// Its address() is the address of the slot.
80// The slot's contents can be read and written using operator* and store().
81class CompressedMaybeObjectSlot
82 : public SlotBase<CompressedMaybeObjectSlot, Tagged_t> {
83 public:
84 using TCompressionScheme = V8HeapCompressionScheme;
85 using TObject = Tagged<MaybeObject>;
86 using THeapObjectSlot = CompressedHeapObjectSlot;
87
88 static constexpr bool kCanBeWeak = true;
89
90 CompressedMaybeObjectSlot() : SlotBase(kNullAddress) {}
91 explicit CompressedMaybeObjectSlot(Address ptr) : SlotBase(ptr) {}
92 explicit CompressedMaybeObjectSlot(Tagged<Object>* ptr)
93 : SlotBase(reinterpret_cast<Address>(ptr)) {}
94 explicit CompressedMaybeObjectSlot(Tagged<MaybeObject>* ptr)
95 : SlotBase(reinterpret_cast<Address>(ptr)) {}
96 explicit CompressedMaybeObjectSlot(const TaggedMemberBase* member)
97 : SlotBase(reinterpret_cast<Address>(member->ptr_location())) {}
98 template <typename T>
99 explicit CompressedMaybeObjectSlot(
100 SlotBase<T, TData, kSlotDataAlignment> slot)
101 : SlotBase(slot.address()) {}
102
103 inline Tagged<MaybeObject> operator*() const;
104 inline Tagged<MaybeObject> load() const;
105 inline Tagged<MaybeObject> load(PtrComprCageBase cage_base) const;
106 inline void store(Tagged<MaybeObject> value) const;
107
108 inline Tagged<MaybeObject> Relaxed_Load() const;
109 inline Tagged<MaybeObject> Relaxed_Load(PtrComprCageBase cage_base) const;
110 inline Tagged_t Relaxed_Load_Raw() const;
111 static inline Tagged<Object> RawToTagged(PtrComprCageBase cage_base,
112 Tagged_t raw);
113 inline void Relaxed_Store(Tagged<MaybeObject> value) const;
114 inline void Release_CompareAndSwap(Tagged<MaybeObject> old,
115 Tagged<MaybeObject> target) const;
116};
117
118// A CompressedHeapObjectSlot instance describes a kTaggedSize-sized field
119// ("slot") holding a weak or strong compressed pointer to a heap object (think:
120// Tagged<HeapObjectReference>).
121// Its address() is the address of the slot.
122// The slot's contents can be read and written using operator* and store().
123// In case it is known that that slot contains a strong heap object pointer,
124// ToHeapObject() can be used to retrieve that heap object.
125class CompressedHeapObjectSlot
126 : public SlotBase<CompressedHeapObjectSlot, Tagged_t> {
127 public:
128 using TCompressionScheme = V8HeapCompressionScheme;
129
130 CompressedHeapObjectSlot() : SlotBase(kNullAddress) {}
131 explicit CompressedHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
132 explicit CompressedHeapObjectSlot(TaggedBase* ptr)
133 : SlotBase(reinterpret_cast<Address>(ptr)) {}
134 template <typename T>
135 explicit CompressedHeapObjectSlot(SlotBase<T, TData, kSlotDataAlignment> slot)
136 : SlotBase(slot.address()) {}
137
138 inline Tagged<HeapObjectReference> operator*() const;
139 inline Tagged<HeapObjectReference> load(PtrComprCageBase cage_base) const;
140 inline void store(Tagged<HeapObjectReference> value) const;
141
142 inline Tagged<HeapObject> ToHeapObject() const;
143
144 inline void StoreHeapObject(Tagged<HeapObject> value) const;
145};
146
147// An OffHeapCompressedObjectSlot instance describes a kTaggedSize-sized field
148// ("slot") holding a compressed tagged pointer (smi or heap object).
149// Unlike CompressedObjectSlot, it does not assume that the slot is on the heap,
150// and so does not provide an operator* with implicit Isolate* calculation.
151// Its address() is the address of the slot.
152// The slot's contents can be read and written using load() and store().
153template <typename CompressionScheme, typename TObject, typename Subclass>
154class OffHeapCompressedObjectSlotBase : public SlotBase<Subclass, Tagged_t> {
155 public:
156 using TSlotBase = SlotBase<Subclass, Tagged_t>;
157 using TCompressionScheme = CompressionScheme;
158
159 OffHeapCompressedObjectSlotBase() : TSlotBase(kNullAddress) {}
160 explicit OffHeapCompressedObjectSlotBase(Address ptr) : TSlotBase(ptr) {}
161 explicit OffHeapCompressedObjectSlotBase(const uint32_t* ptr)
162 : TSlotBase(reinterpret_cast<Address>(ptr)) {}
163
164 inline TObject load() const;
165 inline TObject load(PtrComprCageBase cage_base) const;
166 inline void store(TObject value) const;
167
168 inline TObject Relaxed_Load() const;
169 // TODO(saelo): same as in CompressedObjectSlot, consider removing the load
170 // variant with a PtrComprCageBase but instead adding one with an isolate
171 // parameter that simply forwards the the parameterless variant.
172 inline TObject Relaxed_Load(PtrComprCageBase cage_base) const;
173 inline Tagged_t Relaxed_Load_Raw() const;
174 static inline Tagged<Object> RawToTagged(PtrComprCageBase cage_base,
175 Tagged_t raw);
176 inline TObject Acquire_Load() const;
177 inline TObject Acquire_Load(PtrComprCageBase cage_base) const;
178 inline void Relaxed_Store(TObject value) const;
179 inline void Release_Store(TObject value) const;
180 inline void Release_CompareAndSwap(TObject old, TObject target) const;
181};
182
183template <typename CompressionScheme>
184class OffHeapCompressedObjectSlot
185 : public OffHeapCompressedObjectSlotBase<
186 CompressionScheme, Tagged<Object>,
187 OffHeapCompressedObjectSlot<CompressionScheme>> {
188 public:
189 using TSlotBase = OffHeapCompressedObjectSlotBase<
190 CompressionScheme, Tagged<Object>,
191 OffHeapCompressedObjectSlot<CompressionScheme>>;
192 using TObject = Tagged<Object>;
193 using THeapObjectSlot = OffHeapCompressedObjectSlot<CompressionScheme>;
194
195 static constexpr bool kCanBeWeak = false;
196
197 OffHeapCompressedObjectSlot() : TSlotBase(kNullAddress) {}
198 explicit OffHeapCompressedObjectSlot(Address ptr) : TSlotBase(ptr) {}
199 explicit OffHeapCompressedObjectSlot(const uint32_t* ptr)
200 : TSlotBase(reinterpret_cast<Address>(ptr)) {}
201 // TODO(jkummerow): Not sure this is useful?
202 template <typename T>
203 explicit OffHeapCompressedObjectSlot(SlotBase<T, Tagged_t> slot)
204 : TSlotBase(slot.address()) {}
205};
206
207template <typename CompressionScheme>
208class OffHeapCompressedMaybeObjectSlot
209 : public OffHeapCompressedObjectSlotBase<
210 CompressionScheme, Tagged<MaybeObject>,
211 OffHeapCompressedMaybeObjectSlot<CompressionScheme>> {
212 public:
213 using TSlotBase = OffHeapCompressedObjectSlotBase<
214 CompressionScheme, Tagged<MaybeObject>,
215 OffHeapCompressedMaybeObjectSlot<CompressionScheme>>;
216 using TObject = Tagged<MaybeObject>;
217 using THeapObjectSlot = OffHeapCompressedMaybeObjectSlot<CompressionScheme>;
218
219 static constexpr bool kCanBeWeak = true;
220
221 OffHeapCompressedMaybeObjectSlot() : TSlotBase(kNullAddress) {}
222 explicit OffHeapCompressedMaybeObjectSlot(Address ptr) : TSlotBase(ptr) {}
223 explicit OffHeapCompressedMaybeObjectSlot(const uint32_t* ptr)
224 : TSlotBase(reinterpret_cast<Address>(ptr)) {}
225};
226
227#endif // V8_COMPRESS_POINTERS
228
229} // namespace v8::internal
230
231#endif // V8_OBJECTS_COMPRESSED_SLOTS_H_
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats store(v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) DEFINE_GENERIC_IMPLICATION(trace_gc_object_stats
void Relaxed_Store(volatile Atomic8 *ptr, Atomic8 value)
Definition atomicops.h:189
Atomic8 Release_CompareAndSwap(volatile Atomic8 *ptr, Atomic8 old_value, Atomic8 new_value)
Definition atomicops.h:155
Atomic8 Relaxed_Load(volatile const Atomic8 *ptr)
Definition atomicops.h:234
Atomic8 Acquire_Load(volatile const Atomic8 *ptr)
Definition atomicops.h:249
uintptr_t Address
Definition memory.h:13
void Release_Store(volatile Atomic8 *ptr, Atomic8 value)
Definition atomicops.h:204
constexpr Address kNullAddress
Tagged(T object) -> Tagged< T >
Address Tagged_t
Definition globals.h:547
static constexpr Address kNullAddress
Definition v8-internal.h:53
V8HeapCompressionSchemeImpl< MainCage > V8HeapCompressionScheme
Definition globals.h:1137