v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
visitor.cc
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
6
15
16#if defined(CPPGC_CAGED_HEAP)
18#endif // defined(CPPGC_CAGED_HEAP)
19
20namespace cppgc {
21
22#ifdef V8_ENABLE_CHECKS
23void Visitor::CheckObjectNotInConstruction(const void* address) {
24 // TODO(chromium:1056170): |address| is an inner pointer of an object. Check
25 // that the object is not in construction.
26}
27#endif // V8_ENABLE_CHECKS
28
29namespace internal {
30
31#if defined(CPPGC_POINTER_COMPRESSION)
32// CompressedPointer is compatible with RawPointer and will find full pointers
33// as well.
34using PointerRepresentation = CompressedPointer;
35#else
37#endif // defined(CPPGC_POINTER_COMPRESSION)
38
40 HeapBase& heap, PageBackend& page_backend, cppgc::Visitor& visitor)
41 : heap_(heap), page_backend_(page_backend), visitor_(visitor) {}
42
43// Conservative scanning of objects is not compatible with ASAN as we may scan
44// over objects reading poisoned memory. One such example was added to libc++
45// (June 2024) in the form of container annotations for short std::string.
48 const HeapObjectHeader& header) {
49 const auto object_view = ObjectView<>(header);
50 uintptr_t* word = reinterpret_cast<uintptr_t*>(object_view.Start());
51 for (size_t i = 0; i < (object_view.Size() / sizeof(uintptr_t)); ++i) {
52 uintptr_t maybe_full_ptr = word[i];
53 // |object| may be uninitialized by design or just contain padding bytes.
54 // Copy into a local variable that is not poisoned for conservative marking.
55 // Copy into a temporary variable to maintain the original MSAN state.
56 MSAN_MEMORY_IS_INITIALIZED(&maybe_full_ptr, sizeof(maybe_full_ptr));
57 // Neither first OS page, nor first cage page contain Oilpan objects.
58 if (maybe_full_ptr <= SentinelPointer::kSentinelValue) {
59 continue;
60 }
62 reinterpret_cast<void*>(maybe_full_ptr),
63 [this](const void* raw_pointer) {
64 this->TraceConservativelyIfNeeded(raw_pointer);
65 });
66 // We must also trace full pointers here as the conservative tracing visitor
67 // may be overridden to find pointers to other areas conservatively as well.
68 // E.g., v8::TracedReference points into a different memory region and is
69 // scanned conservatively when the GCed object is in construction. See
70 // `UnifiedHeapConservativeMarkingVisitor::TraceConservativelyIfNeeded()`.
71 this->TraceConservativelyIfNeeded(reinterpret_cast<void*>(maybe_full_ptr));
72 }
73}
74
76 ConstAddress address) {
77#if defined(CPPGC_CAGED_HEAP)
78 // TODO(chromium:1056170): Add support for SIMD in stack scanning.
79 if (V8_LIKELY(!CagedHeapBase::IsWithinCage(address))) return;
80#endif // defined(CPPGC_CAGED_HEAP)
81
82 const BasePage* page =
83 reinterpret_cast<const BasePage*>(page_backend_.Lookup(address));
84 if (!page) {
85 return;
86 }
87 DCHECK_EQ(&heap_, &page->heap());
88 auto* header = const_cast<HeapObjectHeader*>(
89 page->TryObjectHeaderFromInnerAddress(address));
90 if (!header) {
91 return;
92 }
94}
95
97 const void* address) {
98 // Neither first OS page, nor first cage page contain Oilpan objects.
99 if (reinterpret_cast<ConstAddress>(address) <=
101 return;
102 }
104 address, [this](const void* raw_pointer) {
106 reinterpret_cast<ConstAddress>(raw_pointer));
107 });
108}
109
122
124 HeapObjectHeader& header) {
126 header.ObjectStart(),
127 {header.ObjectStart(),
128 GlobalGCInfoTable::GCInfoFromIndex(header.GetGCInfoIndex()).trace});
129}
130
131} // namespace internal
132} // namespace cppgc
#define DISABLE_ASAN
Definition asan.h:62
virtual void Visit(const void *self, TraceDescriptor)
Definition visitor.h:373
void TryTracePointerConservatively(ConstAddress address)
Definition visitor.cc:75
void TraceConservatively(const HeapObjectHeader &)
Definition visitor.cc:47
ConservativeTracingVisitor(HeapBase &, PageBackend &, cppgc::Visitor &)
Definition visitor.cc:39
virtual void VisitInConstructionConservatively(HeapObjectHeader &, TraceConservativelyCallback)
Definition visitor.h:66
virtual void VisitFullyConstructedConservatively(HeapObjectHeader &)
Definition visitor.cc:123
virtual void TraceConservativelyIfNeeded(const void *)
Definition visitor.cc:96
Address Lookup(ConstAddress) const
static V8_INLINE void VisitPossiblePointers(const void *address, Callback callback)
#define MSAN_MEMORY_IS_INITIALIZED(start, size)
Definition msan.h:37
RawPointer PointerRepresentation
Definition visitor.cc:36
const uint8_t * ConstAddress
Definition globals.h:18
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
static constexpr intptr_t kSentinelValue
RootVisitor * visitor_
Heap * heap_
#define V8_LIKELY(condition)
Definition v8config.h:661