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

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: 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void* ptr = partitionAllocGeneric(genericAllocator.root(), size); 187 void* ptr = partitionAllocGeneric(genericAllocator.root(), size);
188 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerA djust(ptr)); 188 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerA djust(ptr));
189 PartitionBucket* bucket = page->bucket; 189 PartitionBucket* bucket = page->bucket;
190 EXPECT_EQ(1, bucket->activePagesHead->numAllocatedSlots); 190 EXPECT_EQ(1, bucket->activePagesHead->numAllocatedSlots);
191 partitionFreeGeneric(genericAllocator.root(), ptr); 191 partitionFreeGeneric(genericAllocator.root(), ptr);
192 EXPECT_EQ(0, bucket->activePagesHead->numAllocatedSlots); 192 EXPECT_EQ(0, bucket->activePagesHead->numAllocatedSlots);
193 EXPECT_NE(-1, bucket->activePagesHead->emptyCacheIndex); 193 EXPECT_NE(-1, bucket->activePagesHead->emptyCacheIndex);
194 } 194 }
195 } 195 }
196 196
197 void CheckPageInCore(void* ptr, bool inCore)
198 {
199 #if OS(LINUX)
200 unsigned char ret;
201 EXPECT_EQ(0, mincore(ptr, kSystemPageSize, &ret));
202 EXPECT_EQ(inCore, ret);
203 #endif
204 }
205
197 class MockPartitionStatsDumper : public PartitionStatsDumper { 206 class MockPartitionStatsDumper : public PartitionStatsDumper {
198 public: 207 public:
199 MockPartitionStatsDumper() 208 MockPartitionStatsDumper()
200 : m_totalResidentBytes(0) 209 : m_totalResidentBytes(0)
201 , m_totalActiveBytes(0) { } 210 , m_totalActiveBytes(0) { }
202 211
203 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats* memoryStats) override 212 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats* memoryStats) override
204 { 213 {
205 (void) partitionName; 214 (void) partitionName;
206 EXPECT_TRUE(memoryStats->isValid); 215 EXPECT_TRUE(memoryStats->isValid);
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1349 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1341 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1350 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1342 1351
1343 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1352 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1344 EXPECT_TRUE(stats); 1353 EXPECT_TRUE(stats);
1345 EXPECT_TRUE(stats->isValid); 1354 EXPECT_TRUE(stats->isValid);
1346 EXPECT_EQ(2048u, stats->bucketSlotSize); 1355 EXPECT_EQ(2048u, stats->bucketSlotSize);
1347 EXPECT_EQ(2048u, stats->activeBytes); 1356 EXPECT_EQ(2048u, stats->activeBytes);
1348 EXPECT_EQ(kSystemPageSize, stats->residentBytes); 1357 EXPECT_EQ(kSystemPageSize, stats->residentBytes);
1349 EXPECT_EQ(0u, stats->decommittableBytes); 1358 EXPECT_EQ(0u, stats->decommittableBytes);
1359 EXPECT_EQ(0u, stats->discardableBytes);
1350 EXPECT_EQ(0u, stats->numFullPages); 1360 EXPECT_EQ(0u, stats->numFullPages);
1351 EXPECT_EQ(1u, stats->numActivePages); 1361 EXPECT_EQ(1u, stats->numActivePages);
1352 EXPECT_EQ(0u, stats->numEmptyPages); 1362 EXPECT_EQ(0u, stats->numEmptyPages);
1353 EXPECT_EQ(0u, stats->numDecommittedPages); 1363 EXPECT_EQ(0u, stats->numDecommittedPages);
1354 } 1364 }
1355 1365
1356 partitionFreeGeneric(genericAllocator.root(), genericPtr); 1366 partitionFreeGeneric(genericAllocator.root(), genericPtr);
1357 1367
1358 { 1368 {
1359 MockPartitionStatsDumper mockStatsDumperGeneric; 1369 MockPartitionStatsDumper mockStatsDumperGeneric;
1360 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1370 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1361 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1371 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1362 1372
1363 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1373 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1364 EXPECT_TRUE(stats); 1374 EXPECT_TRUE(stats);
1365 EXPECT_TRUE(stats->isValid); 1375 EXPECT_TRUE(stats->isValid);
1366 EXPECT_EQ(2048u, stats->bucketSlotSize); 1376 EXPECT_EQ(2048u, stats->bucketSlotSize);
1367 EXPECT_EQ(0u, stats->activeBytes); 1377 EXPECT_EQ(0u, stats->activeBytes);
1368 EXPECT_EQ(kSystemPageSize, stats->residentBytes); 1378 EXPECT_EQ(kSystemPageSize, stats->residentBytes);
1369 EXPECT_EQ(kSystemPageSize, stats->decommittableBytes); 1379 EXPECT_EQ(kSystemPageSize, stats->decommittableBytes);
1380 EXPECT_EQ(0u, stats->discardableBytes);
1370 EXPECT_EQ(0u, stats->numFullPages); 1381 EXPECT_EQ(0u, stats->numFullPages);
1371 EXPECT_EQ(0u, stats->numActivePages); 1382 EXPECT_EQ(0u, stats->numActivePages);
1372 EXPECT_EQ(1u, stats->numEmptyPages); 1383 EXPECT_EQ(1u, stats->numEmptyPages);
1373 EXPECT_EQ(0u, stats->numDecommittedPages); 1384 EXPECT_EQ(0u, stats->numDecommittedPages);
1374 } 1385 }
1375 1386
1376 CycleGenericFreeCache(kTestAllocSize); 1387 CycleGenericFreeCache(kTestAllocSize);
1377 1388
1378 { 1389 {
1379 MockPartitionStatsDumper mockStatsDumperGeneric; 1390 MockPartitionStatsDumper mockStatsDumperGeneric;
1380 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1391 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1381 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1392 EXPECT_FALSE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1382 1393
1383 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048); 1394 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(2048);
1384 EXPECT_TRUE(stats); 1395 EXPECT_TRUE(stats);
1385 EXPECT_TRUE(stats->isValid); 1396 EXPECT_TRUE(stats->isValid);
1386 EXPECT_EQ(2048u, stats->bucketSlotSize); 1397 EXPECT_EQ(2048u, stats->bucketSlotSize);
1387 EXPECT_EQ(0u, stats->activeBytes); 1398 EXPECT_EQ(0u, stats->activeBytes);
1388 EXPECT_EQ(0u, stats->residentBytes); 1399 EXPECT_EQ(0u, stats->residentBytes);
1389 EXPECT_EQ(0u, stats->decommittableBytes); 1400 EXPECT_EQ(0u, stats->decommittableBytes);
1401 EXPECT_EQ(0u, stats->discardableBytes);
1390 EXPECT_EQ(0u, stats->numFullPages); 1402 EXPECT_EQ(0u, stats->numFullPages);
1391 EXPECT_EQ(0u, stats->numActivePages); 1403 EXPECT_EQ(0u, stats->numActivePages);
1392 EXPECT_EQ(0u, stats->numEmptyPages); 1404 EXPECT_EQ(0u, stats->numEmptyPages);
1393 EXPECT_EQ(1u, stats->numDecommittedPages); 1405 EXPECT_EQ(1u, stats->numDecommittedPages);
1394 } 1406 }
1395 } 1407 }
1396 1408
1397 // This test checks for correct empty page list accounting. 1409 // This test checks for correct empty page list accounting.
1398 { 1410 {
1399 size_t size = kPartitionPageSize - kExtraAllocSize; 1411 size_t size = kPartitionPageSize - kExtraAllocSize;
(...skipping 11 matching lines...) Expand all
1411 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1423 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1412 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1424 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1413 1425
1414 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kPartitionPageSize); 1426 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kPartitionPageSize);
1415 EXPECT_TRUE(stats); 1427 EXPECT_TRUE(stats);
1416 EXPECT_TRUE(stats->isValid); 1428 EXPECT_TRUE(stats->isValid);
1417 EXPECT_EQ(kPartitionPageSize, stats->bucketSlotSize); 1429 EXPECT_EQ(kPartitionPageSize, stats->bucketSlotSize);
1418 EXPECT_EQ(kPartitionPageSize, stats->activeBytes); 1430 EXPECT_EQ(kPartitionPageSize, stats->activeBytes);
1419 EXPECT_EQ(kPartitionPageSize, stats->residentBytes); 1431 EXPECT_EQ(kPartitionPageSize, stats->residentBytes);
1420 EXPECT_EQ(0u, stats->decommittableBytes); 1432 EXPECT_EQ(0u, stats->decommittableBytes);
1433 EXPECT_EQ(0u, stats->discardableBytes);
1421 EXPECT_EQ(1u, stats->numFullPages); 1434 EXPECT_EQ(1u, stats->numFullPages);
1422 EXPECT_EQ(0u, stats->numActivePages); 1435 EXPECT_EQ(0u, stats->numActivePages);
1423 EXPECT_EQ(0u, stats->numEmptyPages); 1436 EXPECT_EQ(0u, stats->numEmptyPages);
1424 EXPECT_EQ(1u, stats->numDecommittedPages); 1437 EXPECT_EQ(1u, stats->numDecommittedPages);
1425 } 1438 }
1426 partitionFreeGeneric(genericAllocator.root(), ptr1); 1439 partitionFreeGeneric(genericAllocator.root(), ptr1);
1427 } 1440 }
1428 1441
1429 // This test checks for correct direct mapped accounting. 1442 // This test checks for correct direct mapped accounting.
1430 { 1443 {
(...skipping 10 matching lines...) Expand all
1441 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1454 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1442 1455
1443 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(realSizeSmaller); 1456 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(realSizeSmaller);
1444 EXPECT_TRUE(stats); 1457 EXPECT_TRUE(stats);
1445 EXPECT_TRUE(stats->isValid); 1458 EXPECT_TRUE(stats->isValid);
1446 EXPECT_TRUE(stats->isDirectMap); 1459 EXPECT_TRUE(stats->isDirectMap);
1447 EXPECT_EQ(realSizeSmaller, stats->bucketSlotSize); 1460 EXPECT_EQ(realSizeSmaller, stats->bucketSlotSize);
1448 EXPECT_EQ(realSizeSmaller, stats->activeBytes); 1461 EXPECT_EQ(realSizeSmaller, stats->activeBytes);
1449 EXPECT_EQ(realSizeSmaller, stats->residentBytes); 1462 EXPECT_EQ(realSizeSmaller, stats->residentBytes);
1450 EXPECT_EQ(0u, stats->decommittableBytes); 1463 EXPECT_EQ(0u, stats->decommittableBytes);
1464 EXPECT_EQ(0u, stats->discardableBytes);
1451 EXPECT_EQ(1u, stats->numFullPages); 1465 EXPECT_EQ(1u, stats->numFullPages);
1452 EXPECT_EQ(0u, stats->numActivePages); 1466 EXPECT_EQ(0u, stats->numActivePages);
1453 EXPECT_EQ(0u, stats->numEmptyPages); 1467 EXPECT_EQ(0u, stats->numEmptyPages);
1454 EXPECT_EQ(0u, stats->numDecommittedPages); 1468 EXPECT_EQ(0u, stats->numDecommittedPages);
1455 1469
1456 stats = mockStatsDumperGeneric.GetBucketStats(realSizeBigger); 1470 stats = mockStatsDumperGeneric.GetBucketStats(realSizeBigger);
1457 EXPECT_TRUE(stats); 1471 EXPECT_TRUE(stats);
1458 EXPECT_TRUE(stats->isValid); 1472 EXPECT_TRUE(stats->isValid);
1459 EXPECT_TRUE(stats->isDirectMap); 1473 EXPECT_TRUE(stats->isDirectMap);
1460 EXPECT_EQ(realSizeBigger, stats->bucketSlotSize); 1474 EXPECT_EQ(realSizeBigger, stats->bucketSlotSize);
1461 EXPECT_EQ(realSizeBigger, stats->activeBytes); 1475 EXPECT_EQ(realSizeBigger, stats->activeBytes);
1462 EXPECT_EQ(realSizeBigger, stats->residentBytes); 1476 EXPECT_EQ(realSizeBigger, stats->residentBytes);
1463 EXPECT_EQ(0u, stats->decommittableBytes); 1477 EXPECT_EQ(0u, stats->decommittableBytes);
1478 EXPECT_EQ(0u, stats->discardableBytes);
1464 EXPECT_EQ(1u, stats->numFullPages); 1479 EXPECT_EQ(1u, stats->numFullPages);
1465 EXPECT_EQ(0u, stats->numActivePages); 1480 EXPECT_EQ(0u, stats->numActivePages);
1466 EXPECT_EQ(0u, stats->numEmptyPages); 1481 EXPECT_EQ(0u, stats->numEmptyPages);
1467 EXPECT_EQ(0u, stats->numDecommittedPages); 1482 EXPECT_EQ(0u, stats->numDecommittedPages);
1468 } 1483 }
1469 1484
1470 partitionFreeGeneric(genericAllocator.root(), ptr2); 1485 partitionFreeGeneric(genericAllocator.root(), ptr2);
1471 partitionFreeGeneric(genericAllocator.root(), ptr); 1486 partitionFreeGeneric(genericAllocator.root(), ptr);
1472 1487
1473 // Whilst we're here, allocate again and free with different ordering 1488 // Whilst we're here, allocate again and free with different ordering
(...skipping 15 matching lines...) Expand all
1489 1504
1490 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder); 1505 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1491 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize); 1506 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1492 EXPECT_TRUE(stats); 1507 EXPECT_TRUE(stats);
1493 EXPECT_TRUE(stats->isValid); 1508 EXPECT_TRUE(stats->isValid);
1494 EXPECT_FALSE(stats->isDirectMap); 1509 EXPECT_FALSE(stats->isDirectMap);
1495 EXPECT_EQ(slotSize, stats->bucketSlotSize); 1510 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1496 EXPECT_EQ(65536 + kSystemPageSize, stats->activeBytes); 1511 EXPECT_EQ(65536 + kSystemPageSize, stats->activeBytes);
1497 EXPECT_EQ(slotSize, stats->residentBytes); 1512 EXPECT_EQ(slotSize, stats->residentBytes);
1498 EXPECT_EQ(0u, stats->decommittableBytes); 1513 EXPECT_EQ(0u, stats->decommittableBytes);
1514 EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
1499 EXPECT_EQ(1u, stats->numFullPages); 1515 EXPECT_EQ(1u, stats->numFullPages);
1500 EXPECT_EQ(0u, stats->numActivePages); 1516 EXPECT_EQ(0u, stats->numActivePages);
1501 EXPECT_EQ(0u, stats->numEmptyPages); 1517 EXPECT_EQ(0u, stats->numEmptyPages);
1502 EXPECT_EQ(0u, stats->numDecommittedPages); 1518 EXPECT_EQ(0u, stats->numDecommittedPages);
1503 } 1519 }
1504 1520
1505 partitionFreeGeneric(genericAllocator.root(), ptr); 1521 partitionFreeGeneric(genericAllocator.root(), ptr);
1506 1522
1507 void* ptr2 = partitionAllocGeneric(genericAllocator.root(), 65536 + kSys temPageSize + 1); 1523 void* ptr2 = partitionAllocGeneric(genericAllocator.root(), 65536 + kSys temPageSize + 1);
1508 EXPECT_EQ(ptr, ptr2); 1524 EXPECT_EQ(ptr, ptr2);
1509 1525
1510 { 1526 {
1511 MockPartitionStatsDumper mockStatsDumperGeneric; 1527 MockPartitionStatsDumper mockStatsDumperGeneric;
1512 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric); 1528 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1513 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded()); 1529 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1514 1530
1515 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder); 1531 size_t slotSize = 65536 + (65536 / kGenericNumBucketsPerOrder);
1516 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize); 1532 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(slotSize);
1517 EXPECT_TRUE(stats); 1533 EXPECT_TRUE(stats);
1518 EXPECT_TRUE(stats->isValid); 1534 EXPECT_TRUE(stats->isValid);
1519 EXPECT_FALSE(stats->isDirectMap); 1535 EXPECT_FALSE(stats->isDirectMap);
1520 EXPECT_EQ(slotSize, stats->bucketSlotSize); 1536 EXPECT_EQ(slotSize, stats->bucketSlotSize);
1521 EXPECT_EQ(slotSize, stats->activeBytes); 1537 EXPECT_EQ(slotSize, stats->activeBytes);
1522 EXPECT_EQ(slotSize, stats->residentBytes); 1538 EXPECT_EQ(slotSize, stats->residentBytes);
1523 EXPECT_EQ(0u, stats->decommittableBytes); 1539 EXPECT_EQ(0u, stats->decommittableBytes);
1540 EXPECT_EQ(0u, stats->discardableBytes);
1524 EXPECT_EQ(1u, stats->numFullPages); 1541 EXPECT_EQ(1u, stats->numFullPages);
1525 EXPECT_EQ(0u, stats->numActivePages); 1542 EXPECT_EQ(0u, stats->numActivePages);
1526 EXPECT_EQ(0u, stats->numEmptyPages); 1543 EXPECT_EQ(0u, stats->numEmptyPages);
1527 EXPECT_EQ(0u, stats->numDecommittedPages); 1544 EXPECT_EQ(0u, stats->numDecommittedPages);
1528 } 1545 }
1529 1546
1530 partitionFreeGeneric(genericAllocator.root(), ptr2); 1547 partitionFreeGeneric(genericAllocator.root(), ptr2);
1531 } 1548 }
1532 1549
1533 TestShutdown(); 1550 TestShutdown();
(...skipping 28 matching lines...) Expand all
1562 EXPECT_TRUE(stats->isValid); 1579 EXPECT_TRUE(stats->isValid);
1563 EXPECT_EQ(0u, stats->decommittableBytes); 1580 EXPECT_EQ(0u, stats->decommittableBytes);
1564 EXPECT_EQ(0u, stats->residentBytes); 1581 EXPECT_EQ(0u, stats->residentBytes);
1565 } 1582 }
1566 // Calling purge again here is a good way of testing we didn't mess up the 1583 // Calling purge again here is a good way of testing we didn't mess up the
1567 // state of the free cache ring. 1584 // state of the free cache ring.
1568 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDecommitE mptyPages); 1585 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDecommitE mptyPages);
1569 TestShutdown(); 1586 TestShutdown();
1570 } 1587 }
1571 1588
1589 // Tests the API to purge discardable memory.
1590 TEST(PartitionAllocTest, PurgeDiscardable)
1591 {
1592 TestSetup();
1593
1594 {
1595 void* ptr1 = partitionAllocGeneric(genericAllocator.root(), kSystemPageS ize - kExtraAllocSize);
1596 char* ptr2 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), kSystemPageSize - kExtraAllocSize));
1597 partitionFreeGeneric(genericAllocator.root(), ptr2);
1598 {
1599 MockPartitionStatsDumper mockStatsDumperGeneric;
1600 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1601 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1602
1603 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(kSystemPageSize);
1604 EXPECT_TRUE(stats);
1605 EXPECT_TRUE(stats->isValid);
1606 EXPECT_EQ(0u, stats->decommittableBytes);
1607 EXPECT_EQ(kSystemPageSize, stats->discardableBytes);
1608 EXPECT_EQ(kSystemPageSize, stats->activeBytes);
1609 EXPECT_EQ(2 * kSystemPageSize, stats->residentBytes);
1610 }
1611 CheckPageInCore(ptr2 - kPointerOffset, true);
1612 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1613 CheckPageInCore(ptr2 - kPointerOffset, false);
1614
1615 partitionFreeGeneric(genericAllocator.root(), ptr1);
1616 }
1617 {
1618 char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), 9216 - kExtraAllocSize));
1619 void* ptr2 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1620 void* ptr3 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1621 void* ptr4 = partitionAllocGeneric(genericAllocator.root(), 9216 - kExtr aAllocSize);
1622 memset(ptr1, 'A', 9216 - kExtraAllocSize);
1623 memset(ptr2, 'A', 9216 - kExtraAllocSize);
1624 partitionFreeGeneric(genericAllocator.root(), ptr2);
1625 partitionFreeGeneric(genericAllocator.root(), ptr1);
1626 {
1627 MockPartitionStatsDumper mockStatsDumperGeneric;
1628 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1629 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1630
1631 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(9216);
1632 EXPECT_TRUE(stats);
1633 EXPECT_TRUE(stats->isValid);
1634 EXPECT_EQ(0u, stats->decommittableBytes);
1635 EXPECT_EQ(2 * kSystemPageSize, stats->discardableBytes);
1636 EXPECT_EQ(9216u * 2, stats->activeBytes);
1637 EXPECT_EQ(9 * kSystemPageSize, stats->residentBytes);
1638 }
1639 CheckPageInCore(ptr1 - kPointerOffset, true);
1640 CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, true);
1641 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
1642 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), true);
1643 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
1644 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1645 CheckPageInCore(ptr1 - kPointerOffset, true);
1646 CheckPageInCore(ptr1 - kPointerOffset + kSystemPageSize, false);
1647 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 2), true);
1648 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 3), false);
1649 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 4), true);
1650
1651 partitionFreeGeneric(genericAllocator.root(), ptr3);
1652 partitionFreeGeneric(genericAllocator.root(), ptr4);
1653 }
1654 {
1655 char* ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAlloca tor.root(), (64 * kSystemPageSize) - kExtraAllocSize));
1656 memset(ptr1, 'A', (64 * kSystemPageSize) - kExtraAllocSize);
1657 partitionFreeGeneric(genericAllocator.root(), ptr1);
1658 ptr1 = reinterpret_cast<char*>(partitionAllocGeneric(genericAllocator.ro ot(), (61 * kSystemPageSize) - kExtraAllocSize));
1659 {
1660 MockPartitionStatsDumper mockStatsDumperGeneric;
1661 partitionDumpStatsGeneric(genericAllocator.root(), "mock_generic_all ocator", &mockStatsDumperGeneric);
1662 EXPECT_TRUE(mockStatsDumperGeneric.IsMemoryAllocationRecorded());
1663
1664 const PartitionBucketMemoryStats* stats = mockStatsDumperGeneric.Get BucketStats(64 * kSystemPageSize);
1665 EXPECT_TRUE(stats);
1666 EXPECT_TRUE(stats->isValid);
1667 EXPECT_EQ(0u, stats->decommittableBytes);
1668 EXPECT_EQ(3 * kSystemPageSize, stats->discardableBytes);
1669 EXPECT_EQ(61 * kSystemPageSize, stats->activeBytes);
1670 EXPECT_EQ(64 * kSystemPageSize, stats->residentBytes);
1671 }
1672 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
1673 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), true);
1674 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), true);
1675 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), true);
1676 partitionPurgeMemoryGeneric(genericAllocator.root(), PartitionPurgeDisca rdUnusedSystemPages);
1677 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 60), true);
1678 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 61), false);
1679 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 62), false);
1680 CheckPageInCore(ptr1 - kPointerOffset + (kSystemPageSize * 63), false);
1681
1682 partitionFreeGeneric(genericAllocator.root(), ptr1);
1683 }
1684
1685 TestShutdown();
1686 }
1687
1572 // Tests that the countLeadingZeros() functions work to our satisfaction. 1688 // Tests that the countLeadingZeros() functions work to our satisfaction.
1573 // It doesn't seem worth the overhead of a whole new file for these tests, so 1689 // It doesn't seem worth the overhead of a whole new file for these tests, so
1574 // we'll put them here since partitionAllocGeneric will depend heavily on these 1690 // we'll put them here since partitionAllocGeneric will depend heavily on these
1575 // functions working correctly. 1691 // functions working correctly.
1576 TEST(PartitionAllocTest, CLZWorks) 1692 TEST(PartitionAllocTest, CLZWorks)
1577 { 1693 {
1578 EXPECT_EQ(32u, countLeadingZeros32(0u)); 1694 EXPECT_EQ(32u, countLeadingZeros32(0u));
1579 EXPECT_EQ(31u, countLeadingZeros32(1u)); 1695 EXPECT_EQ(31u, countLeadingZeros32(1u));
1580 EXPECT_EQ(1u, countLeadingZeros32(1u << 30)); 1696 EXPECT_EQ(1u, countLeadingZeros32(1u << 30));
1581 EXPECT_EQ(0u, countLeadingZeros32(1u << 31)); 1697 EXPECT_EQ(0u, countLeadingZeros32(1u << 31));
1582 1698
1583 #if CPU(64BIT) 1699 #if CPU(64BIT)
1584 EXPECT_EQ(64u, countLeadingZerosSizet(0ull)); 1700 EXPECT_EQ(64u, countLeadingZerosSizet(0ull));
1585 EXPECT_EQ(63u, countLeadingZerosSizet(1ull)); 1701 EXPECT_EQ(63u, countLeadingZerosSizet(1ull));
1586 EXPECT_EQ(32u, countLeadingZerosSizet(1ull << 31)); 1702 EXPECT_EQ(32u, countLeadingZerosSizet(1ull << 31));
1587 EXPECT_EQ(1u, countLeadingZerosSizet(1ull << 62)); 1703 EXPECT_EQ(1u, countLeadingZerosSizet(1ull << 62));
1588 EXPECT_EQ(0u, countLeadingZerosSizet(1ull << 63)); 1704 EXPECT_EQ(0u, countLeadingZerosSizet(1ull << 63));
1589 #else 1705 #else
1590 EXPECT_EQ(32u, countLeadingZerosSizet(0u)); 1706 EXPECT_EQ(32u, countLeadingZerosSizet(0u));
1591 EXPECT_EQ(31u, countLeadingZerosSizet(1u)); 1707 EXPECT_EQ(31u, countLeadingZerosSizet(1u));
1592 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); 1708 EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30));
1593 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); 1709 EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31));
1594 #endif 1710 #endif
1595 } 1711 }
1596 1712
1597 } // namespace WTF 1713 } // namespace WTF
1598 1714
1599 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 1715 #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