| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 983 } |
| 984 | 984 |
| 985 TestShutdown(); | 985 TestShutdown(); |
| 986 } | 986 } |
| 987 | 987 |
| 988 // Tests that pages in the free page cache do get freed as appropriate. | 988 // Tests that pages in the free page cache do get freed as appropriate. |
| 989 TEST(PartitionAllocTest, FreeCache) | 989 TEST(PartitionAllocTest, FreeCache) |
| 990 { | 990 { |
| 991 TestSetup(); | 991 TestSetup(); |
| 992 | 992 |
| 993 EXPECT_EQ(0U, allocator.root()->totalSizeOfCommittedPages); |
| 994 |
| 993 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize; | 995 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize; |
| 994 size_t bucketIdx = (bigSize + kExtraAllocSize) >> WTF::kBucketShift; | 996 size_t bucketIdx = (bigSize + kExtraAllocSize) >> WTF::kBucketShift; |
| 995 WTF::PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx]; | 997 WTF::PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx]; |
| 996 | 998 |
| 997 void* ptr = partitionAlloc(allocator.root(), bigSize); | 999 void* ptr = partitionAlloc(allocator.root(), bigSize); |
| 998 EXPECT_TRUE(ptr); | 1000 EXPECT_TRUE(ptr); |
| 999 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF
reePointerAdjust(ptr)); | 1001 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF
reePointerAdjust(ptr)); |
| 1000 EXPECT_EQ(0, bucket->freePagesHead); | 1002 EXPECT_EQ(0, bucket->freePagesHead); |
| 1001 EXPECT_EQ(1, page->numAllocatedSlots); | 1003 EXPECT_EQ(1, page->numAllocatedSlots); |
| 1004 EXPECT_EQ(WTF::kPartitionPageSize, allocator.root()->totalSizeOfCommittedPag
es); |
| 1002 partitionFree(ptr); | 1005 partitionFree(ptr); |
| 1003 EXPECT_EQ(0, page->numAllocatedSlots); | 1006 EXPECT_EQ(0, page->numAllocatedSlots); |
| 1004 EXPECT_NE(-1, page->freeCacheIndex); | 1007 EXPECT_NE(-1, page->freeCacheIndex); |
| 1005 EXPECT_TRUE(page->freelistHead); | 1008 EXPECT_TRUE(page->freelistHead); |
| 1006 | 1009 |
| 1007 CycleFreeCache(kTestAllocSize); | 1010 CycleFreeCache(kTestAllocSize); |
| 1008 | 1011 |
| 1009 // Flushing the cache should have really freed the unused page. | 1012 // Flushing the cache should have really freed the unused page. |
| 1010 EXPECT_FALSE(page->freelistHead); | 1013 EXPECT_FALSE(page->freelistHead); |
| 1011 EXPECT_EQ(-1, page->freeCacheIndex); | 1014 EXPECT_EQ(-1, page->freeCacheIndex); |
| 1012 EXPECT_EQ(0, page->numAllocatedSlots); | 1015 EXPECT_EQ(0, page->numAllocatedSlots); |
| 1016 WTF::PartitionBucket* cycleFreeCacheBucket = &allocator.root()->buckets()[kT
estBucketIndex]; |
| 1017 EXPECT_EQ(cycleFreeCacheBucket->numSystemPagesPerSlotSpan * WTF::kSystemPage
Size, allocator.root()->totalSizeOfCommittedPages); |
| 1013 | 1018 |
| 1014 // Check that an allocation works ok whilst in this state (a free'd page | 1019 // Check that an allocation works ok whilst in this state (a free'd page |
| 1015 // as the active pages head). | 1020 // as the active pages head). |
| 1016 ptr = partitionAlloc(allocator.root(), bigSize); | 1021 ptr = partitionAlloc(allocator.root(), bigSize); |
| 1017 EXPECT_FALSE(bucket->freePagesHead); | 1022 EXPECT_FALSE(bucket->freePagesHead); |
| 1018 partitionFree(ptr); | 1023 partitionFree(ptr); |
| 1019 | 1024 |
| 1020 // Also check that a page that is bouncing immediately between empty and | 1025 // Also check that a page that is bouncing immediately between empty and |
| 1021 // used does not get freed. | 1026 // used does not get freed. |
| 1022 for (size_t i = 0; i < WTF::kMaxFreeableSpans * 2; ++i) { | 1027 for (size_t i = 0; i < WTF::kMaxFreeableSpans * 2; ++i) { |
| 1023 ptr = partitionAlloc(allocator.root(), bigSize); | 1028 ptr = partitionAlloc(allocator.root(), bigSize); |
| 1024 EXPECT_TRUE(page->freelistHead); | 1029 EXPECT_TRUE(page->freelistHead); |
| 1025 partitionFree(ptr); | 1030 partitionFree(ptr); |
| 1026 EXPECT_TRUE(page->freelistHead); | 1031 EXPECT_TRUE(page->freelistHead); |
| 1027 } | 1032 } |
| 1028 | 1033 EXPECT_EQ(WTF::kPartitionPageSize, allocator.root()->totalSizeOfCommittedPag
es); |
| 1029 TestShutdown(); | 1034 TestShutdown(); |
| 1030 } | 1035 } |
| 1031 | 1036 |
| 1032 // Tests for a bug we had with losing references to free pages. | 1037 // Tests for a bug we had with losing references to free pages. |
| 1033 TEST(PartitionAllocTest, LostFreePagesBug) | 1038 TEST(PartitionAllocTest, LostFreePagesBug) |
| 1034 { | 1039 { |
| 1035 TestSetup(); | 1040 TestSetup(); |
| 1036 | 1041 |
| 1037 size_t size = WTF::kPartitionPageSize - kExtraAllocSize; | 1042 size_t size = WTF::kPartitionPageSize - kExtraAllocSize; |
| 1038 | 1043 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); | 1188 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); |
| 1184 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); | 1189 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); |
| 1185 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); | 1190 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); |
| 1186 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); | 1191 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); |
| 1187 #endif | 1192 #endif |
| 1188 } | 1193 } |
| 1189 | 1194 |
| 1190 } // namespace | 1195 } // namespace |
| 1191 | 1196 |
| 1192 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1197 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| OLD | NEW |