summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/evacuation-verifier.cc
blob: f7fcbccc2f5c010babcc9b9188e2c5ce358dfe60 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2022 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.

#include "src/codegen/assembler-inl.h"
#include "src/codegen/reloc-info.h"
#include "src/heap/evacuation-verifier-inl.h"
#include "src/objects/map-inl.h"

namespace v8 {
namespace internal {

#ifdef VERIFY_HEAP

EvacuationVerifier::EvacuationVerifier(Heap* heap)
    : ObjectVisitorWithCageBases(heap), heap_(heap) {}

void EvacuationVerifier::VisitPointers(HeapObject host, ObjectSlot start,
                                       ObjectSlot end) {
  VerifyPointers(start, end);
}

void EvacuationVerifier::VisitPointers(HeapObject host, MaybeObjectSlot start,
                                       MaybeObjectSlot end) {
  VerifyPointers(start, end);
}

void EvacuationVerifier::VisitCodePointer(HeapObject host,
                                          CodeObjectSlot slot) {
  CHECK(V8_EXTERNAL_CODE_SPACE_BOOL);
  VerifyCodePointer(slot);
}

void EvacuationVerifier::VisitRootPointers(Root root, const char* description,
                                           FullObjectSlot start,
                                           FullObjectSlot end) {
  VerifyRootPointers(start, end);
}

void EvacuationVerifier::VisitMapPointer(HeapObject object) {
  VerifyMap(object.map(cage_base()));
}
void EvacuationVerifier::VerifyRoots() {
  heap_->IterateRootsIncludingClients(
      this,
      base::EnumSet<SkipRoot>{SkipRoot::kWeak, SkipRoot::kConservativeStack});
}

void EvacuationVerifier::VerifyEvacuationOnPage(Address start, Address end) {
  Address current = start;
  while (current < end) {
    HeapObject object = HeapObject::FromAddress(current);
    if (!object.IsFreeSpaceOrFiller(cage_base())) {
      object.Iterate(cage_base(), this);
    }
    current += ALIGN_TO_ALLOCATION_ALIGNMENT(object.Size(cage_base()));
  }
}

void EvacuationVerifier::VerifyEvacuation(NewSpace* space) {
  if (!space) return;
  if (v8_flags.minor_mc) {
    VerifyEvacuation(PagedNewSpace::From(space)->paged_space());
    return;
  }
  PageRange range(space->first_allocatable_address(), space->top());
  for (auto it = range.begin(); it != range.end();) {
    Page* page = *(it++);
    Address current = page->area_start();
    Address limit = it != range.end() ? page->area_end() : space->top();
    CHECK(limit == space->top() || !page->Contains(space->top()));
    VerifyEvacuationOnPage(current, limit);
  }
}

void EvacuationVerifier::VerifyEvacuation(PagedSpaceBase* space) {
  for (Page* p : *space) {
    if (p->IsEvacuationCandidate()) continue;
    if (p->Contains(space->top())) {
      CodePageMemoryModificationScope memory_modification_scope(p);
      heap_->CreateFillerObjectAt(
          space->top(), static_cast<int>(space->limit() - space->top()));
    }
    VerifyEvacuationOnPage(p->area_start(), p->area_end());
  }
}

FullEvacuationVerifier::FullEvacuationVerifier(Heap* heap)
    : EvacuationVerifier(heap) {}

void FullEvacuationVerifier::Run() {
  DCHECK(!heap_->sweeping_in_progress());
  VerifyRoots();
  VerifyEvacuation(heap_->new_space());
  VerifyEvacuation(heap_->old_space());
  VerifyEvacuation(heap_->code_space());
  if (heap_->shared_space()) VerifyEvacuation(heap_->shared_space());
}

void FullEvacuationVerifier::VerifyMap(Map map) { VerifyHeapObjectImpl(map); }
void FullEvacuationVerifier::VerifyPointers(ObjectSlot start, ObjectSlot end) {
  VerifyPointersImpl(start, end);
}
void FullEvacuationVerifier::VerifyPointers(MaybeObjectSlot start,
                                            MaybeObjectSlot end) {
  VerifyPointersImpl(start, end);
}
void FullEvacuationVerifier::VerifyCodePointer(CodeObjectSlot slot) {
  CHECK(V8_EXTERNAL_CODE_SPACE_BOOL);
  Object maybe_code = slot.load(code_cage_base());
  HeapObject code;
  // The slot might contain smi during CodeDataContainer creation, so skip it.
  if (maybe_code.GetHeapObject(&code)) {
    VerifyHeapObjectImpl(code);
  }
}
void FullEvacuationVerifier::VisitCodeTarget(Code host, RelocInfo* rinfo) {
  Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
  VerifyHeapObjectImpl(target);
}
void FullEvacuationVerifier::VisitEmbeddedPointer(Code host, RelocInfo* rinfo) {
  VerifyHeapObjectImpl(rinfo->target_object(cage_base()));
}
void FullEvacuationVerifier::VerifyRootPointers(FullObjectSlot start,
                                                FullObjectSlot end) {
  VerifyPointersImpl(start, end);
}

YoungGenerationEvacuationVerifier::YoungGenerationEvacuationVerifier(Heap* heap)
    : EvacuationVerifier(heap) {}

void YoungGenerationEvacuationVerifier::YoungGenerationEvacuationVerifier::
    Run() {
  DCHECK(!heap_->sweeping_in_progress());
  VerifyRoots();
  VerifyEvacuation(heap_->new_space());
  VerifyEvacuation(heap_->old_space());
  VerifyEvacuation(heap_->code_space());
}

void YoungGenerationEvacuationVerifier::VerifyMap(Map map) {
  VerifyHeapObjectImpl(map);
}
void YoungGenerationEvacuationVerifier::VerifyPointers(ObjectSlot start,
                                                       ObjectSlot end) {
  VerifyPointersImpl(start, end);
}
void YoungGenerationEvacuationVerifier::VerifyPointers(MaybeObjectSlot start,
                                                       MaybeObjectSlot end) {
  VerifyPointersImpl(start, end);
}
void YoungGenerationEvacuationVerifier::VerifyCodePointer(CodeObjectSlot slot) {
  CHECK(V8_EXTERNAL_CODE_SPACE_BOOL);
  Object maybe_code = slot.load(code_cage_base());
  HeapObject code;
  // The slot might contain smi during CodeDataContainer creation, so skip it.
  if (maybe_code.GetHeapObject(&code)) {
    VerifyHeapObjectImpl(code);
  }
}
void YoungGenerationEvacuationVerifier::VisitCodeTarget(Code host,
                                                        RelocInfo* rinfo) {
  Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
  VerifyHeapObjectImpl(target);
}
void YoungGenerationEvacuationVerifier::VisitEmbeddedPointer(Code host,
                                                             RelocInfo* rinfo) {
  VerifyHeapObjectImpl(rinfo->target_object(cage_base()));
}
void YoungGenerationEvacuationVerifier::VerifyRootPointers(FullObjectSlot start,
                                                           FullObjectSlot end) {
  VerifyPointersImpl(start, end);
}

#endif  // VERIFY_HEAP

}  // namespace internal
}  // namespace v8