Don't assume allocators clear memory

BitVector, when constructed with an explicit size, would assume that
the allocator would zero out memory. This is not always true and could
lead to unexpected outcomes.

Test: ./test.py --host
Change-Id: Ibe556ebf07b5081f110e76efa927b7fa677a607e
diff --git a/libartbase/base/bit_vector.cc b/libartbase/base/bit_vector.cc
index 2ef14d7..b32b411 100644
--- a/libartbase/base/bit_vector.cc
+++ b/libartbase/base/bit_vector.cc
@@ -45,9 +45,10 @@
               allocator,
               BitsToWords(start_bits),
               static_cast<uint32_t*>(allocator->Alloc(BitsToWords(start_bits) * kWordBytes))) {
+  // We don't know if the allocator cleared things.
+  ClearAllBits();
 }
 
-
 BitVector::BitVector(const BitVector& src,
                      bool expandable,
                      Allocator* allocator)
diff --git a/libartbase/base/bit_vector_test.cc b/libartbase/base/bit_vector_test.cc
index e5ba7b4..bdba22a 100644
--- a/libartbase/base/bit_vector_test.cc
+++ b/libartbase/base/bit_vector_test.cc
@@ -66,6 +66,32 @@
   EXPECT_TRUE(iterator == bv.Indexes().end());
 }
 
+struct MessyAllocator : public Allocator {
+ public:
+  MessyAllocator() : malloc_(Allocator::GetMallocAllocator()) {}
+  ~MessyAllocator() {}
+
+  void* Alloc(size_t s) override {
+    void* res = malloc_->Alloc(s);
+    memset(res, 0xfe, s);
+    return res;
+  }
+
+  void Free(void* v) override {
+    malloc_->Free(v);
+  }
+
+ private:
+  Allocator* malloc_;
+};
+
+TEST(BitVector, MessyAllocator) {
+  MessyAllocator alloc;
+  BitVector bv(32, false, &alloc);
+  EXPECT_EQ(bv.NumSetBits(), 0u);
+  EXPECT_EQ(bv.GetHighestBitSet(), -1);
+}
+
 TEST(BitVector, NoopAllocator) {
   const uint32_t kWords = 2;