| Index: base/allocator/partition_allocator/partition_alloc_unittest.cc
|
| diff --git a/base/allocator/partition_allocator/partition_alloc_unittest.cc b/base/allocator/partition_allocator/partition_alloc_unittest.cc
|
| index b404ab752ea04a60045d1e9cd5e30d66e39a819d..dd1136f27afecacef92386523bba6a271d70e122 100644
|
| --- a/base/allocator/partition_allocator/partition_alloc_unittest.cc
|
| +++ b/base/allocator/partition_allocator/partition_alloc_unittest.cc
|
| @@ -40,7 +40,7 @@ namespace {
|
|
|
| const size_t kTestMaxAllocation = 4096;
|
| SizeSpecificPartitionAllocator<kTestMaxAllocation> allocator;
|
| -PartitionAllocatorGeneric genericAllocator;
|
| +PartitionAllocatorGeneric generic_allocator;
|
|
|
| const size_t kTestAllocSize = 16;
|
| #if !DCHECK_IS_ON()
|
| @@ -53,18 +53,18 @@ const size_t kExtraAllocSize = kCookieSize * 2;
|
| const size_t kRealAllocSize = kTestAllocSize + kExtraAllocSize;
|
| const size_t kTestBucketIndex = kRealAllocSize >> kBucketShift;
|
|
|
| -const char* typeName = nullptr;
|
| +const char* type_name = nullptr;
|
|
|
| void TestSetup() {
|
| allocator.init();
|
| - genericAllocator.init();
|
| + generic_allocator.init();
|
| }
|
|
|
| void TestShutdown() {
|
| // We expect no leaks in the general case. We have a test for leak
|
| // detection.
|
| EXPECT_TRUE(allocator.shutdown());
|
| - EXPECT_TRUE(genericAllocator.shutdown());
|
| + EXPECT_TRUE(generic_allocator.shutdown());
|
| }
|
|
|
| #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX)
|
| @@ -111,72 +111,73 @@ bool ClearAddressSpaceLimit() {
|
| #endif
|
|
|
| PartitionPage* GetFullPage(size_t size) {
|
| - size_t realSize = size + kExtraAllocSize;
|
| - size_t bucketIdx = realSize >> kBucketShift;
|
| - PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx];
|
| - size_t numSlots =
|
| - (bucket->numSystemPagesPerSlotSpan * kSystemPageSize) / realSize;
|
| + size_t real_size = size + kExtraAllocSize;
|
| + size_t bucket_index = real_size >> kBucketShift;
|
| + PartitionBucket* bucket = &allocator.root()->buckets()[bucket_index];
|
| + size_t num_slots =
|
| + (bucket->num_system_pages_per_slot_span * kSystemPageSize) / real_size;
|
| void* first = 0;
|
| void* last = 0;
|
| size_t i;
|
| - for (i = 0; i < numSlots; ++i) {
|
| - void* ptr = partitionAlloc(allocator.root(), size, typeName);
|
| + for (i = 0; i < num_slots; ++i) {
|
| + void* ptr = PartitionAlloc(allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| if (!i)
|
| - first = partitionCookieFreePointerAdjust(ptr);
|
| - else if (i == numSlots - 1)
|
| - last = partitionCookieFreePointerAdjust(ptr);
|
| + first = PartitionCookieFreePointerAdjust(ptr);
|
| + else if (i == num_slots - 1)
|
| + last = PartitionCookieFreePointerAdjust(ptr);
|
| }
|
| - EXPECT_EQ(partitionPointerToPage(first), partitionPointerToPage(last));
|
| - if (bucket->numSystemPagesPerSlotSpan == kNumSystemPagesPerPartitionPage)
|
| + EXPECT_EQ(PartitionPointerToPage(first), PartitionPointerToPage(last));
|
| + if (bucket->num_system_pages_per_slot_span == kNumSystemPagesPerPartitionPage)
|
| EXPECT_EQ(reinterpret_cast<size_t>(first) & kPartitionPageBaseMask,
|
| reinterpret_cast<size_t>(last) & kPartitionPageBaseMask);
|
| - EXPECT_EQ(numSlots,
|
| - static_cast<size_t>(bucket->activePagesHead->numAllocatedSlots));
|
| - EXPECT_EQ(0, bucket->activePagesHead->freelistHead);
|
| - EXPECT_TRUE(bucket->activePagesHead);
|
| - EXPECT_TRUE(bucket->activePagesHead != &PartitionRootGeneric::gSeedPage);
|
| - return bucket->activePagesHead;
|
| + EXPECT_EQ(num_slots, static_cast<size_t>(
|
| + bucket->active_pages_head->num_allocated_slots));
|
| + EXPECT_EQ(0, bucket->active_pages_head->freelist_head);
|
| + EXPECT_TRUE(bucket->active_pages_head);
|
| + EXPECT_TRUE(bucket->active_pages_head != &PartitionRootGeneric::gSeedPage);
|
| + return bucket->active_pages_head;
|
| }
|
|
|
| void FreeFullPage(PartitionPage* page) {
|
| - size_t size = page->bucket->slotSize;
|
| - size_t numSlots =
|
| - (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) / size;
|
| - EXPECT_EQ(numSlots, static_cast<size_t>(abs(page->numAllocatedSlots)));
|
| - char* ptr = reinterpret_cast<char*>(partitionPageToPointer(page));
|
| + size_t size = page->bucket->slot_size;
|
| + size_t num_slots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) / size;
|
| + EXPECT_EQ(num_slots, static_cast<size_t>(abs(page->num_allocated_slots)));
|
| + char* ptr = reinterpret_cast<char*>(PartitionPageToPointer(page));
|
| size_t i;
|
| - for (i = 0; i < numSlots; ++i) {
|
| - partitionFree(ptr + kPointerOffset);
|
| + for (i = 0; i < num_slots; ++i) {
|
| + PartitionFree(ptr + kPointerOffset);
|
| ptr += size;
|
| }
|
| }
|
|
|
| void CycleFreeCache(size_t size) {
|
| - size_t realSize = size + kExtraAllocSize;
|
| - size_t bucketIdx = realSize >> kBucketShift;
|
| - PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx];
|
| - DCHECK(!bucket->activePagesHead->numAllocatedSlots);
|
| + size_t real_size = size + kExtraAllocSize;
|
| + size_t bucket_index = real_size >> kBucketShift;
|
| + PartitionBucket* bucket = &allocator.root()->buckets()[bucket_index];
|
| + DCHECK(!bucket->active_pages_head->num_allocated_slots);
|
|
|
| for (size_t i = 0; i < kMaxFreeableSpans; ++i) {
|
| - void* ptr = partitionAlloc(allocator.root(), size, typeName);
|
| - EXPECT_EQ(1, bucket->activePagesHead->numAllocatedSlots);
|
| - partitionFree(ptr);
|
| - EXPECT_EQ(0, bucket->activePagesHead->numAllocatedSlots);
|
| - EXPECT_NE(-1, bucket->activePagesHead->emptyCacheIndex);
|
| + void* ptr = PartitionAlloc(allocator.root(), size, type_name);
|
| + EXPECT_EQ(1, bucket->active_pages_head->num_allocated_slots);
|
| + PartitionFree(ptr);
|
| + EXPECT_EQ(0, bucket->active_pages_head->num_allocated_slots);
|
| + EXPECT_NE(-1, bucket->active_pages_head->empty_cache_index);
|
| }
|
| }
|
|
|
| void CycleGenericFreeCache(size_t size) {
|
| for (size_t i = 0; i < kMaxFreeableSpans; ++i) {
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr =
|
| + PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| PartitionBucket* bucket = page->bucket;
|
| - EXPECT_EQ(1, bucket->activePagesHead->numAllocatedSlots);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - EXPECT_EQ(0, bucket->activePagesHead->numAllocatedSlots);
|
| - EXPECT_NE(-1, bucket->activePagesHead->emptyCacheIndex);
|
| + EXPECT_EQ(1, bucket->active_pages_head->num_allocated_slots);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + EXPECT_EQ(0, bucket->active_pages_head->num_allocated_slots);
|
| + EXPECT_NE(-1, bucket->active_pages_head->empty_cache_index);
|
| }
|
| }
|
|
|
| @@ -195,52 +196,52 @@ bool IsLargeMemoryDevice() {
|
| class MockPartitionStatsDumper : public PartitionStatsDumper {
|
| public:
|
| MockPartitionStatsDumper()
|
| - : m_totalResidentBytes(0),
|
| - m_totalActiveBytes(0),
|
| - m_totalDecommittableBytes(0),
|
| - m_totalDiscardableBytes(0) {}
|
| -
|
| - void partitionDumpTotals(const char* partitionName,
|
| - const PartitionMemoryStats* memoryStats) override {
|
| - EXPECT_GE(memoryStats->totalMmappedBytes, memoryStats->totalResidentBytes);
|
| - EXPECT_EQ(m_totalResidentBytes, memoryStats->totalResidentBytes);
|
| - EXPECT_EQ(m_totalActiveBytes, memoryStats->totalActiveBytes);
|
| - EXPECT_EQ(m_totalDecommittableBytes, memoryStats->totalDecommittableBytes);
|
| - EXPECT_EQ(m_totalDiscardableBytes, memoryStats->totalDiscardableBytes);
|
| + : total_resident_bytes(0),
|
| + total_active_bytes(0),
|
| + total_decommittable_bytes(0),
|
| + total_discardable_bytes(0) {}
|
| +
|
| + void PartitionDumpTotals(const char* partition_name,
|
| + const PartitionMemoryStats* stats) override {
|
| + EXPECT_GE(stats->total_mmapped_bytes, stats->total_resident_bytes);
|
| + EXPECT_EQ(total_resident_bytes, stats->total_resident_bytes);
|
| + EXPECT_EQ(total_active_bytes, stats->total_active_bytes);
|
| + EXPECT_EQ(total_decommittable_bytes, stats->total_decommittable_bytes);
|
| + EXPECT_EQ(total_discardable_bytes, stats->total_discardable_bytes);
|
| }
|
|
|
| - void partitionsDumpBucketStats(
|
| - const char* partitionName,
|
| - const PartitionBucketMemoryStats* memoryStats) override {
|
| - (void)partitionName;
|
| - EXPECT_TRUE(memoryStats->isValid);
|
| - EXPECT_EQ(0u, memoryStats->bucketSlotSize & kAllocationGranularityMask);
|
| - m_bucketStats.push_back(*memoryStats);
|
| - m_totalResidentBytes += memoryStats->residentBytes;
|
| - m_totalActiveBytes += memoryStats->activeBytes;
|
| - m_totalDecommittableBytes += memoryStats->decommittableBytes;
|
| - m_totalDiscardableBytes += memoryStats->discardableBytes;
|
| + void PartitionsDumpBucketStats(
|
| + const char* partition_name,
|
| + const PartitionBucketMemoryStats* stats) override {
|
| + (void)partition_name;
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->bucket_slot_size & kAllocationGranularityMask);
|
| + bucket_stats.push_back(*stats);
|
| + total_resident_bytes += stats->resident_bytes;
|
| + total_active_bytes += stats->active_bytes;
|
| + total_decommittable_bytes += stats->decommittable_bytes;
|
| + total_discardable_bytes += stats->discardable_bytes;
|
| }
|
|
|
| bool IsMemoryAllocationRecorded() {
|
| - return m_totalResidentBytes != 0 && m_totalActiveBytes != 0;
|
| + return total_resident_bytes != 0 && total_active_bytes != 0;
|
| }
|
|
|
| - const PartitionBucketMemoryStats* GetBucketStats(size_t bucketSize) {
|
| - for (size_t i = 0; i < m_bucketStats.size(); ++i) {
|
| - if (m_bucketStats[i].bucketSlotSize == bucketSize)
|
| - return &m_bucketStats[i];
|
| + const PartitionBucketMemoryStats* GetBucketStats(size_t bucket_size) {
|
| + for (size_t i = 0; i < bucket_stats.size(); ++i) {
|
| + if (bucket_stats[i].bucket_slot_size == bucket_size)
|
| + return &bucket_stats[i];
|
| }
|
| return 0;
|
| }
|
|
|
| private:
|
| - size_t m_totalResidentBytes;
|
| - size_t m_totalActiveBytes;
|
| - size_t m_totalDecommittableBytes;
|
| - size_t m_totalDiscardableBytes;
|
| + size_t total_resident_bytes;
|
| + size_t total_active_bytes;
|
| + size_t total_decommittable_bytes;
|
| + size_t total_discardable_bytes;
|
|
|
| - std::vector<PartitionBucketMemoryStats> m_bucketStats;
|
| + std::vector<PartitionBucketMemoryStats> bucket_stats;
|
| };
|
|
|
| } // anonymous namespace
|
| @@ -251,12 +252,12 @@ TEST(PartitionAllocTest, Basic) {
|
| PartitionBucket* bucket = &allocator.root()->buckets()[kTestBucketIndex];
|
| PartitionPage* seedPage = &PartitionRootGeneric::gSeedPage;
|
|
|
| - EXPECT_FALSE(bucket->emptyPagesHead);
|
| - EXPECT_FALSE(bucket->decommittedPagesHead);
|
| - EXPECT_EQ(seedPage, bucket->activePagesHead);
|
| - EXPECT_EQ(0, bucket->activePagesHead->nextPage);
|
| + EXPECT_FALSE(bucket->empty_pages_head);
|
| + EXPECT_FALSE(bucket->decommitted_pages_head);
|
| + EXPECT_EQ(seedPage, bucket->active_pages_head);
|
| + EXPECT_EQ(0, bucket->active_pages_head->next_page);
|
|
|
| - void* ptr = partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| + void* ptr = PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| EXPECT_EQ(kPointerOffset,
|
| reinterpret_cast<size_t>(ptr) & kPartitionPageOffsetMask);
|
| @@ -264,11 +265,11 @@ TEST(PartitionAllocTest, Basic) {
|
| EXPECT_EQ(kPartitionPageSize + kPointerOffset,
|
| reinterpret_cast<size_t>(ptr) & kSuperPageOffsetMask);
|
|
|
| - partitionFree(ptr);
|
| + PartitionFree(ptr);
|
| // Expect that the last active page gets noticed as empty but doesn't get
|
| // decommitted.
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_FALSE(bucket->decommittedPagesHead);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_FALSE(bucket->decommitted_pages_head);
|
|
|
| TestShutdown();
|
| }
|
| @@ -276,13 +277,13 @@ TEST(PartitionAllocTest, Basic) {
|
| // Check that we can detect a memory leak.
|
| TEST(PartitionAllocTest, SimpleLeak) {
|
| TestSetup();
|
| - void* leakedPtr = partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| + void* leakedPtr = PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| (void)leakedPtr;
|
| - void* leakedPtr2 =
|
| - partitionAllocGeneric(genericAllocator.root(), kTestAllocSize, typeName);
|
| + void* leakedPtr2 = PartitionAllocGeneric(generic_allocator.root(),
|
| + kTestAllocSize, type_name);
|
| (void)leakedPtr2;
|
| EXPECT_FALSE(allocator.shutdown());
|
| - EXPECT_FALSE(genericAllocator.shutdown());
|
| + EXPECT_FALSE(generic_allocator.shutdown());
|
| }
|
|
|
| // Test multiple allocations, and freelist handling.
|
| @@ -290,37 +291,37 @@ TEST(PartitionAllocTest, MultiAlloc) {
|
| TestSetup();
|
|
|
| char* ptr1 = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| char* ptr2 = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_TRUE(ptr1);
|
| EXPECT_TRUE(ptr2);
|
| ptrdiff_t diff = ptr2 - ptr1;
|
| EXPECT_EQ(static_cast<ptrdiff_t>(kRealAllocSize), diff);
|
|
|
| // Check that we re-use the just-freed slot.
|
| - partitionFree(ptr2);
|
| + PartitionFree(ptr2);
|
| ptr2 = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_TRUE(ptr2);
|
| diff = ptr2 - ptr1;
|
| EXPECT_EQ(static_cast<ptrdiff_t>(kRealAllocSize), diff);
|
| - partitionFree(ptr1);
|
| + PartitionFree(ptr1);
|
| ptr1 = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_TRUE(ptr1);
|
| diff = ptr2 - ptr1;
|
| EXPECT_EQ(static_cast<ptrdiff_t>(kRealAllocSize), diff);
|
|
|
| char* ptr3 = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_TRUE(ptr3);
|
| diff = ptr3 - ptr1;
|
| EXPECT_EQ(static_cast<ptrdiff_t>(kRealAllocSize * 2), diff);
|
|
|
| - partitionFree(ptr1);
|
| - partitionFree(ptr2);
|
| - partitionFree(ptr3);
|
| + PartitionFree(ptr1);
|
| + PartitionFree(ptr2);
|
| + PartitionFree(ptr3);
|
|
|
| TestShutdown();
|
| }
|
| @@ -332,39 +333,39 @@ TEST(PartitionAllocTest, MultiPages) {
|
|
|
| PartitionPage* page = GetFullPage(kTestAllocSize);
|
| FreeFullPage(page);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| - EXPECT_EQ(0, page->nextPage);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
| + EXPECT_EQ(0, page->next_page);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
|
|
| page = GetFullPage(kTestAllocSize);
|
| PartitionPage* page2 = GetFullPage(kTestAllocSize);
|
|
|
| - EXPECT_EQ(page2, bucket->activePagesHead);
|
| - EXPECT_EQ(0, page2->nextPage);
|
| - EXPECT_EQ(reinterpret_cast<uintptr_t>(partitionPageToPointer(page)) &
|
| + EXPECT_EQ(page2, bucket->active_pages_head);
|
| + EXPECT_EQ(0, page2->next_page);
|
| + EXPECT_EQ(reinterpret_cast<uintptr_t>(PartitionPageToPointer(page)) &
|
| kSuperPageBaseMask,
|
| - reinterpret_cast<uintptr_t>(partitionPageToPointer(page2)) &
|
| + reinterpret_cast<uintptr_t>(PartitionPageToPointer(page2)) &
|
| kSuperPageBaseMask);
|
|
|
| // Fully free the non-current page. This will leave us with no current
|
| // active page because one is empty and the other is full.
|
| FreeFullPage(page);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
|
|
| // Allocate a new page, it should pull from the freelist.
|
| page = GetFullPage(kTestAllocSize);
|
| - EXPECT_FALSE(bucket->emptyPagesHead);
|
| - EXPECT_EQ(page, bucket->activePagesHead);
|
| + EXPECT_FALSE(bucket->empty_pages_head);
|
| + EXPECT_EQ(page, bucket->active_pages_head);
|
|
|
| FreeFullPage(page);
|
| FreeFullPage(page2);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - EXPECT_EQ(0, page2->numAllocatedSlots);
|
| - EXPECT_EQ(0, page2->numUnprovisionedSlots);
|
| - EXPECT_NE(-1, page2->emptyCacheIndex);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + EXPECT_EQ(0, page2->num_allocated_slots);
|
| + EXPECT_EQ(0, page2->num_unprovisioned_slots);
|
| + EXPECT_NE(-1, page2->empty_cache_index);
|
|
|
| TestShutdown();
|
| }
|
| @@ -375,49 +376,49 @@ TEST(PartitionAllocTest, PageTransitions) {
|
| PartitionBucket* bucket = &allocator.root()->buckets()[kTestBucketIndex];
|
|
|
| PartitionPage* page1 = GetFullPage(kTestAllocSize);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| - EXPECT_EQ(0, page1->nextPage);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
| + EXPECT_EQ(0, page1->next_page);
|
| PartitionPage* page2 = GetFullPage(kTestAllocSize);
|
| - EXPECT_EQ(page2, bucket->activePagesHead);
|
| - EXPECT_EQ(0, page2->nextPage);
|
| + EXPECT_EQ(page2, bucket->active_pages_head);
|
| + EXPECT_EQ(0, page2->next_page);
|
|
|
| // Bounce page1 back into the non-full list then fill it up again.
|
| char* ptr =
|
| - reinterpret_cast<char*>(partitionPageToPointer(page1)) + kPointerOffset;
|
| - partitionFree(ptr);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| - (void)partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| - EXPECT_EQ(page2, bucket->activePagesHead->nextPage);
|
| + reinterpret_cast<char*>(PartitionPageToPointer(page1)) + kPointerOffset;
|
| + PartitionFree(ptr);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
| + (void)PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
| + EXPECT_EQ(page2, bucket->active_pages_head->next_page);
|
|
|
| // Allocating another page at this point should cause us to scan over page1
|
| // (which is both full and NOT our current page), and evict it from the
|
| // freelist. Older code had a O(n^2) condition due to failure to do this.
|
| PartitionPage* page3 = GetFullPage(kTestAllocSize);
|
| - EXPECT_EQ(page3, bucket->activePagesHead);
|
| - EXPECT_EQ(0, page3->nextPage);
|
| + EXPECT_EQ(page3, bucket->active_pages_head);
|
| + EXPECT_EQ(0, page3->next_page);
|
|
|
| // Work out a pointer into page2 and free it.
|
| - ptr = reinterpret_cast<char*>(partitionPageToPointer(page2)) + kPointerOffset;
|
| - partitionFree(ptr);
|
| + ptr = reinterpret_cast<char*>(PartitionPageToPointer(page2)) + kPointerOffset;
|
| + PartitionFree(ptr);
|
| // Trying to allocate at this time should cause us to cycle around to page2
|
| // and find the recently freed slot.
|
| char* newPtr = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_EQ(ptr, newPtr);
|
| - EXPECT_EQ(page2, bucket->activePagesHead);
|
| - EXPECT_EQ(page3, page2->nextPage);
|
| + EXPECT_EQ(page2, bucket->active_pages_head);
|
| + EXPECT_EQ(page3, page2->next_page);
|
|
|
| // Work out a pointer into page1 and free it. This should pull the page
|
| // back into the list of available pages.
|
| - ptr = reinterpret_cast<char*>(partitionPageToPointer(page1)) + kPointerOffset;
|
| - partitionFree(ptr);
|
| + ptr = reinterpret_cast<char*>(PartitionPageToPointer(page1)) + kPointerOffset;
|
| + PartitionFree(ptr);
|
| // This allocation should be satisfied by page1.
|
| newPtr = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| EXPECT_EQ(ptr, newPtr);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| - EXPECT_EQ(page2, page1->nextPage);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
| + EXPECT_EQ(page2, page1->next_page);
|
|
|
| FreeFullPage(page3);
|
| FreeFullPage(page2);
|
| @@ -425,8 +426,8 @@ TEST(PartitionAllocTest, PageTransitions) {
|
|
|
| // Allocating whilst in this state exposed a bug, so keep the test.
|
| ptr = reinterpret_cast<char*>(
|
| - partitionAlloc(allocator.root(), kTestAllocSize, typeName));
|
| - partitionFree(ptr);
|
| + PartitionAlloc(allocator.root(), kTestAllocSize, type_name));
|
| + PartitionFree(ptr);
|
|
|
| TestShutdown();
|
| }
|
| @@ -449,11 +450,11 @@ TEST(PartitionAllocTest, FreePageListPageTransitions) {
|
| for (i = 0; i < numToFillFreeListPage; ++i) {
|
| pages[i] = GetFullPage(kTestAllocSize);
|
| }
|
| - EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->activePagesHead);
|
| + EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->active_pages_head);
|
| for (i = 0; i < numToFillFreeListPage; ++i)
|
| FreeFullPage(pages[i]);
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
|
|
| // Allocate / free in a different bucket size so we get control of a
|
| // different free page list. We need two pages because one will be the last
|
| @@ -466,12 +467,12 @@ TEST(PartitionAllocTest, FreePageListPageTransitions) {
|
| for (i = 0; i < numToFillFreeListPage; ++i) {
|
| pages[i] = GetFullPage(kTestAllocSize);
|
| }
|
| - EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->activePagesHead);
|
| + EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->active_pages_head);
|
|
|
| for (i = 0; i < numToFillFreeListPage; ++i)
|
| FreeFullPage(pages[i]);
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
|
|
| TestShutdown();
|
| }
|
| @@ -494,7 +495,7 @@ TEST(PartitionAllocTest, MultiPageAllocs) {
|
| size_t i;
|
| for (i = 0; i < numPagesNeeded; ++i) {
|
| pages[i] = GetFullPage(kTestAllocSize);
|
| - void* storagePtr = partitionPageToPointer(pages[i]);
|
| + void* storagePtr = PartitionPageToPointer(pages[i]);
|
| if (!i)
|
| firstSuperPageBase =
|
| reinterpret_cast<uintptr_t>(storagePtr) & kSuperPageBaseMask;
|
| @@ -519,15 +520,15 @@ TEST(PartitionAllocTest, MultiPageAllocs) {
|
| TEST(PartitionAllocTest, GenericAlloc) {
|
| TestSetup();
|
|
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(), 1, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), 1, type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), kGenericMaxBucketed + 1,
|
| - typeName);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), kGenericMaxBucketed + 1,
|
| + type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), 1, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), 1, type_name);
|
| EXPECT_TRUE(ptr);
|
| void* origPtr = ptr;
|
| char* charPtr = static_cast<char*>(ptr);
|
| @@ -535,17 +536,17 @@ TEST(PartitionAllocTest, GenericAlloc) {
|
|
|
| // Change the size of the realloc, remaining inside the same bucket.
|
| void* newPtr =
|
| - partitionReallocGeneric(genericAllocator.root(), ptr, 2, typeName);
|
| + PartitionReallocGeneric(generic_allocator.root(), ptr, 2, type_name);
|
| EXPECT_EQ(ptr, newPtr);
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr, 1, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr, 1, type_name);
|
| EXPECT_EQ(ptr, newPtr);
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| - kGenericSmallestBucket, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| + kGenericSmallestBucket, type_name);
|
| EXPECT_EQ(ptr, newPtr);
|
|
|
| // Change the size of the realloc, switching buckets.
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| - kGenericSmallestBucket + 1, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| + kGenericSmallestBucket + 1, type_name);
|
| EXPECT_NE(newPtr, ptr);
|
| // Check that the realloc copied correctly.
|
| char* newCharPtr = static_cast<char*>(newPtr);
|
| @@ -561,13 +562,14 @@ TEST(PartitionAllocTest, GenericAlloc) {
|
| // The realloc moved. To check that the old allocation was freed, we can
|
| // do an alloc of the old allocation size and check that the old allocation
|
| // address is at the head of the freelist and reused.
|
| - void* reusedPtr = partitionAllocGeneric(genericAllocator.root(), 1, typeName);
|
| + void* reusedPtr =
|
| + PartitionAllocGeneric(generic_allocator.root(), 1, type_name);
|
| EXPECT_EQ(reusedPtr, origPtr);
|
| - partitionFreeGeneric(genericAllocator.root(), reusedPtr);
|
| + PartitionFreeGeneric(generic_allocator.root(), reusedPtr);
|
|
|
| // Downsize the realloc.
|
| ptr = newPtr;
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr, 1, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr, 1, type_name);
|
| EXPECT_EQ(newPtr, origPtr);
|
| newCharPtr = static_cast<char*>(newPtr);
|
| EXPECT_EQ(*newCharPtr, 'B');
|
| @@ -575,8 +577,8 @@ TEST(PartitionAllocTest, GenericAlloc) {
|
|
|
| // Upsize the realloc to outside the partition.
|
| ptr = newPtr;
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| - kGenericMaxBucketed + 1, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| + kGenericMaxBucketed + 1, type_name);
|
| EXPECT_NE(newPtr, ptr);
|
| newCharPtr = static_cast<char*>(newPtr);
|
| EXPECT_EQ(*newCharPtr, 'C');
|
| @@ -584,27 +586,27 @@ TEST(PartitionAllocTest, GenericAlloc) {
|
|
|
| // Upsize and downsize the realloc, remaining outside the partition.
|
| ptr = newPtr;
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| - kGenericMaxBucketed * 10, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| + kGenericMaxBucketed * 10, type_name);
|
| newCharPtr = static_cast<char*>(newPtr);
|
| EXPECT_EQ(*newCharPtr, 'D');
|
| *newCharPtr = 'E';
|
| ptr = newPtr;
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| - kGenericMaxBucketed * 2, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| + kGenericMaxBucketed * 2, type_name);
|
| newCharPtr = static_cast<char*>(newPtr);
|
| EXPECT_EQ(*newCharPtr, 'E');
|
| *newCharPtr = 'F';
|
|
|
| // Downsize the realloc to inside the partition.
|
| ptr = newPtr;
|
| - newPtr = partitionReallocGeneric(genericAllocator.root(), ptr, 1, typeName);
|
| + newPtr = PartitionReallocGeneric(generic_allocator.root(), ptr, 1, type_name);
|
| EXPECT_NE(newPtr, ptr);
|
| EXPECT_EQ(newPtr, origPtr);
|
| newCharPtr = static_cast<char*>(newPtr);
|
| EXPECT_EQ(*newCharPtr, 'F');
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), newPtr);
|
| + PartitionFreeGeneric(generic_allocator.root(), newPtr);
|
| TestShutdown();
|
| }
|
|
|
| @@ -613,53 +615,54 @@ TEST(PartitionAllocTest, GenericAlloc) {
|
| TEST(PartitionAllocTest, GenericAllocSizes) {
|
| TestSetup();
|
|
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(), 0, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), 0, type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // kPartitionPageSize is interesting because it results in just one
|
| // allocation per page, which tripped up some corner cases.
|
| size_t size = kPartitionPageSize - kExtraAllocSize;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| // Should be freeable at this point.
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_NE(-1, page->emptyCacheIndex);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_NE(-1, page->empty_cache_index);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
|
|
| size = (((kPartitionPageSize * kMaxPartitionPagesPerSlotSpan) -
|
| kSystemPageSize) /
|
| 2) -
|
| kExtraAllocSize;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| memset(ptr, 'A', size);
|
| - ptr2 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr2 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr2);
|
| - void* ptr3 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr3 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr3);
|
| - void* ptr4 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr4 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr4);
|
|
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| PartitionPage* page2 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr3));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr3));
|
| EXPECT_NE(page, page2);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| // Should be freeable at this point.
|
| - EXPECT_NE(-1, page->emptyCacheIndex);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - EXPECT_EQ(0, page->numUnprovisionedSlots);
|
| - void* newPtr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + EXPECT_NE(-1, page->empty_cache_index);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + EXPECT_EQ(0, page->num_unprovisioned_slots);
|
| + void* newPtr =
|
| + PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_EQ(ptr3, newPtr);
|
| - newPtr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + newPtr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_EQ(ptr2, newPtr);
|
| #if defined(OS_LINUX) && !DCHECK_IS_ON()
|
| // On Linux, we have a guarantee that freelisting a page should cause its
|
| @@ -671,18 +674,18 @@ TEST(PartitionAllocTest, GenericAllocSizes) {
|
| // byte pattern.
|
| EXPECT_EQ(0, *(reinterpret_cast<char*>(newPtr) + (size - 1)));
|
| #endif
|
| - partitionFreeGeneric(genericAllocator.root(), newPtr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr4);
|
| + PartitionFreeGeneric(generic_allocator.root(), newPtr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr4);
|
|
|
| // Can we allocate a massive (512MB) size?
|
| // Allocate 512MB, but +1, to test for cookie writing alignment issues.
|
| // Test this only if the device has enough memory or it might fail due
|
| // to OOM.
|
| if (IsLargeMemoryDevice()) {
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1,
|
| - typeName);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), 512 * 1024 * 1024 + 1,
|
| + type_name);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| }
|
|
|
| // Check a more reasonable, but still direct mapped, size.
|
| @@ -690,18 +693,18 @@ TEST(PartitionAllocTest, GenericAllocSizes) {
|
| size = 20 * 1024 * 1024;
|
| size -= kSystemPageSize;
|
| size -= 1;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| char* charPtr = reinterpret_cast<char*>(ptr);
|
| *(charPtr + (size - 1)) = 'A';
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Can we free null?
|
| - partitionFreeGeneric(genericAllocator.root(), 0);
|
| + PartitionFreeGeneric(generic_allocator.root(), 0);
|
|
|
| // Do we correctly get a null for a failed allocation?
|
| - EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(),
|
| + EXPECT_EQ(0, PartitionAllocGenericFlags(generic_allocator.root(),
|
| PartitionAllocReturnNull,
|
| - 3u * 1024 * 1024 * 1024, typeName));
|
| + 3u * 1024 * 1024 * 1024, type_name));
|
|
|
| TestShutdown();
|
| }
|
| @@ -713,64 +716,67 @@ TEST(PartitionAllocTest, GenericAllocGetSize) {
|
| void* ptr;
|
| size_t requestedSize, actualSize, predictedSize;
|
|
|
| - EXPECT_TRUE(partitionAllocSupportsGetSize());
|
| + EXPECT_TRUE(PartitionAllocSupportsGetSize());
|
|
|
| // Allocate something small.
|
| requestedSize = 511 - kExtraAllocSize;
|
| predictedSize =
|
| - partitionAllocActualSize(genericAllocator.root(), requestedSize);
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
|
| + PartitionAllocActualSize(generic_allocator.root(), requestedSize);
|
| + ptr =
|
| + PartitionAllocGeneric(generic_allocator.root(), requestedSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - actualSize = partitionAllocGetSize(ptr);
|
| + actualSize = PartitionAllocGetSize(ptr);
|
| EXPECT_EQ(predictedSize, actualSize);
|
| EXPECT_LT(requestedSize, actualSize);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Allocate a size that should be a perfect match for a bucket, because it
|
| // is an exact power of 2.
|
| requestedSize = (256 * 1024) - kExtraAllocSize;
|
| predictedSize =
|
| - partitionAllocActualSize(genericAllocator.root(), requestedSize);
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
|
| + PartitionAllocActualSize(generic_allocator.root(), requestedSize);
|
| + ptr =
|
| + PartitionAllocGeneric(generic_allocator.root(), requestedSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - actualSize = partitionAllocGetSize(ptr);
|
| + actualSize = PartitionAllocGetSize(ptr);
|
| EXPECT_EQ(predictedSize, actualSize);
|
| EXPECT_EQ(requestedSize, actualSize);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Allocate a size that is a system page smaller than a bucket. GetSize()
|
| // should return a larger size than we asked for now.
|
| requestedSize = (256 * 1024) - kSystemPageSize - kExtraAllocSize;
|
| predictedSize =
|
| - partitionAllocActualSize(genericAllocator.root(), requestedSize);
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
|
| + PartitionAllocActualSize(generic_allocator.root(), requestedSize);
|
| + ptr =
|
| + PartitionAllocGeneric(generic_allocator.root(), requestedSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - actualSize = partitionAllocGetSize(ptr);
|
| + actualSize = PartitionAllocGetSize(ptr);
|
| EXPECT_EQ(predictedSize, actualSize);
|
| EXPECT_EQ(requestedSize + kSystemPageSize, actualSize);
|
| // Check that we can write at the end of the reported size too.
|
| char* charPtr = reinterpret_cast<char*>(ptr);
|
| *(charPtr + (actualSize - 1)) = 'A';
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Allocate something very large, and uneven.
|
| if (IsLargeMemoryDevice()) {
|
| requestedSize = 512 * 1024 * 1024 - 1;
|
| predictedSize =
|
| - partitionAllocActualSize(genericAllocator.root(), requestedSize);
|
| - ptr =
|
| - partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName);
|
| + PartitionAllocActualSize(generic_allocator.root(), requestedSize);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), requestedSize,
|
| + type_name);
|
| EXPECT_TRUE(ptr);
|
| - actualSize = partitionAllocGetSize(ptr);
|
| + actualSize = PartitionAllocGetSize(ptr);
|
| EXPECT_EQ(predictedSize, actualSize);
|
| EXPECT_LT(requestedSize, actualSize);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| }
|
|
|
| // Too large allocation.
|
| requestedSize = INT_MAX;
|
| predictedSize =
|
| - partitionAllocActualSize(genericAllocator.root(), requestedSize);
|
| + PartitionAllocActualSize(generic_allocator.root(), requestedSize);
|
| EXPECT_EQ(requestedSize, predictedSize);
|
|
|
| TestShutdown();
|
| @@ -781,25 +787,25 @@ TEST(PartitionAllocTest, Realloc) {
|
| TestSetup();
|
|
|
| // realloc(0, size) should be equivalent to malloc().
|
| - void* ptr = partitionReallocGeneric(genericAllocator.root(), 0,
|
| - kTestAllocSize, typeName);
|
| + void* ptr = PartitionReallocGeneric(generic_allocator.root(), 0,
|
| + kTestAllocSize, type_name);
|
| memset(ptr, 'A', kTestAllocSize);
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| // realloc(ptr, 0) should be equivalent to free().
|
| void* ptr2 =
|
| - partitionReallocGeneric(genericAllocator.root(), ptr, 0, typeName);
|
| + PartitionReallocGeneric(generic_allocator.root(), ptr, 0, type_name);
|
| EXPECT_EQ(0, ptr2);
|
| - EXPECT_EQ(partitionCookieFreePointerAdjust(ptr), page->freelistHead);
|
| + EXPECT_EQ(PartitionCookieFreePointerAdjust(ptr), page->freelist_head);
|
|
|
| // Test that growing an allocation with realloc() copies everything from the
|
| // old allocation.
|
| size_t size = kSystemPageSize - kExtraAllocSize;
|
| - EXPECT_EQ(size, partitionAllocActualSize(genericAllocator.root(), size));
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + EXPECT_EQ(size, PartitionAllocActualSize(generic_allocator.root(), size));
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| memset(ptr, 'A', size);
|
| - ptr2 =
|
| - partitionReallocGeneric(genericAllocator.root(), ptr, size + 1, typeName);
|
| + ptr2 = PartitionReallocGeneric(generic_allocator.root(), ptr, size + 1,
|
| + type_name);
|
| EXPECT_NE(ptr, ptr2);
|
| char* charPtr2 = static_cast<char*>(ptr2);
|
| EXPECT_EQ('A', charPtr2[0]);
|
| @@ -810,8 +816,8 @@ TEST(PartitionAllocTest, Realloc) {
|
|
|
| // Test that shrinking an allocation with realloc() also copies everything
|
| // from the old allocation.
|
| - ptr = partitionReallocGeneric(genericAllocator.root(), ptr2, size - 1,
|
| - typeName);
|
| + ptr = PartitionReallocGeneric(generic_allocator.root(), ptr2, size - 1,
|
| + type_name);
|
| EXPECT_NE(ptr2, ptr);
|
| char* charPtr = static_cast<char*>(ptr);
|
| EXPECT_EQ('A', charPtr[0]);
|
| @@ -820,32 +826,32 @@ TEST(PartitionAllocTest, Realloc) {
|
| EXPECT_EQ(kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1]));
|
| #endif
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Test that shrinking a direct mapped allocation happens in-place.
|
| size = kGenericMaxBucketed + 16 * kSystemPageSize;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - size_t actualSize = partitionAllocGetSize(ptr);
|
| - ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr,
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + size_t actualSize = PartitionAllocGetSize(ptr);
|
| + ptr2 = PartitionReallocGeneric(generic_allocator.root(), ptr,
|
| kGenericMaxBucketed + 8 * kSystemPageSize,
|
| - typeName);
|
| + type_name);
|
| EXPECT_EQ(ptr, ptr2);
|
| - EXPECT_EQ(actualSize - 8 * kSystemPageSize, partitionAllocGetSize(ptr2));
|
| + EXPECT_EQ(actualSize - 8 * kSystemPageSize, PartitionAllocGetSize(ptr2));
|
|
|
| // Test that a previously in-place shrunk direct mapped allocation can be
|
| // expanded up again within its original size.
|
| - ptr = partitionReallocGeneric(genericAllocator.root(), ptr2,
|
| - size - kSystemPageSize, typeName);
|
| + ptr = PartitionReallocGeneric(generic_allocator.root(), ptr2,
|
| + size - kSystemPageSize, type_name);
|
| EXPECT_EQ(ptr2, ptr);
|
| - EXPECT_EQ(actualSize - kSystemPageSize, partitionAllocGetSize(ptr));
|
| + EXPECT_EQ(actualSize - kSystemPageSize, PartitionAllocGetSize(ptr));
|
|
|
| // Test that a direct mapped allocation is performed not in-place when the
|
| // new size is small enough.
|
| - ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, kSystemPageSize,
|
| - typeName);
|
| + ptr2 = PartitionReallocGeneric(generic_allocator.root(), ptr, kSystemPageSize,
|
| + type_name);
|
| EXPECT_NE(ptr, ptr2);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
|
|
| TestShutdown();
|
| }
|
| @@ -854,151 +860,156 @@ TEST(PartitionAllocTest, Realloc) {
|
| TEST(PartitionAllocTest, PartialPageFreelists) {
|
| TestSetup();
|
|
|
| - size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize;
|
| + size_t big_size = allocator.root()->max_allocation - kExtraAllocSize;
|
| EXPECT_EQ(kSystemPageSize - kAllocationGranularity,
|
| - bigSize + kExtraAllocSize);
|
| - size_t bucketIdx = (bigSize + kExtraAllocSize) >> kBucketShift;
|
| - PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx];
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| + big_size + kExtraAllocSize);
|
| + size_t bucket_index = (big_size + kExtraAllocSize) >> kBucketShift;
|
| + PartitionBucket* bucket = &allocator.root()->buckets()[bucket_index];
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
|
|
| - void* ptr = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr);
|
|
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| size_t totalSlots =
|
| - (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (bigSize + kExtraAllocSize);
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (big_size + kExtraAllocSize);
|
| EXPECT_EQ(4u, totalSlots);
|
| // The freelist should have one entry, because we were able to exactly fit
|
| // one object slot and one freelist pointer (the null that the head points
|
| // to) into a system page.
|
| - EXPECT_TRUE(page->freelistHead);
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - EXPECT_EQ(2, page->numUnprovisionedSlots);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + EXPECT_EQ(2, page->num_unprovisioned_slots);
|
|
|
| - void* ptr2 = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr2 = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr2);
|
| - EXPECT_FALSE(page->freelistHead);
|
| - EXPECT_EQ(2, page->numAllocatedSlots);
|
| - EXPECT_EQ(2, page->numUnprovisionedSlots);
|
| + EXPECT_FALSE(page->freelist_head);
|
| + EXPECT_EQ(2, page->num_allocated_slots);
|
| + EXPECT_EQ(2, page->num_unprovisioned_slots);
|
|
|
| - void* ptr3 = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr3 = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr3);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - EXPECT_EQ(3, page->numAllocatedSlots);
|
| - EXPECT_EQ(0, page->numUnprovisionedSlots);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + EXPECT_EQ(3, page->num_allocated_slots);
|
| + EXPECT_EQ(0, page->num_unprovisioned_slots);
|
|
|
| - void* ptr4 = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr4 = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr4);
|
| - EXPECT_FALSE(page->freelistHead);
|
| - EXPECT_EQ(4, page->numAllocatedSlots);
|
| - EXPECT_EQ(0, page->numUnprovisionedSlots);
|
| + EXPECT_FALSE(page->freelist_head);
|
| + EXPECT_EQ(4, page->num_allocated_slots);
|
| + EXPECT_EQ(0, page->num_unprovisioned_slots);
|
|
|
| - void* ptr5 = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr5 = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr5);
|
|
|
| PartitionPage* page2 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr5));
|
| - EXPECT_EQ(1, page2->numAllocatedSlots);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr5));
|
| + EXPECT_EQ(1, page2->num_allocated_slots);
|
|
|
| // Churn things a little whilst there's a partial page freelist.
|
| - partitionFree(ptr);
|
| - ptr = partitionAlloc(allocator.root(), bigSize, typeName);
|
| - void* ptr6 = partitionAlloc(allocator.root(), bigSize, typeName);
|
| -
|
| - partitionFree(ptr);
|
| - partitionFree(ptr2);
|
| - partitionFree(ptr3);
|
| - partitionFree(ptr4);
|
| - partitionFree(ptr5);
|
| - partitionFree(ptr6);
|
| - EXPECT_NE(-1, page->emptyCacheIndex);
|
| - EXPECT_NE(-1, page2->emptyCacheIndex);
|
| - EXPECT_TRUE(page2->freelistHead);
|
| - EXPECT_EQ(0, page2->numAllocatedSlots);
|
| + PartitionFree(ptr);
|
| + ptr = PartitionAlloc(allocator.root(), big_size, type_name);
|
| + void* ptr6 = PartitionAlloc(allocator.root(), big_size, type_name);
|
| +
|
| + PartitionFree(ptr);
|
| + PartitionFree(ptr2);
|
| + PartitionFree(ptr3);
|
| + PartitionFree(ptr4);
|
| + PartitionFree(ptr5);
|
| + PartitionFree(ptr6);
|
| + EXPECT_NE(-1, page->empty_cache_index);
|
| + EXPECT_NE(-1, page2->empty_cache_index);
|
| + EXPECT_TRUE(page2->freelist_head);
|
| + EXPECT_EQ(0, page2->num_allocated_slots);
|
|
|
| // And test a couple of sizes that do not cross kSystemPageSize with a single
|
| // allocation.
|
| size_t mediumSize = (kSystemPageSize / 2) - kExtraAllocSize;
|
| - bucketIdx = (mediumSize + kExtraAllocSize) >> kBucketShift;
|
| - bucket = &allocator.root()->buckets()[bucketIdx];
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| + bucket_index = (mediumSize + kExtraAllocSize) >> kBucketShift;
|
| + bucket = &allocator.root()->buckets()[bucket_index];
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
|
|
| - ptr = partitionAlloc(allocator.root(), mediumSize, typeName);
|
| + ptr = PartitionAlloc(allocator.root(), mediumSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - totalSlots = (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (mediumSize + kExtraAllocSize);
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + totalSlots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (mediumSize + kExtraAllocSize);
|
| size_t firstPageSlots = kSystemPageSize / (mediumSize + kExtraAllocSize);
|
| EXPECT_EQ(2u, firstPageSlots);
|
| - EXPECT_EQ(totalSlots - firstPageSlots, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(totalSlots - firstPageSlots, page->num_unprovisioned_slots);
|
|
|
| - partitionFree(ptr);
|
| + PartitionFree(ptr);
|
|
|
| size_t smallSize = (kSystemPageSize / 4) - kExtraAllocSize;
|
| - bucketIdx = (smallSize + kExtraAllocSize) >> kBucketShift;
|
| - bucket = &allocator.root()->buckets()[bucketIdx];
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| + bucket_index = (smallSize + kExtraAllocSize) >> kBucketShift;
|
| + bucket = &allocator.root()->buckets()[bucket_index];
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
|
|
| - ptr = partitionAlloc(allocator.root(), smallSize, typeName);
|
| + ptr = PartitionAlloc(allocator.root(), smallSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - totalSlots = (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (smallSize + kExtraAllocSize);
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + totalSlots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (smallSize + kExtraAllocSize);
|
| firstPageSlots = kSystemPageSize / (smallSize + kExtraAllocSize);
|
| - EXPECT_EQ(totalSlots - firstPageSlots, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(totalSlots - firstPageSlots, page->num_unprovisioned_slots);
|
|
|
| - partitionFree(ptr);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| + PartitionFree(ptr);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
|
|
| size_t verySmallSize = 32 - kExtraAllocSize;
|
| - bucketIdx = (verySmallSize + kExtraAllocSize) >> kBucketShift;
|
| - bucket = &allocator.root()->buckets()[bucketIdx];
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| + bucket_index = (verySmallSize + kExtraAllocSize) >> kBucketShift;
|
| + bucket = &allocator.root()->buckets()[bucket_index];
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
|
|
| - ptr = partitionAlloc(allocator.root(), verySmallSize, typeName);
|
| + ptr = PartitionAlloc(allocator.root(), verySmallSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - totalSlots = (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (verySmallSize + kExtraAllocSize);
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + totalSlots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (verySmallSize + kExtraAllocSize);
|
| firstPageSlots = kSystemPageSize / (verySmallSize + kExtraAllocSize);
|
| - EXPECT_EQ(totalSlots - firstPageSlots, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(totalSlots - firstPageSlots, page->num_unprovisioned_slots);
|
|
|
| - partitionFree(ptr);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| + PartitionFree(ptr);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
|
|
| // And try an allocation size (against the generic allocator) that is
|
| // larger than a system page.
|
| size_t pageAndAHalfSize =
|
| (kSystemPageSize + (kSystemPageSize / 2)) - kExtraAllocSize;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), pageAndAHalfSize,
|
| - typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), pageAndAHalfSize,
|
| + type_name);
|
| EXPECT_TRUE(ptr);
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - totalSlots = (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (pageAndAHalfSize + kExtraAllocSize);
|
| - EXPECT_EQ(totalSlots - 2, page->numUnprovisionedSlots);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + totalSlots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (pageAndAHalfSize + kExtraAllocSize);
|
| + EXPECT_EQ(totalSlots - 2, page->num_unprovisioned_slots);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // And then make sure than exactly the page size only faults one page.
|
| size_t pageSize = kSystemPageSize - kExtraAllocSize;
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), pageSize, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), pageSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - page = partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - EXPECT_FALSE(page->freelistHead);
|
| - totalSlots = (page->bucket->numSystemPagesPerSlotSpan * kSystemPageSize) /
|
| - (pageSize + kExtraAllocSize);
|
| - EXPECT_EQ(totalSlots - 1, page->numUnprovisionedSlots);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + page = PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + EXPECT_FALSE(page->freelist_head);
|
| + totalSlots =
|
| + (page->bucket->num_system_pages_per_slot_span * kSystemPageSize) /
|
| + (pageSize + kExtraAllocSize);
|
| + EXPECT_EQ(totalSlots - 1, page->num_unprovisioned_slots);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| TestShutdown();
|
| }
|
| @@ -1011,31 +1022,31 @@ TEST(PartitionAllocTest, PageRefilling) {
|
| // Grab two full pages and a non-full page.
|
| PartitionPage* page1 = GetFullPage(kTestAllocSize);
|
| PartitionPage* page2 = GetFullPage(kTestAllocSize);
|
| - void* ptr = partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| + void* ptr = PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| EXPECT_TRUE(ptr);
|
| - EXPECT_NE(page1, bucket->activePagesHead);
|
| - EXPECT_NE(page2, bucket->activePagesHead);
|
| + EXPECT_NE(page1, bucket->active_pages_head);
|
| + EXPECT_NE(page2, bucket->active_pages_head);
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
|
|
| // Work out a pointer into page2 and free it; and then page1 and free it.
|
| char* ptr2 =
|
| - reinterpret_cast<char*>(partitionPageToPointer(page1)) + kPointerOffset;
|
| - partitionFree(ptr2);
|
| + reinterpret_cast<char*>(PartitionPageToPointer(page1)) + kPointerOffset;
|
| + PartitionFree(ptr2);
|
| ptr2 =
|
| - reinterpret_cast<char*>(partitionPageToPointer(page2)) + kPointerOffset;
|
| - partitionFree(ptr2);
|
| + reinterpret_cast<char*>(PartitionPageToPointer(page2)) + kPointerOffset;
|
| + PartitionFree(ptr2);
|
|
|
| // If we perform two allocations from the same bucket now, we expect to
|
| // refill both the nearly full pages.
|
| - (void)partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| - (void)partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| + (void)PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| + (void)PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
|
|
| FreeFullPage(page2);
|
| FreeFullPage(page1);
|
| - partitionFree(ptr);
|
| + PartitionFree(ptr);
|
|
|
| TestShutdown();
|
| }
|
| @@ -1049,7 +1060,8 @@ TEST(PartitionAllocTest, PartialPages) {
|
| PartitionBucket* bucket = 0;
|
| while (size < kTestMaxAllocation) {
|
| bucket = &allocator.root()->buckets()[size >> kBucketShift];
|
| - if (bucket->numSystemPagesPerSlotSpan % kNumSystemPagesPerPartitionPage)
|
| + if (bucket->num_system_pages_per_slot_span %
|
| + kNumSystemPagesPerPartitionPage)
|
| break;
|
| size += sizeof(void*);
|
| }
|
| @@ -1079,63 +1091,63 @@ TEST(PartitionAllocTest, MappingCollision) {
|
| firstSuperPagePages[i] = GetFullPage(kTestAllocSize);
|
|
|
| char* pageBase =
|
| - reinterpret_cast<char*>(partitionPageToPointer(firstSuperPagePages[0]));
|
| + reinterpret_cast<char*>(PartitionPageToPointer(firstSuperPagePages[0]));
|
| EXPECT_EQ(kPartitionPageSize,
|
| reinterpret_cast<uintptr_t>(pageBase) & kSuperPageOffsetMask);
|
| pageBase -= kPartitionPageSize;
|
| // Map a single system page either side of the mapping for our allocations,
|
| // with the goal of tripping up alignment of the next mapping.
|
| - void* map1 = allocPages(pageBase - kPageAllocationGranularity,
|
| + void* map1 = AllocPages(pageBase - kPageAllocationGranularity,
|
| kPageAllocationGranularity,
|
| kPageAllocationGranularity, PageInaccessible);
|
| EXPECT_TRUE(map1);
|
| - void* map2 = allocPages(pageBase + kSuperPageSize, kPageAllocationGranularity,
|
| + void* map2 = AllocPages(pageBase + kSuperPageSize, kPageAllocationGranularity,
|
| kPageAllocationGranularity, PageInaccessible);
|
| EXPECT_TRUE(map2);
|
|
|
| for (i = 0; i < numPartitionPagesNeeded; ++i)
|
| secondSuperPagePages[i] = GetFullPage(kTestAllocSize);
|
|
|
| - freePages(map1, kPageAllocationGranularity);
|
| - freePages(map2, kPageAllocationGranularity);
|
| + FreePages(map1, kPageAllocationGranularity);
|
| + FreePages(map2, kPageAllocationGranularity);
|
|
|
| pageBase =
|
| - reinterpret_cast<char*>(partitionPageToPointer(secondSuperPagePages[0]));
|
| + reinterpret_cast<char*>(PartitionPageToPointer(secondSuperPagePages[0]));
|
| EXPECT_EQ(kPartitionPageSize,
|
| reinterpret_cast<uintptr_t>(pageBase) & kSuperPageOffsetMask);
|
| pageBase -= kPartitionPageSize;
|
| // Map a single system page either side of the mapping for our allocations,
|
| // with the goal of tripping up alignment of the next mapping.
|
| - map1 = allocPages(pageBase - kPageAllocationGranularity,
|
| + map1 = AllocPages(pageBase - kPageAllocationGranularity,
|
| kPageAllocationGranularity, kPageAllocationGranularity,
|
| PageAccessible);
|
| EXPECT_TRUE(map1);
|
| - map2 = allocPages(pageBase + kSuperPageSize, kPageAllocationGranularity,
|
| + map2 = AllocPages(pageBase + kSuperPageSize, kPageAllocationGranularity,
|
| kPageAllocationGranularity, PageAccessible);
|
| EXPECT_TRUE(map2);
|
| - setSystemPagesInaccessible(map1, kPageAllocationGranularity);
|
| - setSystemPagesInaccessible(map2, kPageAllocationGranularity);
|
| + SetSystemPagesInaccessible(map1, kPageAllocationGranularity);
|
| + SetSystemPagesInaccessible(map2, kPageAllocationGranularity);
|
|
|
| PartitionPage* pageInThirdSuperPage = GetFullPage(kTestAllocSize);
|
| - freePages(map1, kPageAllocationGranularity);
|
| - freePages(map2, kPageAllocationGranularity);
|
| + FreePages(map1, kPageAllocationGranularity);
|
| + FreePages(map2, kPageAllocationGranularity);
|
|
|
| EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(
|
| - partitionPageToPointer(pageInThirdSuperPage)) &
|
| + PartitionPageToPointer(pageInThirdSuperPage)) &
|
| kPartitionPageOffsetMask);
|
|
|
| // And make sure we really did get a page in a new superpage.
|
| EXPECT_NE(reinterpret_cast<uintptr_t>(
|
| - partitionPageToPointer(firstSuperPagePages[0])) &
|
| + PartitionPageToPointer(firstSuperPagePages[0])) &
|
| kSuperPageBaseMask,
|
| reinterpret_cast<uintptr_t>(
|
| - partitionPageToPointer(pageInThirdSuperPage)) &
|
| + PartitionPageToPointer(pageInThirdSuperPage)) &
|
| kSuperPageBaseMask);
|
| EXPECT_NE(reinterpret_cast<uintptr_t>(
|
| - partitionPageToPointer(secondSuperPagePages[0])) &
|
| + PartitionPageToPointer(secondSuperPagePages[0])) &
|
| kSuperPageBaseMask,
|
| reinterpret_cast<uintptr_t>(
|
| - partitionPageToPointer(pageInThirdSuperPage)) &
|
| + PartitionPageToPointer(pageInThirdSuperPage)) &
|
| kSuperPageBaseMask);
|
|
|
| FreeFullPage(pageInThirdSuperPage);
|
| @@ -1151,50 +1163,53 @@ TEST(PartitionAllocTest, MappingCollision) {
|
| TEST(PartitionAllocTest, FreeCache) {
|
| TestSetup();
|
|
|
| - EXPECT_EQ(0U, allocator.root()->totalSizeOfCommittedPages);
|
| + EXPECT_EQ(0U, allocator.root()->total_size_of_committed_pages);
|
|
|
| - size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize;
|
| - size_t bucketIdx = (bigSize + kExtraAllocSize) >> kBucketShift;
|
| - PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx];
|
| + size_t big_size = allocator.root()->max_allocation - kExtraAllocSize;
|
| + size_t bucket_index = (big_size + kExtraAllocSize) >> kBucketShift;
|
| + PartitionBucket* bucket = &allocator.root()->buckets()[bucket_index];
|
|
|
| - void* ptr = partitionAlloc(allocator.root(), bigSize, typeName);
|
| + void* ptr = PartitionAlloc(allocator.root(), big_size, type_name);
|
| EXPECT_TRUE(ptr);
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| - EXPECT_EQ(1, page->numAllocatedSlots);
|
| - EXPECT_EQ(kPartitionPageSize, allocator.root()->totalSizeOfCommittedPages);
|
| - partitionFree(ptr);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - EXPECT_NE(-1, page->emptyCacheIndex);
|
| - EXPECT_TRUE(page->freelistHead);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
| + EXPECT_EQ(1, page->num_allocated_slots);
|
| + EXPECT_EQ(kPartitionPageSize,
|
| + allocator.root()->total_size_of_committed_pages);
|
| + PartitionFree(ptr);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + EXPECT_NE(-1, page->empty_cache_index);
|
| + EXPECT_TRUE(page->freelist_head);
|
|
|
| CycleFreeCache(kTestAllocSize);
|
|
|
| // Flushing the cache should have really freed the unused page.
|
| - EXPECT_FALSE(page->freelistHead);
|
| - EXPECT_EQ(-1, page->emptyCacheIndex);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - PartitionBucket* cycleFreeCacheBucket =
|
| + EXPECT_FALSE(page->freelist_head);
|
| + EXPECT_EQ(-1, page->empty_cache_index);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + PartitionBucket* cycle_free_cache_bucket =
|
| &allocator.root()->buckets()[kTestBucketIndex];
|
| - EXPECT_EQ(cycleFreeCacheBucket->numSystemPagesPerSlotSpan * kSystemPageSize,
|
| - allocator.root()->totalSizeOfCommittedPages);
|
| + EXPECT_EQ(
|
| + cycle_free_cache_bucket->num_system_pages_per_slot_span * kSystemPageSize,
|
| + allocator.root()->total_size_of_committed_pages);
|
|
|
| // Check that an allocation works ok whilst in this state (a free'd page
|
| // as the active pages head).
|
| - ptr = partitionAlloc(allocator.root(), bigSize, typeName);
|
| - EXPECT_FALSE(bucket->emptyPagesHead);
|
| - partitionFree(ptr);
|
| + ptr = PartitionAlloc(allocator.root(), big_size, type_name);
|
| + EXPECT_FALSE(bucket->empty_pages_head);
|
| + PartitionFree(ptr);
|
|
|
| // Also check that a page that is bouncing immediately between empty and
|
| // used does not get freed.
|
| for (size_t i = 0; i < kMaxFreeableSpans * 2; ++i) {
|
| - ptr = partitionAlloc(allocator.root(), bigSize, typeName);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - partitionFree(ptr);
|
| - EXPECT_TRUE(page->freelistHead);
|
| + ptr = PartitionAlloc(allocator.root(), big_size, type_name);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + PartitionFree(ptr);
|
| + EXPECT_TRUE(page->freelist_head);
|
| }
|
| - EXPECT_EQ(kPartitionPageSize, allocator.root()->totalSizeOfCommittedPages);
|
| + EXPECT_EQ(kPartitionPageSize,
|
| + allocator.root()->total_size_of_committed_pages);
|
| TestShutdown();
|
| }
|
|
|
| @@ -1204,61 +1219,61 @@ TEST(PartitionAllocTest, LostFreePagesBug) {
|
|
|
| size_t size = kPartitionPageSize - kExtraAllocSize;
|
|
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr2);
|
|
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr));
|
| PartitionPage* page2 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr2));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr2));
|
| PartitionBucket* bucket = page->bucket;
|
|
|
| - EXPECT_EQ(0, bucket->emptyPagesHead);
|
| - EXPECT_EQ(-1, page->numAllocatedSlots);
|
| - EXPECT_EQ(1, page2->numAllocatedSlots);
|
| + EXPECT_EQ(0, bucket->empty_pages_head);
|
| + EXPECT_EQ(-1, page->num_allocated_slots);
|
| + EXPECT_EQ(1, page2->num_allocated_slots);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
|
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead->nextPage);
|
| - EXPECT_EQ(0, page->numAllocatedSlots);
|
| - EXPECT_EQ(0, page2->numAllocatedSlots);
|
| - EXPECT_TRUE(page->freelistHead);
|
| - EXPECT_TRUE(page2->freelistHead);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head->next_page);
|
| + EXPECT_EQ(0, page->num_allocated_slots);
|
| + EXPECT_EQ(0, page2->num_allocated_slots);
|
| + EXPECT_TRUE(page->freelist_head);
|
| + EXPECT_TRUE(page2->freelist_head);
|
|
|
| CycleGenericFreeCache(kTestAllocSize);
|
|
|
| - EXPECT_FALSE(page->freelistHead);
|
| - EXPECT_FALSE(page2->freelistHead);
|
| + EXPECT_FALSE(page->freelist_head);
|
| + EXPECT_FALSE(page2->freelist_head);
|
|
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead->nextPage);
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head->next_page);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
|
|
| // At this moment, we have two decommitted pages, on the empty list.
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| - EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_TRUE(bucket->decommittedPagesHead);
|
| + EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->active_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_TRUE(bucket->decommitted_pages_head);
|
|
|
| CycleGenericFreeCache(kTestAllocSize);
|
|
|
| // We're now set up to trigger a historical bug by scanning over the active
|
| // pages list. The current code gets into a different state, but we'll keep
|
| // the test as being an interesting corner case.
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| - EXPECT_TRUE(bucket->activePagesHead);
|
| - EXPECT_TRUE(bucket->emptyPagesHead);
|
| - EXPECT_TRUE(bucket->decommittedPagesHead);
|
| + EXPECT_TRUE(bucket->active_pages_head);
|
| + EXPECT_TRUE(bucket->empty_pages_head);
|
| + EXPECT_TRUE(bucket->decommitted_pages_head);
|
|
|
| TestShutdown();
|
| }
|
| @@ -1281,19 +1296,20 @@ static void DoReturnNullTest(size_t allocSize) {
|
| // Work out the number of allocations for 6 GB of memory.
|
| const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024);
|
|
|
| - void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric(
|
| - genericAllocator.root(), numAllocations * sizeof(void*), typeName));
|
| + void** ptrs = reinterpret_cast<void**>(PartitionAllocGeneric(
|
| + generic_allocator.root(), numAllocations * sizeof(void*), type_name));
|
| int i;
|
|
|
| for (i = 0; i < numAllocations; ++i) {
|
| - ptrs[i] = partitionAllocGenericFlags(
|
| - genericAllocator.root(), PartitionAllocReturnNull, allocSize, typeName);
|
| + ptrs[i] = PartitionAllocGenericFlags(generic_allocator.root(),
|
| + PartitionAllocReturnNull, allocSize,
|
| + type_name);
|
| if (!i)
|
| EXPECT_TRUE(ptrs[0]);
|
| if (!ptrs[i]) {
|
| - ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(),
|
| + ptrs[i] = PartitionAllocGenericFlags(generic_allocator.root(),
|
| PartitionAllocReturnNull, allocSize,
|
| - typeName);
|
| + type_name);
|
| EXPECT_FALSE(ptrs[i]);
|
| break;
|
| }
|
| @@ -1306,14 +1322,15 @@ static void DoReturnNullTest(size_t allocSize) {
|
| // Free, reallocate and free again each block we allocated. We do this to
|
| // check that freeing memory also works correctly after a failed allocation.
|
| for (--i; i >= 0; --i) {
|
| - partitionFreeGeneric(genericAllocator.root(), ptrs[i]);
|
| - ptrs[i] = partitionAllocGenericFlags(
|
| - genericAllocator.root(), PartitionAllocReturnNull, allocSize, typeName);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptrs[i]);
|
| + ptrs[i] = PartitionAllocGenericFlags(generic_allocator.root(),
|
| + PartitionAllocReturnNull, allocSize,
|
| + type_name);
|
| EXPECT_TRUE(ptrs[i]);
|
| - partitionFreeGeneric(genericAllocator.root(), ptrs[i]);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptrs[i]);
|
| }
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptrs);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptrs);
|
|
|
| EXPECT_TRUE(ClearAddressSpaceLimit());
|
|
|
| @@ -1362,13 +1379,13 @@ TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) {
|
| TEST(PartitionAllocDeathTest, LargeAllocs) {
|
| TestSetup();
|
| // Largest alloc.
|
| - EXPECT_DEATH(partitionAllocGeneric(genericAllocator.root(),
|
| - static_cast<size_t>(-1), typeName),
|
| + EXPECT_DEATH(PartitionAllocGeneric(generic_allocator.root(),
|
| + static_cast<size_t>(-1), type_name),
|
| "");
|
| // And the smallest allocation we expect to die.
|
| EXPECT_DEATH(
|
| - partitionAllocGeneric(genericAllocator.root(),
|
| - static_cast<size_t>(INT_MAX) + 1, typeName),
|
| + PartitionAllocGeneric(generic_allocator.root(),
|
| + static_cast<size_t>(INT_MAX) + 1, type_name),
|
| "");
|
|
|
| TestShutdown();
|
| @@ -1378,12 +1395,12 @@ TEST(PartitionAllocDeathTest, LargeAllocs) {
|
| TEST(PartitionAllocDeathTest, ImmediateDoubleFree) {
|
| TestSetup();
|
|
|
| - void* ptr =
|
| - partitionAllocGeneric(genericAllocator.root(), kTestAllocSize, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), kTestAllocSize,
|
| + type_name);
|
| EXPECT_TRUE(ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| - EXPECT_DEATH(partitionFreeGeneric(genericAllocator.root(), ptr), "");
|
| + EXPECT_DEATH(PartitionFreeGeneric(generic_allocator.root(), ptr), "");
|
|
|
| TestShutdown();
|
| }
|
| @@ -1392,18 +1409,18 @@ TEST(PartitionAllocDeathTest, ImmediateDoubleFree) {
|
| TEST(PartitionAllocDeathTest, RefcountDoubleFree) {
|
| TestSetup();
|
|
|
| - void* ptr =
|
| - partitionAllocGeneric(genericAllocator.root(), kTestAllocSize, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), kTestAllocSize,
|
| + type_name);
|
| EXPECT_TRUE(ptr);
|
| - void* ptr2 =
|
| - partitionAllocGeneric(genericAllocator.root(), kTestAllocSize, typeName);
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(), kTestAllocSize,
|
| + type_name);
|
| EXPECT_TRUE(ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| // This is not an immediate double-free so our immediate detection won't
|
| // fire. However, it does take the "refcount" of the partition page to -1,
|
| // which is illegal and should be trapped.
|
| - EXPECT_DEATH(partitionFreeGeneric(genericAllocator.root(), ptr), "");
|
| + EXPECT_DEATH(PartitionFreeGeneric(generic_allocator.root(), ptr), "");
|
|
|
| TestShutdown();
|
| }
|
| @@ -1412,17 +1429,17 @@ TEST(PartitionAllocDeathTest, RefcountDoubleFree) {
|
| TEST(PartitionAllocDeathTest, GuardPages) {
|
| TestSetup();
|
|
|
| -// partitionAlloc adds kPartitionPageSize to the requested size
|
| +// PartitionAlloc adds kPartitionPageSize to the requested size
|
| // (for metadata), and then rounds that size to kPageAllocationGranularity.
|
| // To be able to reliably write one past a direct allocation, choose a size
|
| // that's
|
| // a) larger than kGenericMaxBucketed (to make the allocation direct)
|
| // b) aligned at kPageAllocationGranularity boundaries after
|
| // kPartitionPageSize has been added to it.
|
| -// (On 32-bit, partitionAlloc adds another kSystemPageSize to the
|
| +// (On 32-bit, PartitionAlloc adds another kSystemPageSize to the
|
| // allocation size before rounding, but there it marks the memory right
|
| // after size as inaccessible, so it's fine to write 1 past the size we
|
| -// hand to partitionAlloc and we don't need to worry about allocation
|
| +// hand to PartitionAlloc and we don't need to worry about allocation
|
| // granularities.)
|
| #define ALIGN(N, A) (((N) + (A)-1) / (A) * (A))
|
| const int kSize = ALIGN(kGenericMaxBucketed + 1 + kPartitionPageSize,
|
| @@ -1432,7 +1449,7 @@ TEST(PartitionAllocDeathTest, GuardPages) {
|
| static_assert(kSize > kGenericMaxBucketed,
|
| "allocation not large enough for direct allocation");
|
| size_t size = kSize - kExtraAllocSize;
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
|
|
| EXPECT_TRUE(ptr);
|
| char* charPtr = reinterpret_cast<char*>(ptr) - kPointerOffset;
|
| @@ -1440,7 +1457,7 @@ TEST(PartitionAllocDeathTest, GuardPages) {
|
| EXPECT_DEATH(*(charPtr - 1) = 'A', "");
|
| EXPECT_DEATH(*(charPtr + size + kExtraAllocSize) = 'A', "");
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| TestShutdown();
|
| }
|
| @@ -1452,290 +1469,291 @@ TEST(PartitionAllocDeathTest, FreeWrongPartitionPage) {
|
|
|
| // This large size will result in a direct mapped allocation with guard
|
| // pages at either end.
|
| - void* ptr = partitionAllocGeneric(genericAllocator.root(),
|
| - kPartitionPageSize * 2, typeName);
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(),
|
| + kPartitionPageSize * 2, type_name);
|
| EXPECT_TRUE(ptr);
|
| char* badPtr = reinterpret_cast<char*>(ptr) + kPartitionPageSize;
|
|
|
| - EXPECT_DEATH(partitionFreeGeneric(genericAllocator.root(), badPtr), "");
|
| + EXPECT_DEATH(PartitionFreeGeneric(generic_allocator.root(), badPtr), "");
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| TestShutdown();
|
| }
|
|
|
| #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
|
|
|
| -// Tests that partitionDumpStatsGeneric and partitionDumpStats runs without
|
| +// Tests that PartitionDumpStatsGeneric and PartitionDumpStats runs without
|
| // crashing and returns non zero values when memory is allocated.
|
| TEST(PartitionAllocTest, DumpMemoryStats) {
|
| TestSetup();
|
| {
|
| - void* ptr = partitionAlloc(allocator.root(), kTestAllocSize, typeName);
|
| + void* ptr = PartitionAlloc(allocator.root(), kTestAllocSize, type_name);
|
| MockPartitionStatsDumper mockStatsDumper;
|
| - partitionDumpStats(allocator.root(), "mock_allocator",
|
| + PartitionDumpStats(allocator.root(), "mock_allocator",
|
| false /* detailed dump */, &mockStatsDumper);
|
| EXPECT_TRUE(mockStatsDumper.IsMemoryAllocationRecorded());
|
|
|
| - partitionFree(ptr);
|
| + PartitionFree(ptr);
|
| }
|
|
|
| // This series of tests checks the active -> empty -> decommitted states.
|
| {
|
| - void* genericPtr = partitionAllocGeneric(genericAllocator.root(),
|
| - 2048 - kExtraAllocSize, typeName);
|
| + void* genericPtr = PartitionAllocGeneric(generic_allocator.root(),
|
| + 2048 - kExtraAllocSize, type_name);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(2048);
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(2048);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(2048u, stats->bucketSlotSize);
|
| - EXPECT_EQ(2048u, stats->activeBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(0u, stats->numFullPages);
|
| - EXPECT_EQ(1u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(2048u, stats->bucket_slot_size);
|
| + EXPECT_EQ(2048u, stats->active_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(0u, stats->num_full_pages);
|
| + EXPECT_EQ(1u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), genericPtr);
|
| + PartitionFreeGeneric(generic_allocator.root(), genericPtr);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_FALSE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(2048);
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(2048);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(2048u, stats->bucketSlotSize);
|
| - EXPECT_EQ(0u, stats->activeBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->residentBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(0u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(1u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(2048u, stats->bucket_slot_size);
|
| + EXPECT_EQ(0u, stats->active_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->resident_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(0u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(1u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| CycleGenericFreeCache(kTestAllocSize);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_FALSE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(2048);
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(2048);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(2048u, stats->bucketSlotSize);
|
| - EXPECT_EQ(0u, stats->activeBytes);
|
| - EXPECT_EQ(0u, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(0u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(1u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(2048u, stats->bucket_slot_size);
|
| + EXPECT_EQ(0u, stats->active_bytes);
|
| + EXPECT_EQ(0u, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(0u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(1u, stats->num_decommitted_pages);
|
| }
|
| }
|
|
|
| // This test checks for correct empty page list accounting.
|
| {
|
| size_t size = kPartitionPageSize - kExtraAllocSize;
|
| - void* ptr1 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + void* ptr1 =
|
| + PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr2 =
|
| + PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
|
|
| CycleGenericFreeCache(kTestAllocSize);
|
|
|
| - ptr1 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + ptr1 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(kPartitionPageSize);
|
| + dumper.GetBucketStats(kPartitionPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(kPartitionPageSize, stats->bucketSlotSize);
|
| - EXPECT_EQ(kPartitionPageSize, stats->activeBytes);
|
| - EXPECT_EQ(kPartitionPageSize, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(1u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(1u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(kPartitionPageSize, stats->bucket_slot_size);
|
| + EXPECT_EQ(kPartitionPageSize, stats->active_bytes);
|
| + EXPECT_EQ(kPartitionPageSize, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(1u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(1u, stats->num_decommitted_pages);
|
| }
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| }
|
|
|
| // This test checks for correct direct mapped accounting.
|
| {
|
| - size_t sizeSmaller = kGenericMaxBucketed + 1;
|
| - size_t sizeBigger = (kGenericMaxBucketed * 2) + 1;
|
| - size_t realSizeSmaller =
|
| - (sizeSmaller + kSystemPageOffsetMask) & kSystemPageBaseMask;
|
| - size_t realSizeBigger =
|
| - (sizeBigger + kSystemPageOffsetMask) & kSystemPageBaseMask;
|
| - void* ptr =
|
| - partitionAllocGeneric(genericAllocator.root(), sizeSmaller, typeName);
|
| + size_t size_smaller = kGenericMaxBucketed + 1;
|
| + size_t size_bigger = (kGenericMaxBucketed * 2) + 1;
|
| + size_t real_size_smaller =
|
| + (size_smaller + kSystemPageOffsetMask) & kSystemPageBaseMask;
|
| + size_t real_size_bigger =
|
| + (size_bigger + kSystemPageOffsetMask) & kSystemPageBaseMask;
|
| + void* ptr = PartitionAllocGeneric(generic_allocator.root(), size_smaller,
|
| + type_name);
|
| void* ptr2 =
|
| - partitionAllocGeneric(genericAllocator.root(), sizeBigger, typeName);
|
| + PartitionAllocGeneric(generic_allocator.root(), size_bigger, type_name);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(realSizeSmaller);
|
| + dumper.GetBucketStats(real_size_smaller);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_TRUE(stats->isDirectMap);
|
| - EXPECT_EQ(realSizeSmaller, stats->bucketSlotSize);
|
| - EXPECT_EQ(realSizeSmaller, stats->activeBytes);
|
| - EXPECT_EQ(realSizeSmaller, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(1u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| -
|
| - stats = mockStatsDumperGeneric.GetBucketStats(realSizeBigger);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_TRUE(stats->is_direct_map);
|
| + EXPECT_EQ(real_size_smaller, stats->bucket_slot_size);
|
| + EXPECT_EQ(real_size_smaller, stats->active_bytes);
|
| + EXPECT_EQ(real_size_smaller, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(1u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| +
|
| + stats = dumper.GetBucketStats(real_size_bigger);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_TRUE(stats->isDirectMap);
|
| - EXPECT_EQ(realSizeBigger, stats->bucketSlotSize);
|
| - EXPECT_EQ(realSizeBigger, stats->activeBytes);
|
| - EXPECT_EQ(realSizeBigger, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(1u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_TRUE(stats->is_direct_map);
|
| + EXPECT_EQ(real_size_bigger, stats->bucket_slot_size);
|
| + EXPECT_EQ(real_size_bigger, stats->active_bytes);
|
| + EXPECT_EQ(real_size_bigger, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(1u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| // Whilst we're here, allocate again and free with different ordering
|
| // to give a workout to our linked list code.
|
| - ptr = partitionAllocGeneric(genericAllocator.root(), sizeSmaller, typeName);
|
| - ptr2 = partitionAllocGeneric(genericAllocator.root(), sizeBigger, typeName);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + ptr = PartitionAllocGeneric(generic_allocator.root(), size_smaller,
|
| + type_name);
|
| + ptr2 =
|
| + PartitionAllocGeneric(generic_allocator.root(), size_bigger, type_name);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| }
|
|
|
| // This test checks large-but-not-quite-direct allocations.
|
| {
|
| void* ptr =
|
| - partitionAllocGeneric(genericAllocator.root(), 65536 + 1, typeName);
|
| + PartitionAllocGeneric(generic_allocator.root(), 65536 + 1, type_name);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| + size_t slot_size = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(slotSize);
|
| + dumper.GetBucketStats(slot_size);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_FALSE(stats->isDirectMap);
|
| - EXPECT_EQ(slotSize, stats->bucketSlotSize);
|
| - EXPECT_EQ(65536u + 1 + kExtraAllocSize, stats->activeBytes);
|
| - EXPECT_EQ(slotSize, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(1u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_FALSE(stats->is_direct_map);
|
| + EXPECT_EQ(slot_size, stats->bucket_slot_size);
|
| + EXPECT_EQ(65536u + 1 + kExtraAllocSize, stats->active_bytes);
|
| + EXPECT_EQ(slot_size, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(1u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_FALSE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| + size_t slot_size = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(slotSize);
|
| + dumper.GetBucketStats(slot_size);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_FALSE(stats->isDirectMap);
|
| - EXPECT_EQ(slotSize, stats->bucketSlotSize);
|
| - EXPECT_EQ(0u, stats->activeBytes);
|
| - EXPECT_EQ(slotSize, stats->residentBytes);
|
| - EXPECT_EQ(slotSize, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(1u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_FALSE(stats->is_direct_map);
|
| + EXPECT_EQ(slot_size, stats->bucket_slot_size);
|
| + EXPECT_EQ(0u, stats->active_bytes);
|
| + EXPECT_EQ(slot_size, stats->resident_bytes);
|
| + EXPECT_EQ(slot_size, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(1u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(),
|
| - 65536 + kSystemPageSize + 1, typeName);
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(),
|
| + 65536 + kSystemPageSize + 1, type_name);
|
| EXPECT_EQ(ptr, ptr2);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| + size_t slot_size = 65536 + (65536 / kGenericNumBucketsPerOrder);
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(slotSize);
|
| + dumper.GetBucketStats(slot_size);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_FALSE(stats->isDirectMap);
|
| - EXPECT_EQ(slotSize, stats->bucketSlotSize);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_FALSE(stats->is_direct_map);
|
| + EXPECT_EQ(slot_size, stats->bucket_slot_size);
|
| EXPECT_EQ(65536u + kSystemPageSize + 1 + kExtraAllocSize,
|
| - stats->activeBytes);
|
| - EXPECT_EQ(slotSize, stats->residentBytes);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->discardableBytes);
|
| - EXPECT_EQ(1u, stats->numFullPages);
|
| - EXPECT_EQ(0u, stats->numActivePages);
|
| - EXPECT_EQ(0u, stats->numEmptyPages);
|
| - EXPECT_EQ(0u, stats->numDecommittedPages);
|
| + stats->active_bytes);
|
| + EXPECT_EQ(slot_size, stats->resident_bytes);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->discardable_bytes);
|
| + EXPECT_EQ(1u, stats->num_full_pages);
|
| + EXPECT_EQ(0u, stats->num_active_pages);
|
| + EXPECT_EQ(0u, stats->num_empty_pages);
|
| + EXPECT_EQ(0u, stats->num_decommitted_pages);
|
| }
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| }
|
|
|
| TestShutdown();
|
| @@ -1745,48 +1763,46 @@ TEST(PartitionAllocTest, DumpMemoryStats) {
|
| TEST(PartitionAllocTest, Purge) {
|
| TestSetup();
|
|
|
| - char* ptr = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), 2048 - kExtraAllocSize, typeName));
|
| - partitionFreeGeneric(genericAllocator.root(), ptr);
|
| + char* ptr = reinterpret_cast<char*>(PartitionAllocGeneric(
|
| + generic_allocator.root(), 2048 - kExtraAllocSize, type_name));
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */,
|
| - &mockStatsDumperGeneric);
|
| - EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| -
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(2048);
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_FALSE(dumper.IsMemoryAllocationRecorded());
|
| +
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(2048);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(kSystemPageSize, stats->decommittableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(kSystemPageSize, stats->decommittable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->resident_bytes);
|
| }
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDecommitEmptyPages);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */,
|
| - &mockStatsDumperGeneric);
|
| - EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| -
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(2048);
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_FALSE(dumper.IsMemoryAllocationRecorded());
|
| +
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(2048);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(0u, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(0u, stats->resident_bytes);
|
| }
|
| // Calling purge again here is a good way of testing we didn't mess up the
|
| // state of the free cache ring.
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDecommitEmptyPages);
|
|
|
| char* bigPtr = reinterpret_cast<char*>(
|
| - partitionAllocGeneric(genericAllocator.root(), 256 * 1024, typeName));
|
| - partitionFreeGeneric(genericAllocator.root(), bigPtr);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionAllocGeneric(generic_allocator.root(), 256 * 1024, type_name));
|
| + PartitionFreeGeneric(generic_allocator.root(), bigPtr);
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDecommitEmptyPages);
|
|
|
| CheckPageInCore(ptr - kPointerOffset, false);
|
| @@ -1805,47 +1821,47 @@ TEST(PartitionAllocTest, PreferActiveOverEmpty) {
|
| // Allocate 3 full slot spans worth of 8192-byte allocations.
|
| // Each slot span for this size is 16384 bytes, or 1 partition page and 2
|
| // slots.
|
| - void* ptr1 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr3 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr4 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr5 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| - void* ptr6 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr1 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr3 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr4 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr5 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| + void* ptr6 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
|
|
| PartitionPage* page1 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr1));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr1));
|
| PartitionPage* page2 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr3));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr3));
|
| PartitionPage* page3 =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr6));
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr6));
|
| EXPECT_NE(page1, page2);
|
| EXPECT_NE(page2, page3);
|
| PartitionBucket* bucket = page1->bucket;
|
| - EXPECT_EQ(page3, bucket->activePagesHead);
|
| + EXPECT_EQ(page3, bucket->active_pages_head);
|
|
|
| // Free up the 2nd slot in each slot span.
|
| // This leaves the active list containing 3 pages, each with 1 used and 1
|
| // free slot. The active page will be the one containing ptr1.
|
| - partitionFreeGeneric(genericAllocator.root(), ptr6);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr4);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr6);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr4);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
|
|
| // Empty the middle page in the active list.
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| - EXPECT_EQ(page1, bucket->activePagesHead);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| + EXPECT_EQ(page1, bucket->active_pages_head);
|
|
|
| // Empty the the first page in the active list -- also the current page.
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
|
|
| // A good choice here is to re-fill the third page since the first two are
|
| // empty. We used to fail that.
|
| - void* ptr7 = partitionAllocGeneric(genericAllocator.root(), size, typeName);
|
| + void* ptr7 = PartitionAllocGeneric(generic_allocator.root(), size, type_name);
|
| EXPECT_EQ(ptr6, ptr7);
|
| - EXPECT_EQ(page3, bucket->activePagesHead);
|
| + EXPECT_EQ(page3, bucket->active_pages_head);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr5);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr7);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr5);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr7);
|
|
|
| TestShutdown();
|
| }
|
| @@ -1856,103 +1872,104 @@ TEST(PartitionAllocTest, PurgeDiscardable) {
|
|
|
| // Free the second of two 4096 byte allocations and then purge.
|
| {
|
| - void* ptr1 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - char* ptr2 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName));
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + void* ptr1 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + char* ptr2 = reinterpret_cast<char*>(
|
| + PartitionAllocGeneric(generic_allocator.root(),
|
| + kSystemPageSize - kExtraAllocSize, type_name));
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr1));
|
| - EXPECT_EQ(2u, page->numUnprovisionedSlots);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr1));
|
| + EXPECT_EQ(2u, page->num_unprovisioned_slots);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(kSystemPageSize);
|
| + dumper.GetBucketStats(kSystemPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->activeBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->active_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr2 - kPointerOffset, true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| CheckPageInCore(ptr2 - kPointerOffset, false);
|
| - EXPECT_EQ(3u, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(3u, page->num_unprovisioned_slots);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| }
|
| // Free the first of two 4096 byte allocations and then purge.
|
| {
|
| - char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName));
|
| - void* ptr2 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + char* ptr1 = reinterpret_cast<char*>(
|
| + PartitionAllocGeneric(generic_allocator.root(),
|
| + kSystemPageSize - kExtraAllocSize, type_name));
|
| + void* ptr2 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(kSystemPageSize);
|
| + dumper.GetBucketStats(kSystemPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->activeBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->active_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| CheckPageInCore(ptr1 - kPointerOffset, false);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| }
|
| {
|
| - char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), 9216 - kExtraAllocSize, typeName));
|
| - void* ptr2 = partitionAllocGeneric(genericAllocator.root(),
|
| - 9216 - kExtraAllocSize, typeName);
|
| - void* ptr3 = partitionAllocGeneric(genericAllocator.root(),
|
| - 9216 - kExtraAllocSize, typeName);
|
| - void* ptr4 = partitionAllocGeneric(genericAllocator.root(),
|
| - 9216 - kExtraAllocSize, typeName);
|
| + char* ptr1 = reinterpret_cast<char*>(PartitionAllocGeneric(
|
| + generic_allocator.root(), 9216 - kExtraAllocSize, type_name));
|
| + void* ptr2 = PartitionAllocGeneric(generic_allocator.root(),
|
| + 9216 - kExtraAllocSize, type_name);
|
| + void* ptr3 = PartitionAllocGeneric(generic_allocator.root(),
|
| + 9216 - kExtraAllocSize, type_name);
|
| + void* ptr4 = PartitionAllocGeneric(generic_allocator.root(),
|
| + 9216 - kExtraAllocSize, type_name);
|
| memset(ptr1, 'A', 9216 - kExtraAllocSize);
|
| memset(ptr2, 'A', 9216 - kExtraAllocSize);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| - const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(9216);
|
| + const PartitionBucketMemoryStats* stats = dumper.GetBucketStats(9216);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(9216u * 2, stats->activeBytes);
|
| - EXPECT_EQ(9 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(9216u * 2, stats->active_bytes);
|
| + EXPECT_EQ(9 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, false);
|
| @@ -1960,166 +1977,168 @@ TEST(PartitionAllocTest, PurgeDiscardable) {
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr4);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr4);
|
| }
|
| {
|
| - char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), (64 * kSystemPageSize) - kExtraAllocSize,
|
| - typeName));
|
| + char* ptr1 = reinterpret_cast<char*>(PartitionAllocGeneric(
|
| + generic_allocator.root(), (64 * kSystemPageSize) - kExtraAllocSize,
|
| + type_name));
|
| memset(ptr1, 'A', (64 * kSystemPageSize) - kExtraAllocSize);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| - ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), (61 * kSystemPageSize) - kExtraAllocSize,
|
| - typeName));
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| + ptr1 = reinterpret_cast<char*>(PartitionAllocGeneric(
|
| + generic_allocator.root(), (61 * kSystemPageSize) - kExtraAllocSize,
|
| + type_name));
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(64 * kSystemPageSize);
|
| + dumper.GetBucketStats(64 * kSystemPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(3 * kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(61 * kSystemPageSize, stats->activeBytes);
|
| - EXPECT_EQ(64 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(3 * kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(61 * kSystemPageSize, stats->active_bytes);
|
| + EXPECT_EQ(64 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), false);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), false);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), false);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| }
|
| // This sub-test tests truncation of the provisioned slots in a trickier
|
| // case where the freelist is rewritten.
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDecommitEmptyPages);
|
| {
|
| - char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName));
|
| - void* ptr2 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - void* ptr3 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - void* ptr4 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| + char* ptr1 = reinterpret_cast<char*>(
|
| + PartitionAllocGeneric(generic_allocator.root(),
|
| + kSystemPageSize - kExtraAllocSize, type_name));
|
| + void* ptr2 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + void* ptr3 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + void* ptr4 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| ptr1[0] = 'A';
|
| ptr1[kSystemPageSize] = 'A';
|
| ptr1[kSystemPageSize * 2] = 'A';
|
| ptr1[kSystemPageSize * 3] = 'A';
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr1));
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr4);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| - EXPECT_EQ(0u, page->numUnprovisionedSlots);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr1));
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr4);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| + EXPECT_EQ(0u, page->num_unprovisioned_slots);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(kSystemPageSize);
|
| + dumper.GetBucketStats(kSystemPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(kSystemPageSize, stats->activeBytes);
|
| - EXPECT_EQ(4 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(kSystemPageSize, stats->active_bytes);
|
| + EXPECT_EQ(4 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| - EXPECT_EQ(1u, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(1u, page->num_unprovisioned_slots);
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, false);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false);
|
|
|
| // Let's check we didn't brick the freelist.
|
| - void* ptr1b = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| + void* ptr1b = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| EXPECT_EQ(ptr1, ptr1b);
|
| - void* ptr2b = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| + void* ptr2b = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| EXPECT_EQ(ptr2, ptr2b);
|
| - EXPECT_FALSE(page->freelistHead);
|
| + EXPECT_FALSE(page->freelist_head);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| }
|
| // This sub-test is similar, but tests a double-truncation.
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDecommitEmptyPages);
|
| {
|
| - char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName));
|
| - void* ptr2 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - void* ptr3 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| - void* ptr4 = partitionAllocGeneric(
|
| - genericAllocator.root(), kSystemPageSize - kExtraAllocSize, typeName);
|
| + char* ptr1 = reinterpret_cast<char*>(
|
| + PartitionAllocGeneric(generic_allocator.root(),
|
| + kSystemPageSize - kExtraAllocSize, type_name));
|
| + void* ptr2 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + void* ptr3 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| + void* ptr4 = PartitionAllocGeneric(
|
| + generic_allocator.root(), kSystemPageSize - kExtraAllocSize, type_name);
|
| ptr1[0] = 'A';
|
| ptr1[kSystemPageSize] = 'A';
|
| ptr1[kSystemPageSize * 2] = 'A';
|
| ptr1[kSystemPageSize * 3] = 'A';
|
| PartitionPage* page =
|
| - partitionPointerToPage(partitionCookieFreePointerAdjust(ptr1));
|
| - partitionFreeGeneric(genericAllocator.root(), ptr4);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr3);
|
| - EXPECT_EQ(0u, page->numUnprovisionedSlots);
|
| + PartitionPointerToPage(PartitionCookieFreePointerAdjust(ptr1));
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr4);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr3);
|
| + EXPECT_EQ(0u, page->num_unprovisioned_slots);
|
|
|
| {
|
| - MockPartitionStatsDumper mockStatsDumperGeneric;
|
| - partitionDumpStatsGeneric(
|
| - genericAllocator.root(), "mock_generic_allocator",
|
| - false /* detailed dump */, &mockStatsDumperGeneric);
|
| - EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
|
| + MockPartitionStatsDumper dumper;
|
| + PartitionDumpStatsGeneric(generic_allocator.root(),
|
| + "mock_generic_allocator",
|
| + false /* detailed dump */, &dumper);
|
| + EXPECT_TRUE(dumper.IsMemoryAllocationRecorded());
|
|
|
| const PartitionBucketMemoryStats* stats =
|
| - mockStatsDumperGeneric.GetBucketStats(kSystemPageSize);
|
| + dumper.GetBucketStats(kSystemPageSize);
|
| EXPECT_TRUE(stats);
|
| - EXPECT_TRUE(stats->isValid);
|
| - EXPECT_EQ(0u, stats->decommittableBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->discardableBytes);
|
| - EXPECT_EQ(2 * kSystemPageSize, stats->activeBytes);
|
| - EXPECT_EQ(4 * kSystemPageSize, stats->residentBytes);
|
| + EXPECT_TRUE(stats->is_valid);
|
| + EXPECT_EQ(0u, stats->decommittable_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->discardable_bytes);
|
| + EXPECT_EQ(2 * kSystemPageSize, stats->active_bytes);
|
| + EXPECT_EQ(4 * kSystemPageSize, stats->resident_bytes);
|
| }
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), true);
|
| - partitionPurgeMemoryGeneric(genericAllocator.root(),
|
| + PartitionPurgeMemoryGeneric(generic_allocator.root(),
|
| PartitionPurgeDiscardUnusedSystemPages);
|
| - EXPECT_EQ(2u, page->numUnprovisionedSlots);
|
| + EXPECT_EQ(2u, page->num_unprovisioned_slots);
|
| CheckPageInCore(ptr1 - kPointerOffset, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), false);
|
| CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false);
|
|
|
| - EXPECT_FALSE(page->freelistHead);
|
| + EXPECT_FALSE(page->freelist_head);
|
|
|
| - partitionFreeGeneric(genericAllocator.root(), ptr1);
|
| - partitionFreeGeneric(genericAllocator.root(), ptr2);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr1);
|
| + PartitionFreeGeneric(generic_allocator.root(), ptr2);
|
| }
|
|
|
| TestShutdown();
|
|
|