v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
unified-heap-marking-verifier.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
7#include <memory>
8
10#include "include/v8-cppgc.h"
14
15namespace v8 {
16namespace internal {
17
18namespace {
19
20class UnifiedHeapVerificationVisitor final : public JSVisitor {
21 public:
22 explicit UnifiedHeapVerificationVisitor(UnifiedHeapVerificationState& state)
23 : JSVisitor(cppgc::internal::VisitorFactory::CreateKey()),
24 state_(state) {}
25
26 void Visit(const void*, cppgc::TraceDescriptor desc) final {
27 state_.VerifyMarked(desc.base_object_payload);
28 }
29
30 void VisitWeak(const void*, cppgc::TraceDescriptor desc, cppgc::WeakCallback,
31 const void*) final {
32 // Weak objects should have been cleared at this point. As a consequence,
33 // all objects found through weak references have to point to live objects
34 // at this point.
35 state_.VerifyMarked(desc.base_object_payload);
36 }
37
38 void VisitWeakContainer(const void* object, cppgc::TraceDescriptor,
40 const void*) final {
41 if (!object) return;
42
43 // Contents of weak containers are found themselves through page iteration
44 // and are treated strongly, similar to how they are treated strongly when
45 // found through stack scanning. The verification here only makes sure that
46 // the container itself is properly marked.
47 state_.VerifyMarked(weak_desc.base_object_payload);
48 }
49
50 void Visit(const TracedReferenceBase& ref) final {
51 state_.VerifyMarkedTracedReference(ref);
52 }
53
54 private:
55 UnifiedHeapVerificationState& state_;
56};
57
58} // namespace
59
61 const TracedReferenceBase& ref) const {
62 // The following code will crash with null pointer derefs when finding a
63 // non-empty `TracedReferenceBase` when `CppHeap` is in detached mode.
64 Address* traced_handle_location =
66 // We cannot assume that the reference is non-null as we may get here by
67 // tracing an ephemeron which doesn't have early bailouts, see
68 // `cppgc::Visitor::TraceEphemeron()` for non-Member values.
69 if (!traced_handle_location) {
70 return;
71 }
72 // Verification runs after unamrked nodes are freed. The node for this
73 // TracedReference should still be marked as in use.
74 if (!TracedHandles::IsValidInUseNode(traced_handle_location)) {
75 FATAL(
76 "MarkingVerifier: Encountered unmarked TracedReference.\n"
77 "#\n"
78 "# Hint:\n"
79 "# %s (%p)\n"
80 "# \\-> TracedReference (%p)",
82 ? parent_
84 kUseClassNameIfSupported)
85 .value
86 : "Stack",
87 parent_ ? parent_->ObjectStart() : nullptr, &ref);
88 }
89}
90
93 cppgc::internal::CollectionType collection_type)
94 : MarkingVerifierBase(
95 heap_base, collection_type, state_,
96 std::make_unique<UnifiedHeapVerificationVisitor>(state_)) {}
97
98} // namespace internal
99} // namespace v8
const HeapObjectHeader * parent_
static Address * GetObjectSlotForMarking(const TracedReferenceBase &ref)
static bool IsValidInUseNode(const Address *location)
UnifiedHeapMarkingVerifier(cppgc::internal::HeapBase &, cppgc::internal::CollectionType)
void VerifyMarkedTracedReference(const TracedReferenceBase &ref) const
enum v8::internal::@1270::DeoptimizableCodeIterator::@67 state_
void(*)(const LivenessBroker &, const void *) WeakCallback
Definition visitor.h:37
STL namespace.
#define FATAL(...)
Definition logging.h:47