v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-traced-handle.h
Go to the documentation of this file.
1// Copyright 2021 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 INCLUDE_V8_TRACED_HANDLE_H_
6#define INCLUDE_V8_TRACED_HANDLE_H_
7
8#include <stddef.h>
9#include <stdint.h>
10#include <stdio.h>
11
12#include <atomic>
13#include <memory>
14#include <type_traits>
15#include <utility>
16
17#include "v8-internal.h" // NOLINT(build/include_directory)
18#include "v8-local-handle.h" // NOLINT(build/include_directory)
19#include "v8-weak-callback-info.h" // NOLINT(build/include_directory)
20#include "v8config.h" // NOLINT(build/include_directory)
21
22namespace v8 {
23
24class Value;
25
26namespace internal {
27
28class BasicTracedReferenceExtractor;
29
34
36 kDefault, // See EmbedderRootsHandler::IsRoot().
38};
39
41 Isolate* isolate, Address value, Address* slot,
42 TracedReferenceStoreMode store_mode,
43 TracedReferenceHandling reference_handling);
45V8_EXPORT void CopyTracedReference(const Address* const* from, Address** to);
47
48} // namespace internal
49
55 public:
56 static_assert(sizeof(std::atomic<internal::Address*>) ==
57 sizeof(internal::Address*));
58
63 V8_INLINE void Reset();
64
68 V8_INLINE Local<Data> Get(Isolate* isolate) const {
69 if (IsEmpty()) return Local<Data>();
70 return Local<Data>::New(isolate, this->value<Data>());
71 }
72
77 bool IsEmptyThreadSafe() const { return GetSlotThreadSafe() == nullptr; }
78
79 protected:
81
86 reinterpret_cast<std::atomic<internal::Address*>*>(&slot())->store(
87 new_val, std::memory_order_relaxed);
88 }
89
94 return reinterpret_cast<const std::atomic<internal::Address*>*>(&slot())
95 ->load(std::memory_order_relaxed);
96 }
97
98 V8_EXPORT void CheckValue() const;
99
101 template <typename F>
102 friend class Local;
103 template <typename U>
104 friend bool operator==(const TracedReferenceBase&, const Local<U>&);
105 friend bool operator==(const TracedReferenceBase&,
106 const TracedReferenceBase&);
107};
108
123template <typename T>
125 public:
129 Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
130
131 template <class S>
133 return reinterpret_cast<BasicTracedReference<S>&>(
134 const_cast<BasicTracedReference<T>&>(*this));
135 }
136
137 private:
142
144 Isolate* isolate, T* that, internal::Address** slot,
146 internal::TracedReferenceHandling reference_handling);
147
148 template <typename F>
149 friend class Local;
150 friend class Object;
151 template <typename F>
152 friend class TracedReference;
153 template <typename F>
155 template <typename F>
156 friend class ReturnValue;
157};
158
164template <typename T>
166 public:
167 struct IsDroppable {};
168
170
175
182 template <class S>
184 static_assert(std::is_base_of<T, S>::value, "type check");
185 if (V8_UNLIKELY(that.IsEmpty())) {
186 return;
187 }
188 this->slot() = this->NewFromNonEmptyValue(
189 isolate, *that, &this->slot(),
192 }
193
202 template <class S>
204 : BasicTracedReference<T>() {
205 static_assert(std::is_base_of<T, S>::value, "type check");
206 if (V8_UNLIKELY(that.IsEmpty())) {
207 return;
208 }
209 this->slot() = this->NewFromNonEmptyValue(
210 isolate, *that, &this->slot(),
213 }
214
220 // Forward to operator=.
221 *this = std::move(other);
222 }
223
228 template <typename S>
230 // Forward to operator=.
231 *this = std::move(other);
232 }
233
239 // Forward to operator=;
240 *this = other;
241 }
242
247 template <typename S>
249 // Forward to operator=;
250 *this = other;
251 }
252
257
261 template <class S>
263
268
272 template <class S>
274
279 template <class S>
280 V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
281
286 template <class S>
287 V8_INLINE void Reset(Isolate* isolate, const Local<S>& other, IsDroppable);
288
289 template <class S>
291 return reinterpret_cast<TracedReference<S>&>(
292 const_cast<TracedReference<T>&>(*this));
293 }
294};
295
296// --- Implementation ---
297template <class T>
299 Isolate* isolate, T* that, internal::Address** slot,
301 internal::TracedReferenceHandling reference_handling) {
303 reinterpret_cast<internal::Isolate*>(isolate),
305 reinterpret_cast<internal::Address*>(slot), store_mode,
306 reference_handling);
307}
308
310 if (V8_UNLIKELY(IsEmpty())) {
311 return;
312 }
314 SetSlotThreadSafe(nullptr);
315}
316
318 const TracedReferenceBase& rhs) {
320}
321
322template <typename U>
324 const v8::Local<U>& rhs) {
326}
327
328template <typename U>
330 const TracedReferenceBase& rhs) {
331 return rhs == lhs;
332}
333
335 const TracedReferenceBase& rhs) {
336 return !(lhs == rhs);
337}
338
339template <typename U>
341 const v8::Local<U>& rhs) {
342 return !(lhs == rhs);
343}
344
345template <typename U>
347 const TracedReferenceBase& rhs) {
348 return !(rhs == lhs);
349}
350
351template <class T>
352template <class S>
353void TracedReference<T>::Reset(Isolate* isolate, const Local<S>& other) {
354 static_assert(std::is_base_of<T, S>::value, "type check");
355 this->Reset();
356 if (V8_UNLIKELY(other.IsEmpty())) {
357 return;
358 }
359 this->SetSlotThreadSafe(this->NewFromNonEmptyValue(
360 isolate, *other, &this->slot(),
363}
364
365template <class T>
366template <class S>
367void TracedReference<T>::Reset(Isolate* isolate, const Local<S>& other,
368 IsDroppable) {
369 static_assert(std::is_base_of<T, S>::value, "type check");
370 this->Reset();
371 if (V8_UNLIKELY(other.IsEmpty())) {
372 return;
373 }
374 this->SetSlotThreadSafe(this->NewFromNonEmptyValue(
375 isolate, *other, &this->slot(),
378}
379
380template <class T>
381template <class S>
383 TracedReference<S>&& rhs) noexcept {
384 static_assert(std::is_base_of<T, S>::value, "type check");
385 *this = std::move(rhs.template As<T>());
386 return *this;
387}
388
389template <class T>
390template <class S>
392 const TracedReference<S>& rhs) {
393 static_assert(std::is_base_of<T, S>::value, "type check");
394 *this = rhs.template As<T>();
395 return *this;
396}
397
398template <class T>
400 TracedReference&& rhs) noexcept {
401 if (this != &rhs) {
402 internal::MoveTracedReference(&rhs.slot(), &this->slot());
403 }
404 return *this;
405}
406
407template <class T>
409 if (this != &rhs) {
410 this->Reset();
411 if (!rhs.IsEmpty()) {
412 internal::CopyTracedReference(&rhs.slot(), &this->slot());
413 }
414 }
415 return *this;
416}
417
418} // namespace v8
419
420#endif // INCLUDE_V8_TRACED_HANDLE_H_
static V8_INLINE internal::Address * NewFromNonEmptyValue(Isolate *isolate, T *that, internal::Address **slot, internal::TracedReferenceStoreMode store_mode, internal::TracedReferenceHandling reference_handling)
V8_INLINE BasicTracedReference< S > & As() const
Local< T > Get(Isolate *isolate) const
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
friend bool operator==(const TracedReferenceBase &, const Local< U > &)
V8_EXPORT void CheckValue() const
Definition api.cc:11843
V8_INLINE Local< Data > Get(Isolate *isolate) const
const internal::Address * GetSlotThreadSafe() const
void SetSlotThreadSafe(internal::Address *new_val)
V8_INLINE TracedReferenceBase()=default
V8_INLINE void Reset(Isolate *isolate, const Local< S > &other)
TracedReference(Isolate *isolate, Local< S > that)
V8_INLINE TracedReference(const TracedReference &other)
V8_INLINE TracedReference(TracedReference &&other) noexcept
V8_INLINE TracedReference & operator=(TracedReference< S > &&rhs) noexcept
V8_INLINE TracedReference< S > & As() const
V8_INLINE TracedReference & operator=(const TracedReference< S > &rhs)
V8_INLINE TracedReference(TracedReference< S > &&other) noexcept
V8_INLINE TracedReference(const TracedReference< S > &other)
V8_INLINE TracedReference()=default
V8_INLINE void Reset(Isolate *isolate, const Local< S > &other, IsDroppable)
TracedReference(Isolate *isolate, Local< S > that, IsDroppable)
V8_INLINE TracedReference & operator=(TracedReference &&rhs) noexcept
V8_INLINE internal::Address *const & slot() const
static V8_INLINE bool EqualHandles(const T1 &lhs, const T2 &rhs)
static V8_INLINE Address ValueAsAddress(const T *value)
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 DisposeTracedReference(internal::Address *location)
Definition api.cc:580
void CopyTracedReference(const internal::Address *const *from, internal::Address **to)
Definition api.cc:575
i::Address * GlobalizeTracedReference(i::Isolate *i_isolate, i::Address value, internal::Address *slot, TracedReferenceStoreMode store_mode, TracedReferenceHandling reference_handling)
Definition api.cc:562
void MoveTracedReference(internal::Address **from, internal::Address **to)
Definition api.cc:571
V8_INLINE bool operator==(const TracedReferenceBase &lhs, const TracedReferenceBase &rhs)
V8_INLINE bool operator!=(const TracedReferenceBase &lhs, const TracedReferenceBase &rhs)
#define V8_EXPORT
Definition v8config.h:800
#define V8_INLINE
Definition v8config.h:500
#define V8_UNLIKELY(condition)
Definition v8config.h:660