Chromium Code Reviews| 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..6ecdab32be8d7975c66eecd99fde52e6388ddc04 100644 |
| --- a/third_party/WebKit/Source/wtf/PartitionAlloc.h |
| +++ b/third_party/WebKit/Source/wtf/PartitionAlloc.h |
| @@ -411,6 +411,46 @@ 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 PartitionAllocHooks { |
| +public: |
| + typedef void AllocationHook(void* address, size_t); |
| + typedef void FreeHook(void* address); |
| + |
| + static void setAllocationHook(AllocationHook* hook) { m_allocationHook = hook; } |
| + static void setFreeHook(FreeHook* hook) { m_freeHook = hook; } |
| + |
| + static void maybeInvokeAllocationHook(void* address, size_t size) |
|
haraken
2015/10/20 00:14:19
I'd rename maybeInvokeAllocationHook() to allocati
Ruud van Asseldonk
2015/10/20 11:43:57
Done.
|
| + { |
| + AllocationHook* hook = m_allocationHook; |
|
Primiano Tucci (use gerrit)
2015/10/19 21:32:03
probably a bit more readable if you s/hook/allocat
Ruud van Asseldonk
2015/10/20 11:43:57
Done.
|
| + if (UNLIKELY(hook != nullptr)) |
|
bashi
2015/10/20 00:33:49
nit: UNLIKELY(hook).
We don't use ptr != nullptr
Ruud van Asseldonk
2015/10/20 11:43:57
This is because |UNLIKELY(ptr)| expands to |__buil
|
| + hook(address, size); |
| + } |
| + |
| + static void maybeInvokeFreeHook(void* address) |
| + { |
| + FreeHook* hook = m_freeHook; |
| + if (UNLIKELY(hook != nullptr)) |
| + hook(address); |
| + } |
| + |
| + static void maybeInvokeReallocationHook(void* oldAddress, void* newAddress, size_t size) |
|
haraken
2015/10/20 00:14:19
You won't need this method if you insert the alloc
Ruud van Asseldonk
2015/10/20 11:43:57
Wouldn't I still need it for |partitionReallocGene
|
| + { |
| + // Report a reallocation as a free followed by an allocation. |
| + AllocationHook* allocHook = m_allocationHook; |
| + FreeHook* freeHook = m_freeHook; |
| + if (UNLIKELY(allocHook && freeHook)) { |
| + freeHook(oldAddress); |
| + allocHook(newAddress, size); |
| + } |
| + } |
| + |
| +private: |
| + // Pointers to hook functions that PartitionAlloc will call on allocation and |
| + // free if the pointers are non-null. |
| + static AllocationHook* m_allocationHook; |
| + static FreeHook* m_freeHook; |
| +}; |
| + |
| ALWAYS_INLINE PartitionFreelistEntry* partitionFreelistMask(PartitionFreelistEntry* ptr) |
| { |
| // We use bswap on little endian as a fast mask for two reasons: |
| @@ -613,6 +653,9 @@ ALWAYS_INLINE void* partitionBucketAlloc(PartitionRootBase* root, int flags, siz |
| partitionCookieWriteValue(charRet); |
| partitionCookieWriteValue(charRet + kCookieSize + noCookieSize); |
| #endif |
| + |
| + PartitionAllocHooks::maybeInvokeAllocationHook(ret, size); |
|
haraken
2015/10/20 00:14:19
You need to insert the allocation hook to partitio
haraken
2015/10/20 00:14:19
And you need to insert the allocation hook to part
|
| + |
| return ret; |
| } |
| @@ -645,6 +688,9 @@ ALWAYS_INLINE void partitionFreeWithPage(void* ptr, PartitionPage* page) |
| partitionCookieCheckValue(reinterpret_cast<char*>(ptr) + slotSize - kCookieSize); |
| memset(ptr, kFreedByte, slotSize); |
| #endif |
| + |
| + PartitionAllocHooks::maybeInvokeFreeHook(ptr); |
|
haraken
2015/10/20 00:14:19
You need to insert the free hook to partitionDirec
Ruud van Asseldonk
2015/10/20 11:43:57
That makes sense. Fixed. What about |partitionReal
|
| + |
| ASSERT(page->numAllocatedSlots); |
| PartitionFreelistEntry* freelistHead = page->freelistHead; |
| ASSERT(!freelistHead || partitionPointerIsValid(freelistHead)); |