Reland "Update non-moving space references in reverse"
This reverts commit da91abf4ec6686fce3e17668743ee8f85191e1f3.
Reason for revert: Use signed integer for iterator
Bug: 160737021
Bug: 259643149
Test: art/test/testrunnner/testrunner.py
Change-Id: If11aec8b9734dbee7b2df4030c5fc48e53c80898
(cherry picked from commit 0a7542947329ffbb51ac5f2a25686cef35bce0ea)
Merged-In: If11aec8b9734dbee7b2df4030c5fc48e53c80898
diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc
index bde15e5..cf32252 100644
--- a/runtime/gc/collector/mark_compact.cc
+++ b/runtime/gc/collector/mark_compact.cc
@@ -1891,14 +1891,20 @@
void MarkCompact::UpdateNonMovingSpace() {
TimingLogger::ScopedTiming t(__FUNCTION__, GetTimings());
- uint8_t* page = non_moving_space_->Begin();
- for (size_t i = 0; i < non_moving_first_objs_count_; i++) {
+ // Iterating in reverse ensures that the class pointer in objects which span
+ // across more than one page gets updated in the end. This is necessary for
+ // VisitRefsForCompaction() to work correctly.
+ // TODO: If and when we make non-moving space update concurrent, implement a
+ // mechanism to remember class pointers for such objects off-heap and pass it
+ // to VisitRefsForCompaction().
+ uint8_t* page = non_moving_space_->Begin() + non_moving_first_objs_count_ * kPageSize;
+ for (ssize_t i = non_moving_first_objs_count_ - 1; i >= 0; i--) {
mirror::Object* obj = first_objs_non_moving_space_[i].AsMirrorPtr();
+ page -= kPageSize;
// null means there are no objects on the page to update references.
if (obj != nullptr) {
UpdateNonMovingPage(obj, page);
}
- page += kPageSize;
}
}