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

Unified Diff: third_party/WebKit/Source/wtf/PartitionAlloc.h

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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/PartitionAlloc.h
diff --git a/third_party/WebKit/Source/wtf/PartitionAlloc.h b/third_party/WebKit/Source/wtf/PartitionAlloc.h
index b0e233f4e2d24a442be2936fc08401c1fddc2866..e2f90d12477056abbcd0349696d58cf46ace6ed7 100644
--- a/third_party/WebKit/Source/wtf/PartitionAlloc.h
+++ b/third_party/WebKit/Source/wtf/PartitionAlloc.h
@@ -411,6 +411,17 @@ WTF_EXPORT NEVER_INLINE void* partitionReallocGeneric(PartitionRootGeneric*, voi
WTF_EXPORT void partitionDumpStats(PartitionRoot*, const char* partitionName, bool isLightDump, PartitionStatsDumper*);
WTF_EXPORT void partitionDumpStatsGeneric(PartitionRootGeneric*, const char* partitionName, bool isLightDump, PartitionStatsDumper*);
+class WTF_EXPORT PartitionHooks {
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 nit: PartitionAllocHooks ? otherwise it seems that
Ruud van Asseldonk 2015/10/14 12:30:18 Done.
+public:
+ typedef void AllocationHook(void* address, size_t);
+ typedef void FreeHook(void* address);
+
+ // Pointers to hook functions that PartitionAlloc will call on allocation and
+ // free if the pointers are non-null.
+ static AllocationHook* allocationHook;
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 nit: m_allocationHook i believe
Ruud van Asseldonk 2015/10/14 12:30:18 Done.
+ static FreeHook* freeHook;
Primiano Tucci (use gerrit) 2015/10/14 10:10:12 I think you can make the static private: and expos
Ruud van Asseldonk 2015/10/14 12:30:18 Great idea, done.
+};
+
ALWAYS_INLINE PartitionFreelistEntry* partitionFreelistMask(PartitionFreelistEntry* ptr)
{
// We use bswap on little endian as a fast mask for two reasons:
@@ -613,6 +624,10 @@ ALWAYS_INLINE void* partitionBucketAlloc(PartitionRootBase* root, int flags, siz
partitionCookieWriteValue(charRet);
partitionCookieWriteValue(charRet + kCookieSize + noCookieSize);
#endif
+
+ if (UNLIKELY(PartitionHooks::allocationHook != nullptr))
+ PartitionHooks::allocationHook(ret, size);
+
return ret;
}
@@ -645,6 +660,10 @@ ALWAYS_INLINE void partitionFreeWithPage(void* ptr, PartitionPage* page)
partitionCookieCheckValue(reinterpret_cast<char*>(ptr) + slotSize - kCookieSize);
memset(ptr, kFreedByte, slotSize);
#endif
+
+ if (UNLIKELY(PartitionHooks::freeHook != nullptr))
+ PartitionHooks::freeHook(ptr);
+
ASSERT(page->numAllocatedSlots);
PartitionFreelistEntry* freelistHead = page->freelistHead;
ASSERT(!freelistHead || partitionPointerIsValid(freelistHead));

Powered by Google App Engine
This is Rietveld 408576698