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

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

Issue 1197753003: PartitionAlloc: implement discarding for partitionPurgeMemoryGeneric(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@rawsize
Patch Set: Fix Windows compile error. 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
« no previous file with comments | « 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 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1361 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1362 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1362 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1363 1363
1364 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1364 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1365 EXPECT_TRUE(stats); 1365 EXPECT_TRUE(stats);
1366 EXPECT_TRUE(stats->isValid); 1366 EXPECT_TRUE(stats->isValid);
1367 EXPECT_EQ(2048u, stats->bucketSlotSize); 1367 EXPECT_EQ(2048u, stats->bucketSlotSize);
1368 EXPECT_EQ(2048u, stats->activeBytes); 1368 EXPECT_EQ(2048u, stats->activeBytes);
1369 EXPECT_EQ(kSystemPageSize, stats->residentBytes); 1369 EXPECT_EQ(kSystemPageSize, stats->residentBytes);
1370 EXPECT_EQ(0u, stats->decommittableBytes); 1370 EXPECT_EQ(0u, stats->decommittableBytes);
1371 EXPECT_EQ(0u, stats->discardableBytes);
1371 EXPECT_EQ(0u, stats->numFullPages); 1372 EXPECT_EQ(0u, stats->numFullPages);
1372 EXPECT_EQ(1u, stats->numActivePages); 1373 EXPECT_EQ(1u, stats->numActivePages);
1373 EXPECT_EQ(0u, stats->numEmptyPages); 1374 EXPECT_EQ(0u, stats->numEmptyPages);
1374 EXPECT_EQ(0u, stats->numDecommittedPages); 1375 EXPECT_EQ(0u, stats->numDecommittedPages);
1375 } 1376 }
1376 1377
1377 partitionFreeGeneric(genericAllocator.root(), genericPtr); 1378 partitionFreeGeneric(genericAllocator.root(), genericPtr);
1378 1379
1379 { 1380 {
1380 MockPartitionStatsDumper mockStatsDumperGeneric; 1381 MockPartitionStatsDumper mockStatsDumperGeneric;
1381 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1382 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1382 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1383 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1383 1384
1384 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1385 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1385 EXPECT_TRUE(stats); 1386 EXPECT_TRUE(stats);
1386 EXPECT_TRUE(stats->isValid); 1387 EXPECT_TRUE(stats->isValid);
1387 EXPECT_EQ(2048u, stats->bucketSlotSize); 1388 EXPECT_EQ(2048u, stats->bucketSlotSize);
1388 EXPECT_EQ(0u, stats->activeBytes); 1389 EXPECT_EQ(0u, stats->activeBytes);
1389 EXPECT_EQ(kSystemPageSize, stats->residentBytes); 1390 EXPECT_EQ(kSystemPageSize, stats->residentBytes);
1390 EXPECT_EQ(kSystemPageSize, stats->decommittableBytes); 1391 EXPECT_EQ(kSystemPageSize, stats->decommittableBytes);
1392 EXPECT_EQ(0u, stats->discardableBytes);
1391 EXPECT_EQ(0u, stats->numFullPages); 1393 EXPECT_EQ(0u, stats->numFullPages);
1392 EXPECT_EQ(0u, stats->numActivePages); 1394 EXPECT_EQ(0u, stats->numActivePages);
1393 EXPECT_EQ(1u, stats->numEmptyPages); 1395 EXPECT_EQ(1u, stats->numEmptyPages);
1394 EXPECT_EQ(0u, stats->numDecommittedPages); 1396 EXPECT_EQ(0u, stats->numDecommittedPages);
1395 } 1397 }
1396 1398
1397 CycleGenericFreeCache(kTestAllocSize); 1399 CycleGenericFreeCache(kTestAllocSize);
1398 1400
1399 { 1401 {
1400 MockPartitionStatsDumper mockStatsDumperGeneric; 1402 MockPartitionStatsDumper mockStatsDumperGeneric;
1401 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1403 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1402 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1404 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1403 1405
1404 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1406 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1405 EXPECT_TRUE(stats); 1407 EXPECT_TRUE(stats);
1406 EXPECT_TRUE(stats->isValid); 1408 EXPECT_TRUE(stats->isValid);
1407 EXPECT_EQ(2048u, stats->bucketSlotSize); 1409 EXPECT_EQ(2048u, stats->bucketSlotSize);
1408 EXPECT_EQ(0u, stats->activeBytes); 1410 EXPECT_EQ(0u, stats->activeBytes);
1409 EXPECT_EQ(0u, stats->residentBytes); 1411 EXPECT_EQ(0u, stats->residentBytes);
1410 EXPECT_EQ(0u, stats->decommittableBytes); 1412 EXPECT_EQ(0u, stats->decommittableBytes);
1413 EXPECT_EQ(0u, stats->discardableBytes);
1411 EXPECT_EQ(0u, stats->numFullPages); 1414 EXPECT_EQ(0u, stats->numFullPages);
1412 EXPECT_EQ(0u, stats->numActivePages); 1415 EXPECT_EQ(0u, stats->numActivePages);
1413 EXPECT_EQ(0u, stats->numEmptyPages); 1416 EXPECT_EQ(0u, stats->numEmptyPages);
1414 EXPECT_EQ(1u, stats->numDecommittedPages); 1417 EXPECT_EQ(1u, stats->numDecommittedPages);
1415 } 1418 }
1416 } 1419 }
1417 1420
1418 // This test checks for correct empty page list accounting. 1421 // This test checks for correct empty page list accounting.
1419 { 1422 {
1420 size_t size = kPartitionPageSize - kExtraAllocSize; 1423 size_t size = kPartitionPageSize - kExtraAllocSize;
(...skipping 11 matching lines...) Expand all
1432 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1435 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1433 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1436 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1434 1437
1435 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kPartitionPageSize); 1438 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kPartitionPageSize);
1436 EXPECT_TRUE(stats); 1439 EXPECT_TRUE(stats);
1437 EXPECT_TRUE(stats->isValid); 1440 EXPECT_TRUE(stats->isValid);
1438 EXPECT_EQ(kPartitionPageSize, stats->bucketSlotSize); 1441 EXPECT_EQ(kPartitionPageSize, stats->bucketSlotSize);
1439 EXPECT_EQ(kPartitionPageSize, stats->activeBytes); 1442 EXPECT_EQ(kPartitionPageSize, stats->activeBytes);
1440 EXPECT_EQ(kPartitionPageSize, stats->residentBytes); 1443 EXPECT_EQ(kPartitionPageSize, stats->residentBytes);
1441 EXPECT_EQ(0u, stats->decommittableBytes); 1444 EXPECT_EQ(0u, stats->decommittableBytes);
1445 EXPECT_EQ(0u, stats->discardableBytes);
1442 EXPECT_EQ(1u, stats->numFullPages); 1446 EXPECT_EQ(1u, stats->numFullPages);
1443 EXPECT_EQ(0u, stats->numActivePages); 1447 EXPECT_EQ(0u, stats->numActivePages);
1444 EXPECT_EQ(0u, stats->numEmptyPages); 1448 EXPECT_EQ(0u, stats->numEmptyPages);
1445 EXPECT_EQ(1u, stats->numDecommittedPages); 1449 EXPECT_EQ(1u, stats->numDecommittedPages);
1446 } 1450 }
1447 partitionFreeGeneric(genericAllocator.root(), ptr1); 1451 partitionFreeGeneric(genericAllocator.root(), ptr1);
1448 } 1452 }
1449 1453
1450 // This test checks for correct direct mapped accounting. 1454 // This test checks for correct direct mapped accounting.
1451 { 1455 {
(...skipping 10 matching lines...) Expand all
1462 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1466 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1463 1467
1464 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(realSizeSmaller); 1468 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(realSizeSmaller);
1465 EXPECT_TRUE(stats); 1469 EXPECT_TRUE(stats);
1466 EXPECT_TRUE(stats->isValid); 1470 EXPECT_TRUE(stats->isValid);
1467 EXPECT_TRUE(stats->isDirectMap); 1471 EXPECT_TRUE(stats->isDirectMap);
1468 EXPECT_EQ(realSizeSmaller, stats->bucketSlotSize); 1472 EXPECT_EQ(realSizeSmaller, stats->bucketSlotSize);
1469 EXPECT_EQ(realSizeSmaller, stats->activeBytes); 1473 EXPECT_EQ(realSizeSmaller, stats->activeBytes);
1470 EXPECT_EQ(realSizeSmaller, stats->residentBytes); 1474 EXPECT_EQ(realSizeSmaller, stats->residentBytes);
1471 EXPECT_EQ(0u, stats->decommittableBytes); 1475 EXPECT_EQ(0u, stats->decommittableBytes);
1476 EXPECT_EQ(0u, stats->discardableBytes);
1472 EXPECT_EQ(1u, stats->numFullPages); 1477 EXPECT_EQ(1u, stats->numFullPages);
1473 EXPECT_EQ(0u, stats->numActivePages); 1478 EXPECT_EQ(0u, stats->numActivePages);
1474 EXPECT_EQ(0u, stats->numEmptyPages); 1479 EXPECT_EQ(0u, stats->numEmptyPages);
1475 EXPECT_EQ(0u, stats->numDecommittedPages); 1480 EXPECT_EQ(0u, stats->numDecommittedPages);
1476 1481
1477 stats = mockStatsDumperGeneric.GetBucketStats(realSizeBigger); 1482 stats = mockStatsDumperGeneric.GetBucketStats(realSizeBigger);
1478 EXPECT_TRUE(stats); 1483 EXPECT_TRUE(stats);
1479 EXPECT_TRUE(stats->isValid); 1484 EXPECT_TRUE(stats->isValid);
1480 EXPECT_TRUE(stats->isDirectMap); 1485 EXPECT_TRUE(stats->isDirectMap);
1481 EXPECT_EQ(realSizeBigger, stats->bucketSlotSize); 1486 EXPECT_EQ(realSizeBigger, stats->bucketSlotSize);
1482 EXPECT_EQ(realSizeBigger, stats->activeBytes); 1487 EXPECT_EQ(realSizeBigger, stats->activeBytes);
1483 EXPECT_EQ(realSizeBigger, stats->residentBytes); 1488 EXPECT_EQ(realSizeBigger, stats->residentBytes);
1484 EXPECT_EQ(0u, stats->decommittableBytes); 1489 EXPECT_EQ(0u, stats->decommittableBytes);
1490 EXPECT_EQ(0u, stats->discardableBytes);
1485 EXPECT_EQ(1u, stats->numFullPages); 1491 EXPECT_EQ(1u, stats->numFullPages);
1486 EXPECT_EQ(0u, stats->numActivePages); 1492 EXPECT_EQ(0u, stats->numActivePages);
1487 EXPECT_EQ(0u, stats->numEmptyPages); 1493 EXPECT_EQ(0u, stats->numEmptyPages);
1488 EXPECT_EQ(0u, stats->numDecommittedPages); 1494 EXPECT_EQ(0u, stats->numDecommittedPages);
1489 } 1495 }
1490 1496
1491 partitionFreeGeneric(genericAllocator.root(), ptr2); 1497 partitionFreeGeneric(genericAllocator.root(), ptr2);
1492 partitionFreeGeneric(genericAllocator.root(), ptr); 1498 partitionFreeGeneric(genericAllocator.root(), ptr);
1493 1499
1494 // Whilst we're here, allocate again and free with different ordering 1500 // Whilst we're here, allocate again and free with different ordering
(...skipping 12 matching lines...) Expand all
1507 MockPartitionStatsDumper mockStatsDumperGeneric; 1513 MockPartitionStatsDumper mockStatsDumperGeneric;
1508 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1514 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1509 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1515 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1510 1516
1511 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder); 1517 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1512 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize); 1518 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1513 EXPECT_TRUE(stats); 1519 EXPECT_TRUE(stats);
1514 EXPECT_TRUE(stats->isValid); 1520 EXPECT_TRUE(stats->isValid);
1515 EXPECT_FALSE(stats->isDirectMap); 1521 EXPECT_FALSE(stats->isDirectMap);
1516 EXPECT_EQ(slotSize, stats->bucketSlotSize); 1522 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1517 EXPECT_EQ(65536 + kSystemPageSize, stats->activeBytes); 1523 EXPECT_EQ(65536u + 1 + kExtraAllocSize, stats->activeBytes);
1518 EXPECT_EQ(slotSize, stats->residentBytes); 1524 EXPECT_EQ(slotSize, stats->residentBytes);
1519 EXPECT_EQ(0u, stats->decommittableBytes); 1525 EXPECT_EQ(0u, stats->decommittableBytes);
1526 EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
1520 EXPECT_EQ(1u, stats->numFullPages); 1527 EXPECT_EQ(1u, stats->numFullPages);
1521 EXPECT_EQ(0u, stats->numActivePages); 1528 EXPECT_EQ(0u, stats->numActivePages);
1522 EXPECT_EQ(0u, stats->numEmptyPages); 1529 EXPECT_EQ(0u, stats->numEmptyPages);
1523 EXPECT_EQ(0u, stats->numDecommittedPages); 1530 EXPECT_EQ(0u, stats->numDecommittedPages);
1524 } 1531 }
1525 1532
1526 partitionFreeGeneric(genericAllocator.root(), ptr); 1533 partitionFreeGeneric(genericAllocator.root(), ptr);
1527 1534
1528 { 1535 {
1529 MockPartitionStatsDumper mockStatsDumperGeneric; 1536 MockPartitionStatsDumper mockStatsDumperGeneric;
(...skipping 22 matching lines...) Expand all
1552 MockPartitionStatsDumper mockStatsDumperGeneric; 1559 MockPartitionStatsDumper mockStatsDumperGeneric;
1553 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1560 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1554 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1561 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1555 1562
1556 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder); 1563 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1557 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize); 1564 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1558 EXPECT_TRUE(stats); 1565 EXPECT_TRUE(stats);
1559 EXPECT_TRUE(stats->isValid); 1566 EXPECT_TRUE(stats->isValid);
1560 EXPECT_FALSE(stats->isDirectMap); 1567 EXPECT_FALSE(stats->isDirectMap);
1561 EXPECT_EQ(slotSize, stats->bucketSlotSize); 1568 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1562 EXPECT_EQ(slotSize, stats->activeBytes); 1569 EXPECT_EQ(65536u + kSystemPageSize + 1 + kExtraAllocSize, stats->act iveBytes);
1563 EXPECT_EQ(slotSize, stats->residentBytes); 1570 EXPECT_EQ(slotSize, stats->residentBytes);
1564 EXPECT_EQ(0u, stats->decommittableBytes); 1571 EXPECT_EQ(0u, stats->decommittableBytes);
1572 EXPECT_EQ(0u, stats->discardableBytes);
1565 EXPECT_EQ(1u, stats->numFullPages); 1573 EXPECT_EQ(1u, stats->numFullPages);
1566 EXPECT_EQ(0u, stats->numActivePages); 1574 EXPECT_EQ(0u, stats->numActivePages);
1567 EXPECT_EQ(0u, stats->numEmptyPages); 1575 EXPECT_EQ(0u, stats->numEmptyPages);
1568 EXPECT_EQ(0u, stats->numDecommittedPages); 1576 EXPECT_EQ(0u, stats->numDecommittedPages);
1569 } 1577 }
1570 1578
1571 partitionFreeGeneric(genericAllocator.root(), ptr2); 1579 partitionFreeGeneric(genericAllocator.root(), ptr2);
1572 } 1580 }
1573 1581
1574 TestShutdown(); 1582 TestShutdown();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 void* ptr7 = partitionAllocGeneric(genericAllocator.root(), size); 1672 void* ptr7 = partitionAllocGeneric(genericAllocator.root(), size);
1665 EXPECT_EQ(ptr6, ptr7); 1673 EXPECT_EQ(ptr6, ptr7);
1666 EXPECT_EQ(page3, bucket->activePagesHead); 1674 EXPECT_EQ(page3, bucket->activePagesHead);
1667 1675
1668 partitionFreeGeneric(genericAllocator.root(), ptr5); 1676 partitionFreeGeneric(genericAllocator.root(), ptr5);
1669 partitionFreeGeneric(genericAllocator.root(), ptr7); 1677 partitionFreeGeneric(genericAllocator.root(), ptr7);
1670 1678
1671 TestShutdown(); 1679 TestShutdown();
1672 } 1680 }
1673 1681
1682 // Tests the API to purge discardable memory.
1683 TEST(PartitionAllocTest, PurgeDiscardable)
1684 {
1685 TestSetup();
1686
1687 {
1688 void* ptr1 = partitionAllocGeneric(genericAllocator.root(), kSystemPageS ize - kExtraAllocSize);
1689 char* ptr2 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), kSystemPageSize - kExtraAllocSize));
1690 partitionFreeGeneric(genericAllocator.root(), ptr2);
1691 {
1692 MockPartitionStatsDumper mockStatsDumperGeneric;
1693 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1694 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1695
1696 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kSystemPageSize);
1697 EXPECT_TRUE(stats);
1698 EXPECT_TRUE(stats->isValid);
1699 EXPECT_EQ(0u, stats->decommittableBytes);
1700 EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
1701 EXPECT_EQ(kSystemPageSize, stats->activeBytes);
1702 EXPECT_EQ(2 * kSystemPageSize, stats->residentBytes);
1703 }
1704 CheckPageInCore(ptr2 - kPointerOffset, true);
1705 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1706 CheckPageInCore(ptr2 - kPointerOffset, false);
1707
1708 partitionFreeGeneric(genericAllocator.root(), ptr1);
1709 }
1710 {
1711 char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), 9216 - kExtraAllocSize));
1712 void* ptr2 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1713 void* ptr3 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1714 void* ptr4 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1715 memset(ptr1, 'A', 9216 - kExtraAllocSize);
1716 memset(ptr2, 'A', 9216 - kExtraAllocSize);
1717 partitionFreeGeneric(genericAllocator.root(), ptr2);
1718 partitionFreeGeneric(genericAllocator.root(), ptr1);
1719 {
1720 MockPartitionStatsDumper mockStatsDumperGeneric;
1721 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1722 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1723
1724 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(9216);
1725 EXPECT_TRUE(stats);
1726 EXPECT_TRUE(stats->isValid);
1727 EXPECT_EQ(0u, stats->decommittableBytes);
1728 EXPECT_EQ(2 * kSystemPageSize, stats->discardableBytes);
1729 EXPECT_EQ(9216u * 2, stats->activeBytes);
1730 EXPECT_EQ(9 * kSystemPageSize, stats->residentBytes);
1731 }
1732 CheckPageInCore(ptr1 - kPointerOffset, true);
1733 CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
1734 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
1735 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), true);
1736 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
1737 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1738 CheckPageInCore(ptr1 - kPointerOffset, true);
1739 CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, false);
1740 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
1741 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false);
1742 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
1743
1744 partitionFreeGeneric(genericAllocator.root(), ptr3);
1745 partitionFreeGeneric(genericAllocator.root(), ptr4);
1746 }
1747 {
1748 char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), (64 * kSystemPageSize) - kExtraAllocSize));
1749 memset(ptr1, 'A', (64 * kSystemPageSize) - kExtraAllocSize);
1750 partitionFreeGeneric(genericAllocator.root(), ptr1);
1751 ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAllocator.ro ot(), (61 * kSystemPageSize) - kExtraAllocSize));
1752 {
1753 MockPartitionStatsDumper mockStatsDumperGeneric;
1754 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1755 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1756
1757 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(64 * kSystemPageSize);
1758 EXPECT_TRUE(stats);
1759 EXPECT_TRUE(stats->isValid);
1760 EXPECT_EQ(0u, stats->decommittableBytes);
1761 EXPECT_EQ(3 * kSystemPageSize, stats->discardableBytes);
1762 EXPECT_EQ(61 * kSystemPageSize, stats->activeBytes);
1763 EXPECT_EQ(64 * kSystemPageSize, stats->residentBytes);
1764 }
1765 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
1766 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), true);
1767 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), true);
1768 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), true);
1769 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1770 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
1771 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), false);
1772 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), false);
1773 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), false);
1774
1775 partitionFreeGeneric(genericAllocator.root(), ptr1);
1776 }
1777
1778 TestShutdown();
1779 }
1780
1674 // Tests that the countLeadingZeros() functions work to our satisfaction. 1781 // Tests that the countLeadingZeros() functions work to our satisfaction.
1675 // It doesn't seem worth the overhead of a whole new file for these tests, so 1782 // It doesn't seem worth the overhead of a whole new file for these tests, so
1676 // we'll put them here since partitionAllocGeneric will depend heavily on these 1783 // we'll put them here since partitionAllocGeneric will depend heavily on these
1677 // functions working correctly. 1784 // functions working correctly.
1678 TEST(PartitionAllocTest, CLZWorks) 1785 TEST(PartitionAllocTest, CLZWorks)
1679 { 1786 {
1680 EXPECT_EQ(32u, countLeadingZeros32(0u)); 1787 EXPECT_EQ(32u, countLeadingZeros32(0u));
1681 EXPECT_EQ(31u, countLeadingZeros32(1u)); 1788 EXPECT_EQ(31u, countLeadingZeros32(1u));
1682 EXPECT_EQ(1u, countLeadingZeros32(1u << 30)); 1789 EXPECT_EQ(1u, countLeadingZeros32(1u << 30));
1683 EXPECT_EQ(0u, countLeadingZeros32(1u << 31)); 1790 EXPECT_EQ(0u, countLeadingZeros32(1u << 31));
1684 1791
1685 #if CPU(64BIT) 1792 #if CPU(64BIT)
1686 EXPECT_EQ(64u, countLeadingZerosSizet(0ull)); 1793 EXPECT_EQ(64u, countLeadingZerosSizet(0ull));
1687 EXPECT_EQ(63u, countLeadingZerosSizet(1ull)); 1794 EXPECT_EQ(63u, countLeadingZerosSizet(1ull));
1688 EXPECT_EQ(32u, countLeadingZerosSizet(1ull << 31)); 1795 EXPECT_EQ(32u, countLeadingZerosSizet(1ull << 31));
1689 EXPECT_EQ(1u, countLeadingZerosSizet(1ull << 62)); 1796 EXPECT_EQ(1u, countLeadingZerosSizet(1ull << 62));
1690 EXPECT_EQ(0u, countLeadingZerosSizet(1ull << 63)); 1797 EXPECT_EQ(0u, countLeadingZerosSizet(1ull << 63));
1691 #else 1798 #else
1692 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); 1799 EXPECT_EQ(32u, countLeadingZerosSizet(0u));
1693 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); 1800 EXPECT_EQ(31u, countLeadingZerosSizet(1u));
1694 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); 1801 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30));
1695 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); 1802 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31));
1696 #endif 1803 #endif
1697 } 1804 }
1698 1805
1699 } // namespace WTF 1806 } // namespace WTF
1700 1807
1701 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 1808 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW
« 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