v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
trace-trait.h
Go to the documentation of this file.
1// Copyright 2020 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_CPPGC_TRACE_TRAIT_H_
6#define INCLUDE_CPPGC_TRACE_TRAIT_H_
7
8#include <type_traits>
9
10#include "cppgc/type-traits.h"
11#include "v8config.h" // NOLINT(build/include_directory)
12
13namespace cppgc {
14
15class Visitor;
16
17namespace internal {
18
19class RootVisitor;
20
21using TraceRootCallback = void (*)(RootVisitor&, const void* object);
22
23// Implementation of the default TraceTrait handling GarbageCollected and
24// GarbageCollectedMixin.
25template <typename T,
26 bool = IsGarbageCollectedMixinTypeV<std::remove_const_t<T>>>
27struct TraceTraitImpl;
28
29} // namespace internal
30
31/**
32 * Callback for invoking tracing on a given object.
33 *
34 * \param visitor The visitor to dispatch to.
35 * \param object The object to invoke tracing on.
36 */
37using TraceCallback = void (*)(Visitor* visitor, const void* object);
38
39/**
40 * Describes how to trace an object, i.e., how to visit all Oilpan-relevant
41 * fields of an object.
42 */
44 /**
45 * Adjusted base pointer, i.e., the pointer to the class inheriting directly
46 * from GarbageCollected, of the object that is being traced.
47 */
49 /**
50 * Callback for tracing the object.
51 */
52 TraceCallback callback;
53};
54
55/**
56 * Callback for getting a TraceDescriptor for a given address.
57 *
58 * \param address Possibly inner address of an object.
59 * \returns a TraceDescriptor for the provided address.
60 */
61using TraceDescriptorCallback = TraceDescriptor (*)(const void* address);
62
63namespace internal {
64
66 static TraceDescriptor GetTraceDescriptor(const void* address);
67};
68
69/**
70 * Trait specifying how the garbage collector processes an object of type T.
71 *
72 * Advanced users may override handling by creating a specialization for their
73 * type.
74 */
75template <typename T>
77 static_assert(internal::IsTraceableV<T>, "T must have a Trace() method");
78
79 /**
80 * Accessor for retrieving a TraceDescriptor to process an object of type T.
81 *
82 * \param self The object to be processed.
83 * \returns a TraceDescriptor to process the object.
84 */
85 static TraceDescriptor GetTraceDescriptor(const void* self) {
86 return internal::TraceTraitImpl<T>::GetTraceDescriptor(
87 static_cast<const T*>(self));
88 }
89
90 /**
91 * Function invoking the tracing for an object of type T.
92 *
93 * \param visitor The visitor to dispatch to.
94 * \param self The object to invoke tracing on.
95 */
96 static void Trace(Visitor* visitor, const void* self) {
97 static_cast<const T*>(self)->Trace(visitor);
98 }
99};
100
101} // namespace internal
102
103template <typename T>
104struct TraceTrait : public internal::TraceTraitBase<T> {};
105
106namespace internal {
107
108template <typename T>
109struct TraceTraitImpl<T, false> {
110 static_assert(IsGarbageCollectedTypeV<T>,
111 "T must be of type GarbageCollected or GarbageCollectedMixin");
112 static TraceDescriptor GetTraceDescriptor(const void* self) {
113 return {self, TraceTrait<T>::Trace};
114 }
115};
116
117template <typename T>
118struct TraceTraitImpl<T, true> {
119 static TraceDescriptor GetTraceDescriptor(const void* self) {
121 }
122};
123
124} // namespace internal
125} // namespace cppgc
126
127#endif // INCLUDE_CPPGC_TRACE_TRAIT_H_
TraceCallback callback
Definition trace-trait.h:52
const void * base_object_payload
Definition trace-trait.h:48
static void Trace(Visitor *visitor, const void *self)
Definition trace-trait.h:96
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition trace-trait.h:85
static TraceDescriptor GetTraceDescriptor(const void *address)
static TraceDescriptor GetTraceDescriptor(const void *self)
static TraceDescriptor GetTraceDescriptor(const void *self)
#define V8_EXPORT
Definition v8config.h:860