Commit ad6bc485 authored by Maciej Goszczycki's avatar Maciej Goszczycki Committed by Commit Bot

[cleanup] Remove unreachable code in PagedSpaces

counter_ could never be RO_SPACE. Make sure RO_SPACE and OLD_SPACE are
marked as unreachable.

Added tests for PagedSpaces and SpaceIterator.

Bug: v8:9183
Change-Id: I97bc2b4e0e5af37363a1c628ca7d69d2790a97b4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1635696
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61943}
parent f993a9c9
......@@ -5340,9 +5340,8 @@ void Heap::ClearRecordedSlotRange(Address start, Address end) {
PagedSpace* PagedSpaces::next() {
switch (counter_++) {
case RO_SPACE:
// skip NEW_SPACE
counter_++;
return heap_->read_only_space();
case NEW_SPACE:
UNREACHABLE();
case OLD_SPACE:
return heap_->old_space();
case CODE_SPACE:
......
......@@ -2245,8 +2245,8 @@ class VerifySmisVisitor : public RootVisitor {
};
// Space iterator for iterating over all the paged spaces of the heap: Map
// space, old space, code space and optionally read only space. Returns each
// space in turn, and null when it is done.
// space, old space and code space. Returns each space in turn, and null when it
// is done.
class V8_EXPORT_PRIVATE PagedSpaces {
public:
explicit PagedSpaces(Heap* heap) : heap_(heap), counter_(OLD_SPACE) {}
......@@ -2257,8 +2257,7 @@ class V8_EXPORT_PRIVATE PagedSpaces {
int counter_;
};
class SpaceIterator : public Malloced {
class V8_EXPORT_PRIVATE SpaceIterator : public Malloced {
public:
explicit SpaceIterator(Heap* heap);
virtual ~SpaceIterator();
......
......@@ -96,6 +96,24 @@ TEST(CombinedHeapIterator) {
CHECK(seen_sample_object);
}
TEST(PagedSpaces) {
Heap* const heap = CcTest::heap();
PagedSpaces iterator(heap);
CHECK_EQ(iterator.next(), reinterpret_cast<PagedSpace*>(heap->old_space()));
CHECK_EQ(iterator.next(), reinterpret_cast<PagedSpace*>(heap->code_space()));
CHECK_EQ(iterator.next(), reinterpret_cast<PagedSpace*>(heap->map_space()));
for (int i = 0; i < 20; i++) {
CHECK_NULL(iterator.next());
}
}
TEST(SpaceIterator) {
auto* const read_only_space = CcTest::read_only_heap()->read_only_space();
for (SpaceIterator it(CcTest::heap()); it.has_next();) {
CHECK_NE(it.next(), reinterpret_cast<Space*>(read_only_space));
}
}
} // namespace heap
} // namespace internal
} // namespace v8
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