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

Side by Side Diff: third_party/WebKit/Source/platform/heap/Heap.h

Issue 1711643002: Show type names in Oilpan heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue-585063-impl-hooks
Patch Set: Created 4 years, 10 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 | « third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.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 30 matching lines...) Expand all
41 #include "wtf/Allocator.h" 41 #include "wtf/Allocator.h"
42 #include "wtf/Assertions.h" 42 #include "wtf/Assertions.h"
43 #include "wtf/Atomics.h" 43 #include "wtf/Atomics.h"
44 #include "wtf/Forward.h" 44 #include "wtf/Forward.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 class PLATFORM_EXPORT HeapAllocHooks { 48 class PLATFORM_EXPORT HeapAllocHooks {
49 public: 49 public:
50 // TODO(hajimehoshi): Pass a type name of the allocated object. 50 // TODO(hajimehoshi): Pass a type name of the allocated object.
51 typedef void AllocationHook(Address, size_t); 51 typedef void AllocationHook(Address, size_t, const char*);
52 typedef void FreeHook(Address); 52 typedef void FreeHook(Address);
53 53
54 static void setAllocationHook(AllocationHook* hook) { m_allocationHook = hoo k; } 54 static void setAllocationHook(AllocationHook* hook) { m_allocationHook = hoo k; }
55 static void setFreeHook(FreeHook* hook) { m_freeHook = hook; } 55 static void setFreeHook(FreeHook* hook) { m_freeHook = hook; }
56 56
57 static void allocationHookIfEnabled(Address address, size_t size) 57 static void allocationHookIfEnabled(Address address, size_t size, const char * typeName)
58 { 58 {
59 AllocationHook* allocationHook = m_allocationHook; 59 AllocationHook* allocationHook = m_allocationHook;
60 if (UNLIKELY(!!allocationHook)) 60 if (UNLIKELY(!!allocationHook))
61 allocationHook(address, size); 61 allocationHook(address, size, typeName);
62 } 62 }
63 63
64 static void freeHookIfEnabled(Address address) 64 static void freeHookIfEnabled(Address address)
65 { 65 {
66 FreeHook* freeHook = m_freeHook; 66 FreeHook* freeHook = m_freeHook;
67 if (UNLIKELY(!!freeHook)) 67 if (UNLIKELY(!!freeHook))
68 freeHook(address); 68 freeHook(address);
69 } 69 }
70 70
71 static void reallocHookIfEnabled(Address oldAddress, Address newAddress, siz e_t size) 71 static void reallocHookIfEnabled(Address oldAddress, Address newAddress, siz e_t size, const char* typeName)
72 { 72 {
73 // Report a reallocation as a free followed by an allocation. 73 // Report a reallocation as a free followed by an allocation.
74 AllocationHook* allocationHook = m_allocationHook; 74 AllocationHook* allocationHook = m_allocationHook;
75 FreeHook* freeHook = m_freeHook; 75 FreeHook* freeHook = m_freeHook;
76 if (UNLIKELY(allocationHook && freeHook)) { 76 if (UNLIKELY(allocationHook && freeHook)) {
77 freeHook(oldAddress); 77 freeHook(oldAddress);
78 allocationHook(newAddress, size); 78 allocationHook(newAddress, size, typeName);
79 } 79 }
80 } 80 }
81 81
82 private: 82 private:
83 static AllocationHook* m_allocationHook; 83 static AllocationHook* m_allocationHook;
84 static FreeHook* m_freeHook; 84 static FreeHook* m_freeHook;
85 }; 85 };
86 86
87 class CrossThreadPersistentRegion; 87 class CrossThreadPersistentRegion;
88 template<typename T> class Member; 88 template<typename T> class Member;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex); 489 ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex);
490 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); 490 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex));
491 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex); 491 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex);
492 } 492 }
493 493
494 template<typename T> 494 template<typename T>
495 Address Heap::allocate(size_t size, bool eagerlySweep) 495 Address Heap::allocate(size_t size, bool eagerlySweep)
496 { 496 {
497 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); 497 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state();
498 Address address = Heap::allocateOnHeapIndex(state, size, eagerlySweep ? Blin kGC::EagerSweepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::i ndex()); 498 Address address = Heap::allocateOnHeapIndex(state, size, eagerlySweep ? Blin kGC::EagerSweepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::i ndex());
499 HeapAllocHooks::allocationHookIfEnabled(address, size); 499 const char* typeName = WTF_HEAP_PROFILER_TYPE_NAME(T);
500 HeapAllocHooks::allocationHookIfEnabled(address, size, typeName);
500 return address; 501 return address;
501 } 502 }
502 503
503 template<typename T> 504 template<typename T>
504 Address Heap::reallocate(void* previous, size_t size) 505 Address Heap::reallocate(void* previous, size_t size)
505 { 506 {
506 // Not intended to be a full C realloc() substitute; 507 // Not intended to be a full C realloc() substitute;
507 // realloc(nullptr, size) is not a supported alias for malloc(size). 508 // realloc(nullptr, size) is not a supported alias for malloc(size).
508 509
509 // TODO(sof): promptly free the previous object. 510 // TODO(sof): promptly free the previous object.
(...skipping 13 matching lines...) Expand all
523 heapIndex = heapIndexForObjectSize(size); 524 heapIndex = heapIndexForObjectSize(size);
524 525
525 // TODO(haraken): We don't support reallocate() for finalizable objects. 526 // TODO(haraken): We don't support reallocate() for finalizable objects.
526 ASSERT(!Heap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer()); 527 ASSERT(!Heap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer());
527 ASSERT(previousHeader->gcInfoIndex() == GCInfoTrait<T>::index()); 528 ASSERT(previousHeader->gcInfoIndex() == GCInfoTrait<T>::index());
528 Address address = Heap::allocateOnHeapIndex(state, size, heapIndex, GCInfoTr ait<T>::index()); 529 Address address = Heap::allocateOnHeapIndex(state, size, heapIndex, GCInfoTr ait<T>::index());
529 size_t copySize = previousHeader->payloadSize(); 530 size_t copySize = previousHeader->payloadSize();
530 if (copySize > size) 531 if (copySize > size)
531 copySize = size; 532 copySize = size;
532 memcpy(address, previous, copySize); 533 memcpy(address, previous, copySize);
533 HeapAllocHooks::reallocHookIfEnabled(static_cast<Address>(previous), address , size); 534 const char* typeName = WTF_HEAP_PROFILER_TYPE_NAME(T);
535 HeapAllocHooks::reallocHookIfEnabled(static_cast<Address>(previous), address , size, typeName);
534 return address; 536 return address;
535 } 537 }
536 538
537 template<typename Derived> 539 template<typename Derived>
538 template<typename T> 540 template<typename T>
539 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) 541 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object)
540 { 542 {
541 T** cell = reinterpret_cast<T**>(object); 543 T** cell = reinterpret_cast<T**>(object);
542 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) 544 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell))
543 *cell = nullptr; 545 *cell = nullptr;
544 } 546 }
545 547
546 } // namespace blink 548 } // namespace blink
547 549
548 #endif // Heap_h 550 #endif // Heap_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/BlinkGCMemoryDumpProvider.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698