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

Side by Side Diff: Source/wtf/PartitionAllocTest.cpp

Issue 1195543005: PartitionAlloc: fixes and improvements to large-chunk size tracking. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review feedback. Created 5 years, 6 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 unified diff | Download patch
« Source/wtf/PartitionAlloc.cpp ('K') | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // We only run the check when asserts are disabled because when they are 644 // We only run the check when asserts are disabled because when they are
645 // enabled, the allocated area is overwritten with an "uninitialized" 645 // enabled, the allocated area is overwritten with an "uninitialized"
646 // byte pattern. 646 // byte pattern.
647 EXPECT_EQ(0, *(reinterpret_cast<char*>(newPtr) + (size - 1))); 647 EXPECT_EQ(0, *(reinterpret_cast<char*>(newPtr) + (size - 1)));
648 #endif 648 #endif
649 partitionFreeGeneric(genericAllocator.root(), newPtr); 649 partitionFreeGeneric(genericAllocator.root(), newPtr);
650 partitionFreeGeneric(genericAllocator.root(), ptr3); 650 partitionFreeGeneric(genericAllocator.root(), ptr3);
651 partitionFreeGeneric(genericAllocator.root(), ptr4); 651 partitionFreeGeneric(genericAllocator.root(), ptr4);
652 652
653 // Can we allocate a massive (512MB) size? 653 // Can we allocate a massive (512MB) size?
654 ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024); 654 // Allocate 512MB, but +1, to test for cookie writing alignment issues.
655 ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1);
655 partitionFreeGeneric(genericAllocator.root(), ptr); 656 partitionFreeGeneric(genericAllocator.root(), ptr);
656 657
657 // Check a more reasonable, but still direct mapped, size. 658 // Check a more reasonable, but still direct mapped, size.
658 // Chop a system page and a byte off to test for rounding errors. 659 // Chop a system page and a byte off to test for rounding errors.
659 size = 20 * 1024 * 1024; 660 size = 20 * 1024 * 1024;
660 size -= kSystemPageSize; 661 size -= kSystemPageSize;
661 size -= 1; 662 size -= 1;
662 ptr = partitionAllocGeneric(genericAllocator.root(), size); 663 ptr = partitionAllocGeneric(genericAllocator.root(), size);
663 char* charPtr = reinterpret_cast<char*>(ptr); 664 char* charPtr = reinterpret_cast<char*>(ptr);
664 *(charPtr + (size - 1)) = 'A'; 665 *(charPtr + (size - 1)) = 'A';
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 // Whilst we're here, allocate again and free with different ordering 1473 // Whilst we're here, allocate again and free with different ordering
1473 // to give a workout to our linked list code. 1474 // to give a workout to our linked list code.
1474 ptr = partitionAllocGeneric(genericAllocator.root(), sizeSmaller); 1475 ptr = partitionAllocGeneric(genericAllocator.root(), sizeSmaller);
1475 ptr2 = partitionAllocGeneric(genericAllocator.root(), sizeBigger); 1476 ptr2 = partitionAllocGeneric(genericAllocator.root(), sizeBigger);
1476 partitionFreeGeneric(genericAllocator.root(), ptr); 1477 partitionFreeGeneric(genericAllocator.root(), ptr);
1477 partitionFreeGeneric(genericAllocator.root(), ptr2); 1478 partitionFreeGeneric(genericAllocator.root(), ptr2);
1478 } 1479 }
1479 1480
1480 // This test checks large-but-not-quite-direct allocations. 1481 // This test checks large-but-not-quite-direct allocations.
1481 { 1482 {
1482 void* ptr = partitionAllocGeneric(genericAllocator.root(), 65537); 1483 void* ptr = partitionAllocGeneric(genericAllocator.root(), 65536 + 1);
1483 1484
1484 { 1485 {
1485 MockPartitionStatsDumper mockStatsDumperGeneric; 1486 MockPartitionStatsDumper mockStatsDumperGeneric;
1486 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1487 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1487 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1488 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1488 1489
1489 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder); 1490 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1490 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize); 1491 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1491 EXPECT_TRUE(stats); 1492 EXPECT_TRUE(stats);
1492 EXPECT_TRUE(stats->isValid); 1493 EXPECT_TRUE(stats->isValid);
1493 EXPECT_FALSE(stats->isDirectMap); 1494 EXPECT_FALSE(stats->isDirectMap);
1494 EXPECT_EQ(slotSize, stats->bucketSlotSize); 1495 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1495 EXPECT_EQ(65536 + kSystemPageSize, stats->activeBytes); 1496 EXPECT_EQ(65536 + kSystemPageSize, stats->activeBytes);
1496 EXPECT_EQ(slotSize, stats->residentBytes); 1497 EXPECT_EQ(slotSize, stats->residentBytes);
1497 EXPECT_EQ(0u, stats->decommittableBytes); 1498 EXPECT_EQ(0u, stats->decommittableBytes);
1498 EXPECT_EQ(1u, stats->numFullPages); 1499 EXPECT_EQ(1u, stats->numFullPages);
1499 EXPECT_EQ(0u, stats->numActivePages); 1500 EXPECT_EQ(0u, stats->numActivePages);
1500 EXPECT_EQ(0u, stats->numEmptyPages); 1501 EXPECT_EQ(0u, stats->numEmptyPages);
1501 EXPECT_EQ(0u, stats->numDecommittedPages); 1502 EXPECT_EQ(0u, stats->numDecommittedPages);
1502 } 1503 }
1503 1504
1504 partitionFreeGeneric(genericAllocator.root(), ptr); 1505 partitionFreeGeneric(genericAllocator.root(), ptr);
1506
1507 void* ptr2 = partitionAllocGeneric(genericAllocator.root(), 65536 + kSys temPageSize + 1);
1508 EXPECT_EQ(ptr, ptr2);
1509
1510 {
1511 MockPartitionStatsDumper mockStatsDumperGeneric;
1512 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1513 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1514
1515 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1516 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1517 EXPECT_TRUE(stats);
1518 EXPECT_TRUE(stats->isValid);
1519 EXPECT_FALSE(stats->isDirectMap);
1520 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1521 EXPECT_EQ(slotSize, stats->activeBytes);
1522 EXPECT_EQ(slotSize, stats->residentBytes);
1523 EXPECT_EQ(0u, stats->decommittableBytes);
1524 EXPECT_EQ(1u, stats->numFullPages);
1525 EXPECT_EQ(0u, stats->numActivePages);
1526 EXPECT_EQ(0u, stats->numEmptyPages);
1527 EXPECT_EQ(0u, stats->numDecommittedPages);
1528 }
1529
1530 partitionFreeGeneric(genericAllocator.root(), ptr2);
1505 } 1531 }
1506 1532
1507 TestShutdown(); 1533 TestShutdown();
1508 } 1534 }
1509 1535
1510 // Tests the API to purge freeable memory. 1536 // Tests the API to purge freeable memory.
1511 TEST(PartitionAllocTest, Purge) 1537 TEST(PartitionAllocTest, Purge)
1512 { 1538 {
1513 TestSetup(); 1539 TestSetup();
1514 1540
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); 1590 EXPECT_EQ(32u, countLeadingZerosSizet(0u));
1565 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); 1591 EXPECT_EQ(31u, countLeadingZerosSizet(1u));
1566 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); 1592 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30));
1567 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); 1593 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31));
1568 #endif 1594 #endif
1569 } 1595 }
1570 1596
1571 } // namespace WTF 1597 } // namespace WTF
1572 1598
1573 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 1599 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« Source/wtf/PartitionAlloc.cpp ('K') | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698