Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2049)

Unified Diff: Source/wtf/PartitionAllocTest.cpp

Issue 172533004: Add partitionAllocActualSize() for predicting actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressing review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/PartitionAllocTest.cpp
diff --git a/Source/wtf/PartitionAllocTest.cpp b/Source/wtf/PartitionAllocTest.cpp
index fc1c1e85cc62df2e04d12ab8f5ae168445582ed4..49af4635a39d32d43947c3f5d77ca52f10e086a4 100644
--- a/Source/wtf/PartitionAllocTest.cpp
+++ b/Source/wtf/PartitionAllocTest.cpp
@@ -593,33 +593,39 @@ TEST(WTF_PartitionAlloc, GenericAllocGetSize)
TestSetup();
void* ptr;
- size_t requestedSize, actualSize;
+ size_t requestedSize, actualSize, predictedSize;
EXPECT_TRUE(partitionAllocSupportsGetSize());
// Allocate something small.
requestedSize = 511 - kExtraAllocSize;
+ predictedSize = partitionAllocActualSize(genericAllocator.root(), requestedSize);
ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
EXPECT_TRUE(ptr);
actualSize = partitionAllocGetSize(ptr);
+ EXPECT_EQ(predictedSize, actualSize);
EXPECT_LT(requestedSize, actualSize);
partitionFreeGeneric(genericAllocator.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);
EXPECT_TRUE(ptr);
actualSize = partitionAllocGetSize(ptr);
+ EXPECT_EQ(predictedSize, actualSize);
EXPECT_EQ(requestedSize, actualSize);
partitionFreeGeneric(genericAllocator.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) - WTF::kSystemPageSize - kExtraAllocSize;
+ predictedSize = partitionAllocActualSize(genericAllocator.root(), requestedSize);
ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
EXPECT_TRUE(ptr);
actualSize = partitionAllocGetSize(ptr);
+ EXPECT_EQ(predictedSize, actualSize);
EXPECT_EQ(requestedSize + WTF::kSystemPageSize, actualSize);
// Check that we can write at the end of the reported size too.
char* charPtr = reinterpret_cast<char*>(ptr);
@@ -628,12 +634,19 @@ TEST(WTF_PartitionAlloc, GenericAllocGetSize)
// Allocate something very large, and uneven.
requestedSize = 512 * 1024 * 1024 - 1;
+ predictedSize = partitionAllocActualSize(genericAllocator.root(), requestedSize);
ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
EXPECT_TRUE(ptr);
actualSize = partitionAllocGetSize(ptr);
+ EXPECT_EQ(predictedSize, actualSize);
EXPECT_LT(requestedSize, actualSize);
partitionFreeGeneric(genericAllocator.root(), ptr);
+ // Too large allocation.
+ requestedSize = INT_MAX;
+ predictedSize = partitionAllocActualSize(genericAllocator.root(), requestedSize);
+ EXPECT_EQ(requestedSize, predictedSize);
+
TestShutdown();
}
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698