// TODO: Use this code to implement SpaceBitmap. class Bitmap { public: // Create and initialize a bitmap with size num_bits. Storage is allocated with a MemMap. static Bitmap* Create(const std::string& name, size_t num_bits);
// Initialize a space bitmap using the provided mem_map as the live bits. Takes ownership of the // mem map. The address range covered starts at heap_begin and is of size equal to heap_capacity. // Objects are kAlignement-aligned. static Bitmap* CreateFromMemMap(MemMap&& mem_map, size_t num_bits);
// offset is the difference from base to a index. static ALWAYS_INLINE constexpr size_t BitIndexToWordIndex(uintptr_t offset) { return offset / kBitsPerBitmapWord;
}
// Returns true if the bit_index was previously set.
ALWAYS_INLINE bool AtomicTestAndSetBit(size_t bit_index);
// Fill the bitmap with zeroes. Returns the bitmap's memory to the system as a side-effect. void Clear();
// Visit the all the set bits range [visit_begin, visit_end) where visit_begin and visit_end are // bit indices visitor is called with the index of each set bit. template <typename Visitor> void VisitSetBits(uintptr_t visit_begin, size_t visit_end, const Visitor& visitor) const;
// Size of our bitmap in bits.
size_t BitmapSize() const { return bitmap_numbits_; }
// Check that a bit index is valid with a DCHECK.
ALWAYS_INLINE void CheckValidBitIndex(size_t bit_index) const {
DCHECK_LT(bit_index, BitmapSize());
}
// Backing storage for bitmap. This is interpreted as an array of // kBitsPerBitmapWord-sized integers, with bits assigned in each word little // endian first.
MemMap mem_map_;
// This bitmap itself, word sized for efficiency in scanning.
uintptr_t* const bitmap_begin_;
// Number of bits in the bitmap.
size_t bitmap_numbits_;
// Beginning of the memory range that the bitmap covers.
ALWAYS_INLINE uintptr_t CoverBegin() const { return cover_begin_;
}
// End of the memory range that the bitmap covers.
ALWAYS_INLINE uintptr_t CoverEnd() const { return cover_begin_ + kAlignment * BitmapSize();
}
// Return the address associated with a bit index.
ALWAYS_INLINE uintptr_t AddrFromBitIndex(size_t bit_index) const { const uintptr_t addr = CoverBegin() + bit_index * kAlignment;
DCHECK_EQ(BitIndexFromAddr(addr), bit_index); return addr;
}
// Return the bit index associated with an address .
ALWAYS_INLINE uintptr_t BitIndexFromAddr(uintptr_t addr) const {
uintptr_t result = (addr - CoverBegin()) / kAlignment;
DCHECK(result < BitmapSize()) << CoverBegin() << " <= " << addr << " < " << CoverEnd(); return result;
}
ALWAYS_INLINE bool HasAddress(const uintptr_t addr) const { // Don't use BitIndexFromAddr() here as the addr passed to this function // could be outside the range. If addr < cover_begin_, then the result // underflows to some very large value past the end of the bitmap. // Therefore, all operations are unsigned here. bool ret = (addr - CoverBegin()) / kAlignment < BitmapSize(); if (ret) {
DCHECK(CoverBegin() <= addr && addr < CoverEnd())
<< CoverBegin() << " <= " << addr << " < " << CoverEnd();
} return ret;
}
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.