heap: Fix bug in ReadOnlySpaceObjectIterator

ReadOnlySpaceObjectIterator did not iterate through objects, because of
a bug in the initialization of `cur_addr_` and `cur_end_`. This CL also
merges methods `Next` and `FromCurrentPage`.

Change-Id: Id56bff279216c7a5982d984d80b649bd0c915959
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3758225
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81668}
This commit is contained in:
Nikolaos Papaspyrou 2022-07-12 16:21:38 +02:00 committed by V8 LUCI CQ
parent 192d8c172a
commit d0a4c900ba

View File

@ -421,19 +421,14 @@ class ReadOnlySpaceObjectIterator : public ObjectIterator {
public:
ReadOnlySpaceObjectIterator(const Heap* heap, const ReadOnlySpace* space,
BasicMemoryChunk* chunk)
: cur_addr_(kNullAddress), cur_end_(kNullAddress), space_(space) {}
: cur_addr_(chunk->area_start()),
cur_end_(chunk->area_end()),
space_(space) {}
// Advance to the next object, skipping free spaces and other fillers and
// skipping the special garbage section of which there is one per space.
// Returns nullptr when the iteration has ended.
// Returns a null object when the iteration has ended.
HeapObject Next() override {
HeapObject next_obj = FromCurrentPage();
if (!next_obj.is_null()) return next_obj;
return HeapObject();
}
private:
HeapObject FromCurrentPage() {
while (cur_addr_ != cur_end_) {
if (cur_addr_ == space_->top() && cur_addr_ != space_->limit()) {
cur_addr_ = space_->limit();