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) { ...@@ -5340,9 +5340,8 @@ void Heap::ClearRecordedSlotRange(Address start, Address end) {
PagedSpace* PagedSpaces::next() { PagedSpace* PagedSpaces::next() {
switch (counter_++) { switch (counter_++) {
case RO_SPACE: case RO_SPACE:
// skip NEW_SPACE case NEW_SPACE:
counter_++; UNREACHABLE();
return heap_->read_only_space();
case OLD_SPACE: case OLD_SPACE:
return heap_->old_space(); return heap_->old_space();
case CODE_SPACE: case CODE_SPACE:
......
...@@ -2245,8 +2245,8 @@ class VerifySmisVisitor : public RootVisitor { ...@@ -2245,8 +2245,8 @@ class VerifySmisVisitor : public RootVisitor {
}; };
// Space iterator for iterating over all the paged spaces of the heap: Map // 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, old space and code space. Returns each space in turn, and null when it
// space in turn, and null when it is done. // is done.
class V8_EXPORT_PRIVATE PagedSpaces { class V8_EXPORT_PRIVATE PagedSpaces {
public: public:
explicit PagedSpaces(Heap* heap) : heap_(heap), counter_(OLD_SPACE) {} explicit PagedSpaces(Heap* heap) : heap_(heap), counter_(OLD_SPACE) {}
...@@ -2257,8 +2257,7 @@ class V8_EXPORT_PRIVATE PagedSpaces { ...@@ -2257,8 +2257,7 @@ class V8_EXPORT_PRIVATE PagedSpaces {
int counter_; int counter_;
}; };
class V8_EXPORT_PRIVATE SpaceIterator : public Malloced {
class SpaceIterator : public Malloced {
public: public:
explicit SpaceIterator(Heap* heap); explicit SpaceIterator(Heap* heap);
virtual ~SpaceIterator(); virtual ~SpaceIterator();
......
...@@ -96,6 +96,24 @@ TEST(CombinedHeapIterator) { ...@@ -96,6 +96,24 @@ TEST(CombinedHeapIterator) {
CHECK(seen_sample_object); 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 heap
} // namespace internal } // namespace internal
} // namespace v8 } // 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