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

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

Issue 254103003: PartitionAlloc: Make in-place realloc() less likely to happen (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: extended test Created 6 years, 7 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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 EXPECT_NE(ptr2, ptr); 685 EXPECT_NE(ptr2, ptr);
686 char* charPtr = static_cast<char*>(ptr); 686 char* charPtr = static_cast<char*>(ptr);
687 EXPECT_EQ('A', charPtr[0]); 687 EXPECT_EQ('A', charPtr[0]);
688 EXPECT_EQ('A', charPtr[size - 2]); 688 EXPECT_EQ('A', charPtr[size - 2]);
689 #ifndef NDEBUG 689 #ifndef NDEBUG
690 EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1])); 690 EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1]));
691 #endif 691 #endif
692 692
693 partitionFreeGeneric(genericAllocator.root(), ptr); 693 partitionFreeGeneric(genericAllocator.root(), ptr);
694 694
695 // Test that shrinking a direct mapped allocation happens in-place (even 695 // Test that shrinking a direct mapped allocation happens in-place.
696 // though the new size is smaller than kGenericMaxBucketed).
697 size = WTF::kGenericMaxBucketed + 16 * WTF::kSystemPageSize; 696 size = WTF::kGenericMaxBucketed + 16 * WTF::kSystemPageSize;
698 ptr = partitionAllocGeneric(genericAllocator.root(), size); 697 ptr = partitionAllocGeneric(genericAllocator.root(), size);
699 size_t actualSize = partitionAllocGetSize(ptr); 698 size_t actualSize = partitionAllocGetSize(ptr);
700 ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, WTF::kGenericMa xBucketed - 16 * WTF::kSystemPageSize); 699 ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, WTF::kGenericMa xBucketed + 8 * WTF::kSystemPageSize);
701 EXPECT_EQ(ptr, ptr2); 700 EXPECT_EQ(ptr, ptr2);
702 EXPECT_EQ(actualSize - 32 * WTF::kSystemPageSize, partitionAllocGetSize(ptr2 )); 701 EXPECT_EQ(actualSize - 8 * WTF::kSystemPageSize, partitionAllocGetSize(ptr2) );
703 702
704 // Test that a previously in-place shrunk direct mapped allocation can be 703 // Test that a previously in-place shrunk direct mapped allocation can be
705 // expanded up again within its original size. 704 // expanded up again within its original size.
706 ptr = partitionReallocGeneric(genericAllocator.root(), ptr2, size - WTF::kSy stemPageSize); 705 ptr = partitionReallocGeneric(genericAllocator.root(), ptr2, size - WTF::kSy stemPageSize);
707 EXPECT_EQ(ptr2, ptr); 706 EXPECT_EQ(ptr2, ptr);
708 EXPECT_EQ(actualSize - WTF::kSystemPageSize, partitionAllocGetSize(ptr)); 707 EXPECT_EQ(actualSize - WTF::kSystemPageSize, partitionAllocGetSize(ptr));
709 708
710 partitionFreeGeneric(genericAllocator.root(), ptr); 709 // Test that a direct mapped allocation is performed not in-place when the
710 // new size is small enough.
711 ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, WTF::kSystemPag eSize);
712 EXPECT_NE(ptr, ptr2);
713
714 partitionFreeGeneric(genericAllocator.root(), ptr2);
711 715
712 TestShutdown(); 716 TestShutdown();
713 } 717 }
714 718
715 // Tests the handing out of freelists for partial pages. 719 // Tests the handing out of freelists for partial pages.
716 TEST(PartitionAllocTest, PartialPageFreelists) 720 TEST(PartitionAllocTest, PartialPageFreelists)
717 { 721 {
718 TestSetup(); 722 TestSetup();
719 723
720 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize; 724 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize;
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); 1177 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0));
1174 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); 1178 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1));
1175 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); 1179 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30));
1176 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); 1180 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31));
1177 #endif 1181 #endif
1178 } 1182 }
1179 1183
1180 } // namespace 1184 } // namespace
1181 1185
1182 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 1186 #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