diff options
author | 2024-03-22 14:03:46 +0000 | |
---|---|---|
committer | 2024-03-25 15:16:22 +0000 | |
commit | 5f80711ebc1510811b4f3aa6c748106a26b78d29 (patch) | |
tree | b0b811c0231653c4b6fd4c49220e5fb9ba74dca3 | |
parent | b71150621fd1357e4be1bf2644a3fd99e69bc933 (diff) |
Move responsibility of clearing BitVectors to the allocators/callers
Both CallocAllocator and ArenaAllocator already zero the bit vector
so we don't have to do it again. ScopedArenaAllocator was the only
one which needed the ClearAllBits call so move the call to that
constructor.
Bug: 329037671
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Change-Id: Iff1c1386f573bfd51a7e906696a173f6d4b30fc7
-rw-r--r-- | libartbase/base/arena_bit_vector.cc | 3 | ||||
-rw-r--r-- | libartbase/base/bit_vector.cc | 20 | ||||
-rw-r--r-- | libartbase/base/bit_vector.h | 7 | ||||
-rw-r--r-- | libartbase/base/bit_vector_test.cc | 1 |
4 files changed, 12 insertions, 19 deletions
diff --git a/libartbase/base/arena_bit_vector.cc b/libartbase/base/arena_bit_vector.cc index a532466d3c..aeeb57bfb8 100644 --- a/libartbase/base/arena_bit_vector.cc +++ b/libartbase/base/arena_bit_vector.cc @@ -18,6 +18,7 @@ #include "allocator.h" #include "arena_allocator.h" +#include "bit_vector-inl.h" namespace art { @@ -94,7 +95,7 @@ ArenaBitVector::ArenaBitVector(ScopedArenaAllocator* allocator, : BitVector(start_bits, expandable, ArenaBitVectorAllocator<ScopedArenaAllocator>::Create(allocator, kind)) { - DCHECK_EQ(GetHighestBitSet(), -1) << "The arena bit vector should start empty"; + ClearAllBits(); } } // namespace art diff --git a/libartbase/base/bit_vector.cc b/libartbase/base/bit_vector.cc index 5b022b11c2..68d6c10222 100644 --- a/libartbase/base/bit_vector.cc +++ b/libartbase/base/bit_vector.cc @@ -38,21 +38,11 @@ BitVector::BitVector(bool expandable, static_assert(sizeof(*storage_) * 8u == kWordBits, "word bits"); } -BitVector::BitVector(uint32_t start_bits, - bool expandable, - Allocator* allocator) - : BitVector(expandable, - allocator, - BitsToWords(start_bits), - static_cast<uint32_t*>(allocator->Alloc(BitsToWords(start_bits) * kWordBytes))) { - // We don't know if the allocator cleared things. - // TODO(solanes): We should be able to remove this call to `ClearAllBits`. Currently we have: - // * `MallocAllocator` and `ArenaAllocator` which sets it to zero, and - // * `ScopedArenaAllocator` which does not. - // We also have `NoopAllocator` but that allocator should never call this method (as the Alloc - // call will turn into a LOG(FATAL)). - ClearAllBits(); -} +BitVector::BitVector(uint32_t start_bits, bool expandable, Allocator* allocator) + : BitVector(expandable, + allocator, + BitsToWords(start_bits), + static_cast<uint32_t*>(allocator->Alloc(BitsToWords(start_bits) * kWordBytes))) {} BitVector::BitVector(const BitVector& src, bool expandable, diff --git a/libartbase/base/bit_vector.h b/libartbase/base/bit_vector.h index a605529a81..ec94efb09f 100644 --- a/libartbase/base/bit_vector.h +++ b/libartbase/base/bit_vector.h @@ -30,8 +30,10 @@ class Allocator; class ArenaBitVector; /* - * Expanding bitmap, used for tracking resources. Bits are numbered starting - * from zero. All operations on a BitVector are unsynchronized. + * Expanding bitmap. Bits are numbered starting from zero. All operations on a BitVector are + * unsynchronized. New BitVectors are not necessarily zeroed out. If the used allocator doesn't do + * clear the vector (e.g. ScopedArenaAllocator), the responsibility of clearing it relies on the + * caller (e.g. ArenaBitVector). */ class BitVector { public: @@ -123,7 +125,6 @@ class BitVector { other.storage_size_ = 0u; } - // Guarantees the BitVector starts empty. BitVector(uint32_t start_bits, bool expandable, Allocator* allocator); diff --git a/libartbase/base/bit_vector_test.cc b/libartbase/base/bit_vector_test.cc index ddd42f94f1..244cff1cb4 100644 --- a/libartbase/base/bit_vector_test.cc +++ b/libartbase/base/bit_vector_test.cc @@ -90,6 +90,7 @@ struct MessyAllocator : public Allocator { TEST(BitVector, MessyAllocator) { MessyAllocator alloc; BitVector bv(32, false, &alloc); + bv.ClearAllBits(); EXPECT_EQ(bv.NumSetBits(), 0u); EXPECT_EQ(bv.GetHighestBitSet(), -1); } |