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

Unified Diff: Source/wtf/PartitionAllocTest.cpp

Issue 169523004: Add partitionAllocGetSize() for determining actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: adjust test sizes, and reword/fix 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.h ('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 aef6f5c86b35ca3d8c32e08be56288b9d716ef1f..232c85a208224a8f22f9283c66e898dd0be13c1a 100644
--- a/Source/wtf/PartitionAllocTest.cpp
+++ b/Source/wtf/PartitionAllocTest.cpp
@@ -574,6 +574,56 @@ TEST(WTF_PartitionAlloc, GenericAllocSizes)
TestShutdown();
}
+// Test that we can fetch the real allocated size after an allocation.
+TEST(WTF_PartitionAlloc, GenericAllocGetSize)
+{
+ TestSetup();
+
+ void* ptr;
+ size_t requestedSize, actualSize;
+
+ EXPECT_TRUE(partitionAllocSupportsGetSize());
+
+ // Allocate something small.
+ requestedSize = 511 - kExtraAllocSize;
+ ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
+ EXPECT_TRUE(ptr);
+ actualSize = partitionAllocGetSize(ptr);
+ 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;
+ ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
+ EXPECT_TRUE(ptr);
+ actualSize = partitionAllocGetSize(ptr);
+ 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;
+ ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
+ EXPECT_TRUE(ptr);
+ actualSize = partitionAllocGetSize(ptr);
+ 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);
+ *(charPtr + (actualSize - 1)) = 'A';
+ partitionFreeGeneric(genericAllocator.root(), ptr);
+
+ // Allocate something very large, and uneven.
+ requestedSize = 512 * 1024 * 1024 - 1;
+ ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize);
+ EXPECT_TRUE(ptr);
+ actualSize = partitionAllocGetSize(ptr);
+ EXPECT_LT(requestedSize, actualSize);
+ partitionFreeGeneric(genericAllocator.root(), ptr);
+
+ TestShutdown();
+}
+
// Test the realloc() contract.
TEST(WTF_PartitionAlloc, Realloc)
{
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698