Chromium Code Reviews| 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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 768 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 768 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 769 return realloc(ptr, newSize); | 769 return realloc(ptr, newSize); |
| 770 #else | 770 #else |
| 771 if (UNLIKELY(!ptr)) | 771 if (UNLIKELY(!ptr)) |
| 772 return partitionAllocGeneric(root, newSize); | 772 return partitionAllocGeneric(root, newSize); |
| 773 if (UNLIKELY(!newSize)) { | 773 if (UNLIKELY(!newSize)) { |
| 774 partitionFreeGeneric(root, ptr); | 774 partitionFreeGeneric(root, ptr); |
| 775 return 0; | 775 return 0; |
| 776 } | 776 } |
| 777 | 777 |
| 778 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the | 778 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr))); |
|
Chris Evans
2014/02/26 00:22:52
This TODO is not TO-DONE :) so I'm not sure why it
Jens Widell
2014/02/26 05:45:44
Sorry about that; quite sloppy of me. Will restore
| |
| 779 // new size is a significant percentage smaller. We could do the same if we | |
| 780 // determine it is a win. | |
| 781 void* realPtr = partitionCookieFreePointerAdjust(ptr); | |
| 782 ASSERT(partitionPointerIsValid(realPtr)); | |
| 783 PartitionPage* oldPage = partitionPointerToPage(realPtr); | |
| 784 PartitionBucket* oldBucket = oldPage->bucket; | |
| 785 | 779 |
| 786 size_t allocSize = partitionCookieSizeAdjustAdd(newSize); | 780 size_t actualNewSize = partitionAllocActualSize(root, newSize); |
|
Chris Evans
2014/02/26 00:22:52
Don't we need partitionCookieSizeAdjustAdd() aroun
Jens Widell
2014/02/26 05:45:44
We don't need it for the comparison to actualOldSi
| |
| 787 PartitionBucket* newBucket = partitionGenericSizeToBucket(root, allocSize); | 781 size_t actualOldSize = partitionAllocGetSize(ptr); |
| 788 | 782 |
| 789 // TODO: for a downsize on a direct mapped allocation, we really should | 783 if (actualNewSize == actualOldSize) { |
|
Chris Evans
2014/02/26 00:22:52
This TODO is also not TO-DONE. So we might want to
| |
| 790 // just de-commit the correct number of pages off the end. | 784 // Trying to allocate a block of size newSize would give us a block of |
| 791 if (oldBucket == newBucket) | 785 // the same size as the one we've already got, so no point in doing |
| 786 // anything here. | |
| 792 return ptr; | 787 return ptr; |
| 788 } | |
| 793 | 789 |
| 794 // This realloc cannot be resized in-place. Sadness. | 790 // This realloc cannot be resized in-place. Sadness. |
| 795 void* ret = partitionAllocGeneric(root, newSize); | 791 void* ret = partitionAllocGeneric(root, newSize); |
| 796 size_t copySize = oldPage->bucket->slotSize; | 792 size_t copySize = actualOldSize; |
|
Chris Evans
2014/02/26 00:22:52
I think the loss of the partitionCookieSizeAdjustS
Jens Widell
2014/02/26 05:45:44
I don't see it. This function is now only using "p
| |
| 797 copySize = partitionCookieSizeAdjustSubtract(copySize); | |
| 798 if (newSize < copySize) | 793 if (newSize < copySize) |
| 799 copySize = newSize; | 794 copySize = newSize; |
| 800 | 795 |
| 801 memcpy(ret, ptr, copySize); | 796 memcpy(ret, ptr, copySize); |
| 802 partitionFreeGeneric(root, ptr); | 797 partitionFreeGeneric(root, ptr); |
| 803 return ret; | 798 return ret; |
| 804 #endif | 799 #endif |
| 805 } | 800 } |
| 806 | 801 |
| 807 #ifndef NDEBUG | 802 #ifndef NDEBUG |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 printf("total live: %zu bytes\n", totalLive); | 850 printf("total live: %zu bytes\n", totalLive); |
| 856 printf("total resident: %zu bytes\n", totalResident); | 851 printf("total resident: %zu bytes\n", totalResident); |
| 857 printf("total freeable: %zu bytes\n", totalFreeable); | 852 printf("total freeable: %zu bytes\n", totalFreeable); |
| 858 fflush(stdout); | 853 fflush(stdout); |
| 859 } | 854 } |
| 860 | 855 |
| 861 #endif // !NDEBUG | 856 #endif // !NDEBUG |
| 862 | 857 |
| 863 } // namespace WTF | 858 } // namespace WTF |
| 864 | 859 |
| OLD | NEW |