Commit f00727d2 authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

[heap] Make PagedSpace::Verify* methods const

Bug: v8:12612
Change-Id: I47bf134a9ff57a5c4ace9d35bf023a1c5e248896
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3644615Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80498}
parent 87098192
......@@ -4792,6 +4792,10 @@ void Heap::VerifyCountersBeforeConcurrentSweeping() {
PagedSpaceIterator spaces(this);
for (PagedSpace* space = spaces.Next(); space != nullptr;
space = spaces.Next()) {
// We need to refine the counters on pages that are already swept and have
// not been moved over to the actual space. Otherwise, the AccountingStats
// are just an over approximation.
space->RefillFreeList();
space->VerifyCountersBeforeConcurrentSweeping();
}
}
......
......@@ -263,7 +263,7 @@ class MajorMarkingState final
chunk->live_byte_count_.fetch_add(by, std::memory_order_relaxed);
}
intptr_t live_bytes(MemoryChunk* chunk) const {
intptr_t live_bytes(const MemoryChunk* chunk) const {
return chunk->live_byte_count_.load(std::memory_order_relaxed);
}
......@@ -306,7 +306,7 @@ class MajorNonAtomicMarkingState final
chunk->live_byte_count_.fetch_add(by, std::memory_order_relaxed);
}
intptr_t live_bytes(MemoryChunk* chunk) const {
intptr_t live_bytes(const MemoryChunk* chunk) const {
return chunk->live_byte_count_.load(std::memory_order_relaxed);
}
......
......@@ -30,7 +30,7 @@ namespace internal {
// PagedSpaceObjectIterator
PagedSpaceObjectIterator::PagedSpaceObjectIterator(Heap* heap,
PagedSpace* space)
const PagedSpace* space)
: cur_addr_(kNullAddress),
cur_end_(kNullAddress),
space_(space),
......@@ -46,8 +46,8 @@ PagedSpaceObjectIterator::PagedSpaceObjectIterator(Heap* heap,
}
PagedSpaceObjectIterator::PagedSpaceObjectIterator(Heap* heap,
PagedSpace* space,
Page* page)
const PagedSpace* space,
const Page* page)
: cur_addr_(kNullAddress),
cur_end_(kNullAddress),
space_(space),
......@@ -70,7 +70,7 @@ PagedSpaceObjectIterator::PagedSpaceObjectIterator(Heap* heap,
bool PagedSpaceObjectIterator::AdvanceToNextPage() {
DCHECK_EQ(cur_addr_, cur_end_);
if (current_page_ == page_range_.end()) return false;
Page* cur_page = *(current_page_++);
const Page* cur_page = *(current_page_++);
cur_addr_ = cur_page->area_start();
cur_end_ = cur_page->area_end();
......@@ -733,7 +733,7 @@ void PagedSpace::Print() {}
#endif
#ifdef VERIFY_HEAP
void PagedSpace::Verify(Isolate* isolate, ObjectVisitor* visitor) {
void PagedSpace::Verify(Isolate* isolate, ObjectVisitor* visitor) const {
bool allocation_pointer_found_in_space =
(allocation_info_->top() == allocation_info_->limit());
size_t external_space_bytes[kNumTypes];
......@@ -744,7 +744,7 @@ void PagedSpace::Verify(Isolate* isolate, ObjectVisitor* visitor) {
}
PtrComprCageBase cage_base(isolate);
for (Page* page : *this) {
for (const Page* page : *this) {
CHECK_EQ(page->owner(), this);
for (int i = 0; i < kNumTypes; i++) {
......@@ -819,11 +819,11 @@ void PagedSpace::Verify(Isolate* isolate, ObjectVisitor* visitor) {
#endif
}
void PagedSpace::VerifyLiveBytes() {
void PagedSpace::VerifyLiveBytes() const {
IncrementalMarking::MarkingState* marking_state =
heap()->incremental_marking()->marking_state();
PtrComprCageBase cage_base(heap()->isolate());
for (Page* page : *this) {
for (const Page* page : *this) {
CHECK(page->SweepingDone());
PagedSpaceObjectIterator it(heap(), this, page);
int black_size = 0;
......@@ -839,11 +839,11 @@ void PagedSpace::VerifyLiveBytes() {
#endif // VERIFY_HEAP
#ifdef DEBUG
void PagedSpace::VerifyCountersAfterSweeping(Heap* heap) {
void PagedSpace::VerifyCountersAfterSweeping(Heap* heap) const {
size_t total_capacity = 0;
size_t total_allocated = 0;
PtrComprCageBase cage_base(heap->isolate());
for (Page* page : *this) {
for (const Page* page : *this) {
DCHECK(page->SweepingDone());
total_capacity += page->area_size();
PagedSpaceObjectIterator it(heap, this, page);
......@@ -863,17 +863,12 @@ void PagedSpace::VerifyCountersAfterSweeping(Heap* heap) {
DCHECK_EQ(total_allocated, accounting_stats_.Size());
}
void PagedSpace::VerifyCountersBeforeConcurrentSweeping() {
// We need to refine the counters on pages that are already swept and have
// not been moved over to the actual space. Otherwise, the AccountingStats
// are just an over approximation.
RefillFreeList();
void PagedSpace::VerifyCountersBeforeConcurrentSweeping() const {
size_t total_capacity = 0;
size_t total_allocated = 0;
auto marking_state =
heap()->incremental_marking()->non_atomic_marking_state();
for (Page* page : *this) {
for (const Page* page : *this) {
size_t page_allocated =
page->SweepingDone()
? page->allocated_bytes()
......
......@@ -30,7 +30,7 @@ class Isolate;
class ObjectVisitor;
// -----------------------------------------------------------------------------
// Heap object iterator in old/map spaces.
// Heap object iterator in paged spaces.
//
// A PagedSpaceObjectIterator iterates objects from the bottom of the given
// space to its top or from the bottom of the given page to its top.
......@@ -41,8 +41,9 @@ class ObjectVisitor;
class V8_EXPORT_PRIVATE PagedSpaceObjectIterator : public ObjectIterator {
public:
// Creates a new object iterator in a given space.
PagedSpaceObjectIterator(Heap* heap, PagedSpace* space);
PagedSpaceObjectIterator(Heap* heap, PagedSpace* space, Page* page);
PagedSpaceObjectIterator(Heap* heap, const PagedSpace* space);
PagedSpaceObjectIterator(Heap* heap, const PagedSpace* space,
const Page* page);
// Advance to the next object, skipping free spaces and other fillers and
// skipping the special garbage section of which there is one per space.
......@@ -70,8 +71,8 @@ class V8_EXPORT_PRIVATE PagedSpaceObjectIterator : public ObjectIterator {
Address cur_addr_; // Current iteration point.
Address cur_end_; // End iteration point.
const PagedSpace* const space_;
PageRange page_range_;
PageRange::iterator current_page_;
ConstPageRange page_range_;
ConstPageRange::iterator current_page_;
#if V8_COMPRESS_POINTERS
const PtrComprCageBase cage_base_;
#endif // V8_COMPRESS_POINTERS
......@@ -233,9 +234,9 @@ class V8_EXPORT_PRIVATE PagedSpace
#ifdef VERIFY_HEAP
// Verify integrity of this space.
virtual void Verify(Isolate* isolate, ObjectVisitor* visitor);
virtual void Verify(Isolate* isolate, ObjectVisitor* visitor) const;
void VerifyLiveBytes();
void VerifyLiveBytes() const;
// Overridden by subclasses to verify space-specific object
// properties (e.g., only maps or free-list nodes are in map space).
......@@ -243,8 +244,8 @@ class V8_EXPORT_PRIVATE PagedSpace
#endif
#ifdef DEBUG
void VerifyCountersAfterSweeping(Heap* heap);
void VerifyCountersBeforeConcurrentSweeping();
void VerifyCountersAfterSweeping(Heap* heap) const;
void VerifyCountersBeforeConcurrentSweeping() const;
// Print meta info and objects in this space.
void Print() override;
......
......@@ -42,6 +42,16 @@ PageRange::PageRange(Address start, Address limit)
#endif // DEBUG
}
ConstPageRange::ConstPageRange(Address start, Address limit)
: begin_(Page::FromAddress(start)),
end_(Page::FromAllocationAreaAddress(limit)->next_page()) {
#ifdef DEBUG
if (begin_->InNewSpace()) {
SemiSpace::AssertValidRange(start, limit);
}
#endif // DEBUG
}
void Space::IncrementExternalBackingStoreBytes(ExternalBackingStoreType type,
size_t amount) {
base::CheckedIncrement(&external_backing_store_bytes_[type], amount);
......
......@@ -388,6 +388,23 @@ class PageRange {
Page* end_;
};
class ConstPageRange {
public:
using iterator = ConstPageIterator;
ConstPageRange(const Page* begin, const Page* end)
: begin_(begin), end_(end) {}
explicit ConstPageRange(const Page* page)
: ConstPageRange(page, page->next_page()) {}
inline ConstPageRange(Address start, Address limit);
iterator begin() { return iterator(begin_); }
iterator end() { return iterator(end_); }
private:
const Page* begin_;
const Page* end_;
};
// -----------------------------------------------------------------------------
// A space has a circular list of pages. The next page can be accessed via
// Page::next_page() call.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment