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

Side by Side Diff: third_party/WebKit/Source/wtf/PartitionAlloc.cpp

Issue 1391933004: [Tracing] Add hook to PartitionAlloc for heap profiling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address some primiano comments Created 5 years, 2 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 static_assert(WTF::kGenericSmallestBucket == 8, "generic smallest bucket"); 53 static_assert(WTF::kGenericSmallestBucket == 8, "generic smallest bucket");
54 static_assert(WTF::kGenericMaxBucketed == 983040, "generic max bucketed"); 54 static_assert(WTF::kGenericMaxBucketed == 983040, "generic max bucketed");
55 55
56 namespace WTF { 56 namespace WTF {
57 57
58 int PartitionRootBase::gInitializedLock = 0; 58 int PartitionRootBase::gInitializedLock = 0;
59 bool PartitionRootBase::gInitialized = false; 59 bool PartitionRootBase::gInitialized = false;
60 PartitionPage PartitionRootBase::gSeedPage; 60 PartitionPage PartitionRootBase::gSeedPage;
61 PartitionBucket PartitionRootBase::gPagedBucket; 61 PartitionBucket PartitionRootBase::gPagedBucket;
62 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr; 62 void (*PartitionRootBase::gOomHandlingFunction)() = nullptr;
63 PartitionHooks::AllocationHook* PartitionHooks::allocationHook = nullptr;
64 PartitionHooks::FreeHook* PartitionHooks::freeHook = nullptr;
63 65
64 static uint16_t partitionBucketNumSystemPages(size_t size) 66 static uint16_t partitionBucketNumSystemPages(size_t size)
65 { 67 {
66 // This works out reasonably for the current bucket sizes of the generic 68 // This works out reasonably for the current bucket sizes of the generic
67 // allocator, and the current values of partition page size and constants. 69 // allocator, and the current values of partition page size and constants.
68 // Specifically, we have enough room to always pack the slots perfectly into 70 // Specifically, we have enough room to always pack the slots perfectly into
69 // some number of system pages. The only waste is the waste associated with 71 // some number of system pages. The only waste is the waste associated with
70 // unfaulted pages (i.e. wasted address space). 72 // unfaulted pages (i.e. wasted address space).
71 // TODO: we end up using a lot of system pages for very small sizes. For 73 // TODO: we end up using a lot of system pages for very small sizes. For
72 // example, we'll use 12 system pages for slot size 24. The slot size is 74 // example, we'll use 12 system pages for slot size 24. The slot size is
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 partitionExcessiveAllocationSize(); 1055 partitionExcessiveAllocationSize();
1054 1056
1055 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr))); 1057 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr)));
1056 1058
1057 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerAdjus t(ptr)); 1059 PartitionPage* page = partitionPointerToPage(partitionCookieFreePointerAdjus t(ptr));
1058 1060
1059 if (UNLIKELY(partitionBucketIsDirectMapped(page->bucket))) { 1061 if (UNLIKELY(partitionBucketIsDirectMapped(page->bucket))) {
1060 // We may be able to perform the realloc in place by changing the 1062 // We may be able to perform the realloc in place by changing the
1061 // accessibility of memory pages and, if reducing the size, decommitting 1063 // accessibility of memory pages and, if reducing the size, decommitting
1062 // them. 1064 // them.
1063 if (partitionReallocDirectMappedInPlace(root, page, newSize)) 1065 if (partitionReallocDirectMappedInPlace(root, page, newSize)) {
1066 // Report a realloc as a free followed by alloc when heap profiling
1067 // is enabled.
1068 if (UNLIKELY(PartitionHooks::allocationHook && PartitionHooks::freeH ook)) {
1069 PartitionHooks::freeHook(ptr);
1070 PartitionHooks::allocationHook(ptr, newSize);
1071 }
1072
1064 return ptr; 1073 return ptr;
1074 }
1065 } 1075 }
1066 1076
1067 size_t actualNewSize = partitionAllocActualSize(root, newSize); 1077 size_t actualNewSize = partitionAllocActualSize(root, newSize);
1068 size_t actualOldSize = partitionAllocGetSize(ptr); 1078 size_t actualOldSize = partitionAllocGetSize(ptr);
1069 1079
1070 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the 1080 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the
1071 // new size is a significant percentage smaller. We could do the same if we 1081 // new size is a significant percentage smaller. We could do the same if we
1072 // determine it is a win. 1082 // determine it is a win.
1073 if (actualNewSize == actualOldSize) { 1083 if (actualNewSize == actualOldSize) {
1074 // Trying to allocate a block of size newSize would give us a block of 1084 // Trying to allocate a block of size newSize would give us a block of
1075 // the same size as the one we've already got, so no point in doing 1085 // the same size as the one we've already got, so no point in doing
1076 // anything here. 1086 // anything here.
1077 return ptr; 1087 return ptr;
1078 } 1088 }
1079 1089
1080 // This realloc cannot be resized in-place. Sadness. 1090 // This realloc cannot be resized in-place. Sadness.
1081 void* ret = partitionAllocGeneric(root, newSize); 1091 void* ret = partitionAllocGeneric(root, newSize);
1082 size_t copySize = actualOldSize; 1092 size_t copySize = actualOldSize;
1083 if (newSize < copySize) 1093 if (newSize < copySize)
1084 copySize = newSize; 1094 copySize = newSize;
1085 1095
1086 memcpy(ret, ptr, copySize); 1096 memcpy(ret, ptr, copySize);
1087 partitionFreeGeneric(root, ptr); 1097 partitionFreeGeneric(root, ptr);
1098
1099 // Report a realloc as a free followed by alloc when heap profiling is
1100 // enabled.
1101 if (UNLIKELY(PartitionHooks::allocationHook && PartitionHooks::freeHook)) {
1102 PartitionHooks::freeHook(ptr);
1103 PartitionHooks::allocationHook(ret, newSize);
1104 }
1105
1088 return ret; 1106 return ret;
1089 #endif 1107 #endif
1090 } 1108 }
1091 1109
1092 static size_t partitionPurgePage(PartitionPage* page, bool discard) 1110 static size_t partitionPurgePage(PartitionPage* page, bool discard)
1093 { 1111 {
1094 const PartitionBucket* bucket = page->bucket; 1112 const PartitionBucket* bucket = page->bucket;
1095 size_t slotSize = bucket->slotSize; 1113 size_t slotSize = bucket->slotSize;
1096 if (slotSize < kSystemPageSize || !page->numAllocatedSlots) 1114 if (slotSize < kSystemPageSize || !page->numAllocatedSlots)
1097 return 0; 1115 return 0;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes; 1423 partitionStats.totalDiscardableBytes += memoryStats[i].discardableBy tes;
1406 if (!isLightDump) 1424 if (!isLightDump)
1407 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]); 1425 partitionStatsDumper->partitionsDumpBucketStats(partitionName, & memoryStats[i]);
1408 } 1426 }
1409 } 1427 }
1410 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats); 1428 partitionStatsDumper->partitionDumpTotals(partitionName, &partitionStats);
1411 } 1429 }
1412 1430
1413 } // namespace WTF 1431 } // namespace WTF
1414 1432
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698