summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2024-03-22 10:47:58 +0000
committer Santiago Aboy Solanes <solanes@google.com> 2024-03-25 15:13:59 +0000
commitb71150621fd1357e4be1bf2644a3fd99e69bc933 (patch)
tree56245d40e59089c748fadab509d93ddf860c6fc5
parent00fbc4047bd6a1984c333b93fc39e73e61a2521a (diff)
Rename MallocAllocator to CallocAllocator
It was a misnomer since MallocAllocator was internally calling calloc. The difference is that calloc sets the memory to zero which malloc does not. Bug: 329037671 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: I77f44df2681b64a25e1d06773b2a2ed150748e00
-rw-r--r--compiler/optimizing/optimizing_unit_test.h2
-rw-r--r--dex2oat/linker/oat_writer.cc4
-rw-r--r--libartbase/base/allocator.cc13
-rw-r--r--libartbase/base/allocator.h2
-rw-r--r--libartbase/base/bit_vector.cc1
-rw-r--r--libartbase/base/bit_vector_test.cc38
6 files changed, 29 insertions, 31 deletions
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index 8729763e73..e1d8969b2b 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -340,7 +340,7 @@ class OptimizingUnitTestHelper {
void EnsurePredecessorOrder(HBasicBlock* target, std::initializer_list<HBasicBlock*> preds) {
// Make sure the given preds and block predecessors have the same blocks.
- BitVector bv(preds.size(), false, Allocator::GetMallocAllocator());
+ BitVector bv(preds.size(), false, Allocator::GetCallocAllocator());
auto preds_and_idx = ZipCount(MakeIterationRange(target->GetPredecessors()));
bool correct_preds = preds.size() == target->GetPredecessors().size() &&
std::all_of(preds.begin(), preds.end(), [&](HBasicBlock* pred) {
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index af4b69163e..8a296e83c7 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -779,7 +779,7 @@ class OatWriter::InitBssLayoutMethodVisitor : public DexMethodVisitor {
if (refs_it == references->end()) {
refs_it = references->Put(
ref.dex_file,
- BitVector(number_of_indexes, /* expandable */ false, Allocator::GetMallocAllocator()));
+ BitVector(number_of_indexes, /* expandable */ false, Allocator::GetCallocAllocator()));
}
refs_it->second.SetBit(ref.index);
}
@@ -4054,7 +4054,7 @@ OatWriter::OatClass::OatClass(const dchecked_vector<CompiledMethod*>& compiled_m
num_methods_ = num_methods;
oat_method_offsets_offset_from_oat_class += sizeof(num_methods_);
if (oat_class_type == enum_cast<uint16_t>(OatClassType::kSomeCompiled)) {
- method_bitmap_.reset(new BitVector(num_methods, false, Allocator::GetMallocAllocator()));
+ method_bitmap_.reset(new BitVector(num_methods, false, Allocator::GetCallocAllocator()));
uint32_t bitmap_size = BitVector::BitsToWords(num_methods) * BitVector::kWordBytes;
DCHECK_EQ(bitmap_size, method_bitmap_->GetSizeOf());
oat_method_offsets_offset_from_oat_class += bitmap_size;
diff --git a/libartbase/base/allocator.cc b/libartbase/base/allocator.cc
index b65ba16eb2..ef073a1fa2 100644
--- a/libartbase/base/allocator.cc
+++ b/libartbase/base/allocator.cc
@@ -25,11 +25,10 @@
namespace art {
-// Note that this class is a misnomer as it calls `calloc` which sets the memory to zero.
-class MallocAllocator final : public Allocator {
+class CallocAllocator final : public Allocator {
public:
- MallocAllocator() {}
- ~MallocAllocator() {}
+ CallocAllocator() {}
+ ~CallocAllocator() {}
void* Alloc(size_t size) override {
return calloc(sizeof(uint8_t), size);
@@ -40,10 +39,10 @@ class MallocAllocator final : public Allocator {
}
private:
- DISALLOW_COPY_AND_ASSIGN(MallocAllocator);
+ DISALLOW_COPY_AND_ASSIGN(CallocAllocator);
};
-MallocAllocator g_malloc_allocator;
+CallocAllocator g_malloc_allocator;
class NoopAllocator final : public Allocator {
public:
@@ -65,7 +64,7 @@ class NoopAllocator final : public Allocator {
NoopAllocator g_noop_allocator;
-Allocator* Allocator::GetMallocAllocator() {
+Allocator* Allocator::GetCallocAllocator() {
return &g_malloc_allocator;
}
diff --git a/libartbase/base/allocator.h b/libartbase/base/allocator.h
index 24374a2b40..c3f32282e8 100644
--- a/libartbase/base/allocator.h
+++ b/libartbase/base/allocator.h
@@ -28,7 +28,7 @@ static constexpr bool kEnableTrackingAllocator = false;
class Allocator {
public:
- static Allocator* GetMallocAllocator();
+ static Allocator* GetCallocAllocator();
static Allocator* GetNoopAllocator();
Allocator() {}
diff --git a/libartbase/base/bit_vector.cc b/libartbase/base/bit_vector.cc
index 85f326385e..5b022b11c2 100644
--- a/libartbase/base/bit_vector.cc
+++ b/libartbase/base/bit_vector.cc
@@ -51,7 +51,6 @@ BitVector::BitVector(uint32_t start_bits,
// * `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)).
- // As a note, MallocAllocator is a misnomer as it uses `calloc` which sets the memory to zero.
ClearAllBits();
}
diff --git a/libartbase/base/bit_vector_test.cc b/libartbase/base/bit_vector_test.cc
index 6f65815723..ddd42f94f1 100644
--- a/libartbase/base/bit_vector_test.cc
+++ b/libartbase/base/bit_vector_test.cc
@@ -28,7 +28,7 @@ namespace art {
TEST(BitVector, Test) {
const size_t kBits = 32;
- BitVector bv(kBits, false, Allocator::GetMallocAllocator());
+ BitVector bv(kBits, false, Allocator::GetCallocAllocator());
EXPECT_EQ(1U, bv.GetStorageSize());
EXPECT_EQ(sizeof(uint32_t), bv.GetSizeOf());
EXPECT_FALSE(bv.IsExpandable());
@@ -70,7 +70,7 @@ TEST(BitVector, Test) {
struct MessyAllocator : public Allocator {
public:
- MessyAllocator() : malloc_(Allocator::GetMallocAllocator()) {}
+ MessyAllocator() : malloc_(Allocator::GetCallocAllocator()) {}
~MessyAllocator() {}
void* Alloc(size_t s) override {
@@ -172,9 +172,9 @@ TEST(BitVector, SetInitialBits) {
TEST(BitVector, UnionIfNotIn) {
{
- BitVector first(2, true, Allocator::GetMallocAllocator());
- BitVector second(5, true, Allocator::GetMallocAllocator());
- BitVector third(5, true, Allocator::GetMallocAllocator());
+ BitVector first(2, true, Allocator::GetCallocAllocator());
+ BitVector second(5, true, Allocator::GetCallocAllocator());
+ BitVector third(5, true, Allocator::GetCallocAllocator());
second.SetBit(64);
third.SetBit(64);
@@ -184,9 +184,9 @@ TEST(BitVector, UnionIfNotIn) {
}
{
- BitVector first(2, true, Allocator::GetMallocAllocator());
- BitVector second(5, true, Allocator::GetMallocAllocator());
- BitVector third(5, true, Allocator::GetMallocAllocator());
+ BitVector first(2, true, Allocator::GetCallocAllocator());
+ BitVector second(5, true, Allocator::GetCallocAllocator());
+ BitVector third(5, true, Allocator::GetCallocAllocator());
second.SetBit(64);
bool changed = first.UnionIfNotIn(&second, &third);
@@ -198,8 +198,8 @@ TEST(BitVector, UnionIfNotIn) {
TEST(BitVector, Subset) {
{
- BitVector first(2, true, Allocator::GetMallocAllocator());
- BitVector second(5, true, Allocator::GetMallocAllocator());
+ BitVector first(2, true, Allocator::GetCallocAllocator());
+ BitVector second(5, true, Allocator::GetCallocAllocator());
EXPECT_TRUE(first.IsSubsetOf(&second));
second.SetBit(4);
@@ -207,8 +207,8 @@ TEST(BitVector, Subset) {
}
{
- BitVector first(5, true, Allocator::GetMallocAllocator());
- BitVector second(5, true, Allocator::GetMallocAllocator());
+ BitVector first(5, true, Allocator::GetCallocAllocator());
+ BitVector second(5, true, Allocator::GetCallocAllocator());
first.SetBit(5);
EXPECT_FALSE(first.IsSubsetOf(&second));
@@ -217,8 +217,8 @@ TEST(BitVector, Subset) {
}
{
- BitVector first(5, true, Allocator::GetMallocAllocator());
- BitVector second(5, true, Allocator::GetMallocAllocator());
+ BitVector first(5, true, Allocator::GetCallocAllocator());
+ BitVector second(5, true, Allocator::GetCallocAllocator());
first.SetBit(16);
first.SetBit(32);
@@ -243,7 +243,7 @@ TEST(BitVector, Subset) {
TEST(BitVector, CopyTo) {
{
// Test copying an empty BitVector. Padding should fill `buf` with zeroes.
- BitVector bv(0, true, Allocator::GetMallocAllocator());
+ BitVector bv(0, true, Allocator::GetCallocAllocator());
uint32_t buf;
bv.CopyTo(&buf, sizeof(buf));
@@ -253,7 +253,7 @@ TEST(BitVector, CopyTo) {
{
// Test copying when `bv.storage_` and `buf` are of equal lengths.
- BitVector bv(0, true, Allocator::GetMallocAllocator());
+ BitVector bv(0, true, Allocator::GetCallocAllocator());
uint32_t buf;
bv.SetBit(0);
@@ -268,7 +268,7 @@ TEST(BitVector, CopyTo) {
{
// Test copying when the `bv.storage_` is longer than `buf`. As long as
// `buf` is long enough to hold all set bits, copying should succeed.
- BitVector bv(0, true, Allocator::GetMallocAllocator());
+ BitVector bv(0, true, Allocator::GetCallocAllocator());
uint8_t buf[5];
bv.SetBit(18);
@@ -285,7 +285,7 @@ TEST(BitVector, CopyTo) {
{
// Test zero padding when `bv.storage_` is shorter than `buf`.
- BitVector bv(0, true, Allocator::GetMallocAllocator());
+ BitVector bv(0, true, Allocator::GetCallocAllocator());
uint32_t buf[2];
bv.SetBit(18);
@@ -299,7 +299,7 @@ TEST(BitVector, CopyTo) {
}
TEST(BitVector, TransformIterator) {
- BitVector bv(16, false, Allocator::GetMallocAllocator());
+ BitVector bv(16, false, Allocator::GetCallocAllocator());
bv.SetBit(4);
bv.SetBit(8);