blob: 95475f5191aa948110c3d988439590155e9d4aff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_HEAP_CPPGC_MARKING_VERIFIER_H_
#define V8_HEAP_CPPGC_MARKING_VERIFIER_H_
#include <unordered_set>
#include "src/heap/base/stack.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/heap-visitor.h"
#include "src/heap/cppgc/heap.h"
#include "src/heap/cppgc/visitor.h"
namespace cppgc {
namespace internal {
class VerificationState {
public:
void VerifyMarked(const void*) const;
void SetCurrentParent(const HeapObjectHeader* header) { parent_ = header; }
// No parent means parent was on stack.
bool IsParentOnStack() const { return !parent_; }
private:
const HeapObjectHeader* parent_ = nullptr;
};
class V8_EXPORT_PRIVATE MarkingVerifierBase
: private HeapVisitor<MarkingVerifierBase>,
public ConservativeTracingVisitor,
public heap::base::StackVisitor {
friend class HeapVisitor<MarkingVerifierBase>;
public:
~MarkingVerifierBase() override = default;
MarkingVerifierBase(const MarkingVerifierBase&) = delete;
MarkingVerifierBase& operator=(const MarkingVerifierBase&) = delete;
void Run(Heap::Config::StackState, uintptr_t, size_t);
protected:
MarkingVerifierBase(HeapBase&, VerificationState&,
std::unique_ptr<cppgc::Visitor>);
private:
void VisitInConstructionConservatively(HeapObjectHeader&,
TraceConservativelyCallback) final;
void VisitPointer(const void*) final;
bool VisitHeapObjectHeader(HeapObjectHeader*);
VerificationState& verification_state_;
std::unique_ptr<cppgc::Visitor> visitor_;
std::unordered_set<const HeapObjectHeader*> in_construction_objects_heap_;
std::unordered_set<const HeapObjectHeader*> in_construction_objects_stack_;
std::unordered_set<const HeapObjectHeader*>* in_construction_objects_ =
&in_construction_objects_heap_;
size_t found_marked_bytes_ = 0;
};
class V8_EXPORT_PRIVATE MarkingVerifier final : public MarkingVerifierBase {
public:
explicit MarkingVerifier(HeapBase&);
~MarkingVerifier() final = default;
private:
VerificationState state_;
};
} // namespace internal
} // namespace cppgc
#endif // V8_HEAP_CPPGC_MARKING_VERIFIER_H_
|