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 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "wtf/allocator/PartitionAlloc.h" | 31 #include "wtf/allocator/PartitionAlloc.h" |
32 | 32 |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "wtf/BitwiseOperations.h" | 34 #include "wtf/BitwiseOperations.h" |
35 #include "wtf/CPU.h" | 35 #include "wtf/CPU.h" |
36 #include "wtf/PtrUtil.h" | 36 #include "wtf/OwnPtr.h" |
| 37 #include "wtf/PassOwnPtr.h" |
37 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
38 #include <memory> | |
39 #include <stdlib.h> | 39 #include <stdlib.h> |
40 #include <string.h> | 40 #include <string.h> |
41 | 41 |
42 #if OS(POSIX) | 42 #if OS(POSIX) |
43 #include <sys/mman.h> | 43 #include <sys/mman.h> |
44 #include <sys/resource.h> | 44 #include <sys/resource.h> |
45 #include <sys/time.h> | 45 #include <sys/time.h> |
46 | 46 |
47 #ifndef MAP_ANONYMOUS | 47 #ifndef MAP_ANONYMOUS |
48 #define MAP_ANONYMOUS MAP_ANON | 48 #define MAP_ANONYMOUS MAP_ANON |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 // free page list metadata bucket. | 440 // free page list metadata bucket. |
441 TEST(PartitionAllocTest, FreePageListPageTransitions) | 441 TEST(PartitionAllocTest, FreePageListPageTransitions) |
442 { | 442 { |
443 TestSetup(); | 443 TestSetup(); |
444 PartitionBucket* bucket = &allocator.root()->buckets()[kTestBucketIndex]; | 444 PartitionBucket* bucket = &allocator.root()->buckets()[kTestBucketIndex]; |
445 | 445 |
446 size_t numToFillFreeListPage = kPartitionPageSize / (sizeof(PartitionPage) +
kExtraAllocSize); | 446 size_t numToFillFreeListPage = kPartitionPageSize / (sizeof(PartitionPage) +
kExtraAllocSize); |
447 // The +1 is because we need to account for the fact that the current page | 447 // The +1 is because we need to account for the fact that the current page |
448 // never gets thrown on the freelist. | 448 // never gets thrown on the freelist. |
449 ++numToFillFreeListPage; | 449 ++numToFillFreeListPage; |
450 std::unique_ptr<PartitionPage*[]> pages = wrapArrayUnique(new PartitionPage*
[numToFillFreeListPage]); | 450 OwnPtr<PartitionPage*[]> pages = adoptArrayPtr(new PartitionPage*[numToFillF
reeListPage]); |
451 | 451 |
452 size_t i; | 452 size_t i; |
453 for (i = 0; i < numToFillFreeListPage; ++i) { | 453 for (i = 0; i < numToFillFreeListPage; ++i) { |
454 pages[i] = GetFullPage(kTestAllocSize); | 454 pages[i] = GetFullPage(kTestAllocSize); |
455 } | 455 } |
456 EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->activePagesHead); | 456 EXPECT_EQ(pages[numToFillFreeListPage - 1], bucket->activePagesHead); |
457 for (i = 0; i < numToFillFreeListPage; ++i) | 457 for (i = 0; i < numToFillFreeListPage; ++i) |
458 FreeFullPage(pages[i]); | 458 FreeFullPage(pages[i]); |
459 EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead); | 459 EXPECT_EQ(&PartitionRootGeneric::gSeedPage, bucket->activePagesHead); |
460 EXPECT_TRUE(bucket->emptyPagesHead); | 460 EXPECT_TRUE(bucket->emptyPagesHead); |
(...skipping 25 matching lines...) Expand all Loading... |
486 { | 486 { |
487 TestSetup(); | 487 TestSetup(); |
488 // This is guaranteed to cross a super page boundary because the first | 488 // This is guaranteed to cross a super page boundary because the first |
489 // partition page "slot" will be taken up by a guard page. | 489 // partition page "slot" will be taken up by a guard page. |
490 size_t numPagesNeeded = kNumPartitionPagesPerSuperPage; | 490 size_t numPagesNeeded = kNumPartitionPagesPerSuperPage; |
491 // The super page should begin and end in a guard so we one less page in | 491 // The super page should begin and end in a guard so we one less page in |
492 // order to allocate a single page in the new super page. | 492 // order to allocate a single page in the new super page. |
493 --numPagesNeeded; | 493 --numPagesNeeded; |
494 | 494 |
495 EXPECT_GT(numPagesNeeded, 1u); | 495 EXPECT_GT(numPagesNeeded, 1u); |
496 std::unique_ptr<PartitionPage*[]> pages; | 496 OwnPtr<PartitionPage*[]> pages; |
497 pages = wrapArrayUnique(new PartitionPage*[numPagesNeeded]); | 497 pages = adoptArrayPtr(new PartitionPage*[numPagesNeeded]); |
498 uintptr_t firstSuperPageBase = 0; | 498 uintptr_t firstSuperPageBase = 0; |
499 size_t i; | 499 size_t i; |
500 for (i = 0; i < numPagesNeeded; ++i) { | 500 for (i = 0; i < numPagesNeeded; ++i) { |
501 pages[i] = GetFullPage(kTestAllocSize); | 501 pages[i] = GetFullPage(kTestAllocSize); |
502 void* storagePtr = partitionPageToPointer(pages[i]); | 502 void* storagePtr = partitionPageToPointer(pages[i]); |
503 if (!i) | 503 if (!i) |
504 firstSuperPageBase = reinterpret_cast<uintptr_t>(storagePtr) & kSupe
rPageBaseMask; | 504 firstSuperPageBase = reinterpret_cast<uintptr_t>(storagePtr) & kSupe
rPageBaseMask; |
505 if (i == numPagesNeeded - 1) { | 505 if (i == numPagesNeeded - 1) { |
506 uintptr_t secondSuperPageBase = reinterpret_cast<uintptr_t>(storageP
tr) & kSuperPageBaseMask; | 506 uintptr_t secondSuperPageBase = reinterpret_cast<uintptr_t>(storageP
tr) & kSuperPageBaseMask; |
507 uintptr_t secondSuperPageOffset = reinterpret_cast<uintptr_t>(storag
ePtr) & kSuperPageOffsetMask; | 507 uintptr_t secondSuperPageOffset = reinterpret_cast<uintptr_t>(storag
ePtr) & kSuperPageOffsetMask; |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 TestShutdown(); | 1019 TestShutdown(); |
1020 } | 1020 } |
1021 | 1021 |
1022 // Test correct handling if our mapping collides with another. | 1022 // Test correct handling if our mapping collides with another. |
1023 TEST(PartitionAllocTest, MappingCollision) | 1023 TEST(PartitionAllocTest, MappingCollision) |
1024 { | 1024 { |
1025 TestSetup(); | 1025 TestSetup(); |
1026 // The -2 is because the first and last partition pages in a super page are | 1026 // The -2 is because the first and last partition pages in a super page are |
1027 // guard pages. | 1027 // guard pages. |
1028 size_t numPartitionPagesNeeded = kNumPartitionPagesPerSuperPage - 2; | 1028 size_t numPartitionPagesNeeded = kNumPartitionPagesPerSuperPage - 2; |
1029 std::unique_ptr<PartitionPage*[]> firstSuperPagePages = wrapArrayUnique(new
PartitionPage*[numPartitionPagesNeeded]); | 1029 OwnPtr<PartitionPage*[]> firstSuperPagePages = adoptArrayPtr(new PartitionPa
ge*[numPartitionPagesNeeded]); |
1030 std::unique_ptr<PartitionPage*[]> secondSuperPagePages = wrapArrayUnique(new
PartitionPage*[numPartitionPagesNeeded]); | 1030 OwnPtr<PartitionPage*[]> secondSuperPagePages = adoptArrayPtr(new PartitionP
age*[numPartitionPagesNeeded]); |
1031 | 1031 |
1032 size_t i; | 1032 size_t i; |
1033 for (i = 0; i < numPartitionPagesNeeded; ++i) | 1033 for (i = 0; i < numPartitionPagesNeeded; ++i) |
1034 firstSuperPagePages[i] = GetFullPage(kTestAllocSize); | 1034 firstSuperPagePages[i] = GetFullPage(kTestAllocSize); |
1035 | 1035 |
1036 char* pageBase = reinterpret_cast<char*>(partitionPageToPointer(firstSuperPa
gePages[0])); | 1036 char* pageBase = reinterpret_cast<char*>(partitionPageToPointer(firstSuperPa
gePages[0])); |
1037 EXPECT_EQ(kPartitionPageSize, reinterpret_cast<uintptr_t>(pageBase) & kSuper
PageOffsetMask); | 1037 EXPECT_EQ(kPartitionPageSize, reinterpret_cast<uintptr_t>(pageBase) & kSuper
PageOffsetMask); |
1038 pageBase -= kPartitionPageSize; | 1038 pageBase -= kPartitionPageSize; |
1039 // Map a single system page either side of the mapping for our allocations, | 1039 // Map a single system page either side of the mapping for our allocations, |
1040 // with the goal of tripping up alignment of the next mapping. | 1040 // with the goal of tripping up alignment of the next mapping. |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); | 1958 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); |
1959 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); | 1959 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); |
1960 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); | 1960 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); |
1961 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); | 1961 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); |
1962 #endif | 1962 #endif |
1963 } | 1963 } |
1964 | 1964 |
1965 } // namespace WTF | 1965 } // namespace WTF |
1966 | 1966 |
1967 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1967 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |