// Start with the right edge
uintptr_t word = bitmap_begin_[index_start].load(std::memory_order_relaxed); // visit_begin could be the first word of the object we are looking for. const uintptr_t right_edge_mask = OffsetToMask(offset_start);
word &= right_edge_mask | (right_edge_mask - 1); while (index_start > index_end) { if (word != 0) { const uintptr_t ptr_base = IndexToOffset(index_start) + heap_begin_;
size_t pos_leading_set_bit = kBitsPerIntPtrT - CLZ(word) - 1; returnreinterpret_cast<mirror::Object*>(ptr_base + pos_leading_set_bit * kAlignment);
}
word = bitmap_begin_[--index_start].load(std::memory_order_relaxed);
}
// Index(begin) ... Index(end) // [xxxxx???][........][????yyyy] // ^ ^ // | #---- Bit of visit_end // #---- Bit of visit_begin //
// Left edge.
uintptr_t left_edge = bitmap_begin_[index_start]; // Mark of lower bits that are not in range.
left_edge &= ~((static_cast<uintptr_t>(1) << bit_start) - 1);
// Right edge. Either unique, or left_edge.
uintptr_t right_edge;
if (index_start < index_end) { // Left edge != right edge.
// Traverse left edge. if (left_edge != 0) { const uintptr_t ptr_base = IndexToOffset(index_start) + heap_begin_; do { const size_t shift = CTZ(left_edge);
mirror::Object* obj = reinterpret_cast<mirror::Object*>(ptr_base + shift * kAlignment);
visitor(obj); if (kVisitOnce) { return;
}
left_edge ^= (static_cast<uintptr_t>(1)) << shift;
} while (left_edge != 0);
}
// Traverse the middle, full part. for (size_t i = index_start + 1; i < index_end; ++i) {
uintptr_t w = bitmap_begin_[i].load(std::memory_order_relaxed); if (w != 0) { const uintptr_t ptr_base = IndexToOffset(i) + heap_begin_; // Iterate on the bits set in word `w`, from the least to the most significant bit. do { const size_t shift = CTZ(w);
mirror::Object* obj = reinterpret_cast<mirror::Object*>(ptr_base + shift * kAlignment);
visitor(obj); if (kVisitOnce) { return;
}
w ^= (static_cast<uintptr_t>(1)) << shift;
} while (w != 0);
}
}
// Right edge is unique. // But maybe we don't have anything to do: visit_end starts in a new word... if (bit_end == 0) { // Do not read memory, as it could be after the end of the bitmap.
right_edge = 0;
} else {
right_edge = bitmap_begin_[index_end];
}
} else { // Right edge = left edge.
right_edge = left_edge;
}
// Right edge handling.
right_edge &= ((static_cast<uintptr_t>(1) << bit_end) - 1); if (right_edge != 0) { const uintptr_t ptr_base = IndexToOffset(index_end) + heap_begin_; // Iterate on the bits set in word `right_edge`, from the least to the most significant bit. do { const size_t shift = CTZ(right_edge);
mirror::Object* obj = reinterpret_cast<mirror::Object*>(ptr_base + shift * kAlignment);
visitor(obj); if (kVisitOnce) { return;
}
right_edge ^= (static_cast<uintptr_t>(1)) << shift;
} while (right_edge != 0);
} #endif
}
uintptr_t end = OffsetToIndex(HeapLimit() - heap_begin_ - 1);
Atomic<uintptr_t>* bitmap_begin = bitmap_begin_; for (uintptr_t i = 0; i <= end; ++i) {
uintptr_t w = bitmap_begin[i].load(std::memory_order_relaxed); if (w != 0) {
uintptr_t ptr_base = IndexToOffset(i) + heap_begin_; do { const size_t shift = CTZ(w);
mirror::Object* obj = reinterpret_cast<mirror::Object*>(ptr_base + shift * kAlignment);
visitor(obj);
w ^= (static_cast<uintptr_t>(1)) << shift;
} while (w != 0);
}
}
}
template<size_t kAlignment> template<bool kSetBit> inlinebool SpaceBitmap<kAlignment>::Modify(const mirror::Object* obj) {
DCHECK(obj != nullptr);
uintptr_t addr = reinterpret_cast<uintptr_t>(obj);
DCHECK_GE(addr, heap_begin_);
DCHECK(HasAddress(obj)) << obj; const uintptr_t offset = addr - heap_begin_; const size_t index = OffsetToIndex(offset); const uintptr_t mask = OffsetToMask(offset);
DCHECK_LT(index, bitmap_size_ / sizeof(intptr_t)) << " bitmap_size_ = " << bitmap_size_;
Atomic<uintptr_t>* atomic_entry = &bitmap_begin_[index];
uintptr_t old_word = atomic_entry->load(std::memory_order_relaxed); if (kSetBit) { // Check the bit before setting the word incase we are trying to mark a read only bitmap // like an image space bitmap. This bitmap is mapped as read only and will fault if we // attempt to change any words. Since all of the objects are marked, this will never // occur if we check before setting the bit. This also prevents dirty pages that would // occur if the bitmap was read write and we did not check the bit. if ((old_word & mask) == 0) {
atomic_entry->store(old_word | mask, std::memory_order_relaxed);
}
} else {
atomic_entry->store(old_word & ~mask, std::memory_order_relaxed);
}
DCHECK_EQ(Test(obj), kSetBit); return (old_word & mask) != 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.