v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
evacuation-verifier.cc
Go to the documentation of this file.
1// Copyright 2022 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
10
11namespace v8 {
12namespace internal {
13
14#ifdef VERIFY_HEAP
15
16EvacuationVerifier::EvacuationVerifier(Heap* heap)
17 : ObjectVisitorWithCageBases(heap), heap_(heap) {}
18
19void EvacuationVerifier::Run() {
20 CHECK(!heap_->sweeping_in_progress());
21 VerifyRoots();
22 VerifyEvacuation(heap_->new_space());
23 VerifyEvacuation(heap_->old_space());
24 VerifyEvacuation(heap_->code_space());
25 if (heap_->shared_space()) VerifyEvacuation(heap_->shared_space());
26}
27
28void EvacuationVerifier::VisitPointers(Tagged<HeapObject> host,
29 ObjectSlot start, ObjectSlot end) {
30 VerifyPointersImpl(start, end);
31}
32
33void EvacuationVerifier::VisitPointers(Tagged<HeapObject> host,
34 MaybeObjectSlot start,
35 MaybeObjectSlot end) {
36 VerifyPointersImpl(start, end);
37}
38
39void EvacuationVerifier::VisitInstructionStreamPointer(
40 Tagged<Code> host, InstructionStreamSlot slot) {
41 Tagged<Object> maybe_code = slot.load(code_cage_base());
42 Tagged<HeapObject> code;
43 // The slot might contain smi during Code creation, so skip it.
44 if (maybe_code.GetHeapObject(&code)) {
45 VerifyHeapObjectImpl(code);
46 }
47}
48
49void EvacuationVerifier::VisitRootPointers(Root root, const char* description,
50 FullObjectSlot start,
51 FullObjectSlot end) {
52 VerifyPointersImpl(start, end);
53}
54
55void EvacuationVerifier::VisitMapPointer(Tagged<HeapObject> object) {
56 VerifyHeapObjectImpl(object->map(cage_base()));
57}
58
59void EvacuationVerifier::VisitCodeTarget(Tagged<InstructionStream> host,
60 RelocInfo* rinfo) {
61 Tagged<InstructionStream> target =
62 InstructionStream::FromTargetAddress(rinfo->target_address());
63 VerifyHeapObjectImpl(target);
64}
65
66void EvacuationVerifier::VisitEmbeddedPointer(Tagged<InstructionStream> host,
67 RelocInfo* rinfo) {
68 VerifyHeapObjectImpl(rinfo->target_object(cage_base()));
69}
70
71void EvacuationVerifier::VerifyRoots() {
72 heap_->IterateRootsIncludingClients(
73 this,
74 base::EnumSet<SkipRoot>{SkipRoot::kWeak, SkipRoot::kConservativeStack});
75}
76
77void EvacuationVerifier::VerifyEvacuationOnPage(Address start, Address end) {
78 Address current = start;
79 while (current < end) {
80 Tagged<HeapObject> object = HeapObject::FromAddress(current);
81 if (!IsFreeSpaceOrFiller(object, cage_base())) {
82 VisitObject(heap_->isolate(), object, this);
83 }
84 current += ALIGN_TO_ALLOCATION_ALIGNMENT(object->Size(cage_base()));
85 }
86}
87
88void EvacuationVerifier::VerifyEvacuation(NewSpace* space) {
89 if (!space) return;
90
91 if (v8_flags.minor_ms) {
92 VerifyEvacuation(PagedNewSpace::From(space)->paged_space());
93 return;
94 }
95
96 for (PageMetadata* p : *space) {
97 VerifyEvacuationOnPage(p->area_start(), p->area_end());
98 }
99}
100
101void EvacuationVerifier::VerifyEvacuation(PagedSpaceBase* space) {
102 for (PageMetadata* p : *space) {
103 if (p->Chunk()->IsEvacuationCandidate()) continue;
104 VerifyEvacuationOnPage(p->area_start(), p->area_end());
105 }
106}
107
108#endif // VERIFY_HEAP
109
110} // namespace internal
111} // namespace v8
Handle< Code > code
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
int start
int end
uintptr_t Address
Definition memory.h:13
V8_INLINE constexpr bool IsFreeSpaceOrFiller(InstanceType instance_type)
void VisitObject(Isolate *isolate, Tagged< HeapObject > object, ObjectVisitor *visitor)
V8_EXPORT_PRIVATE FlagValues v8_flags
#define CHECK(condition)
Definition logging.h:124
Heap * heap_