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 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ThreadState_h | 31 #ifndef ThreadState_h |
| 32 #define ThreadState_h | 32 #define ThreadState_h |
| 33 | 33 |
| 34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
| 35 #include "platform/heap/AddressSanitizer.h" | 35 #include "platform/heap/AddressSanitizer.h" |
| 36 #include "platform/heap/ThreadingTraits.h" | 36 #include "platform/heap/ThreadingTraits.h" |
| 37 #include "public/platform/WebMemoryDumpProvider.h" | |
| 37 #include "public/platform/WebThread.h" | 38 #include "public/platform/WebThread.h" |
| 38 #include "wtf/Forward.h" | 39 #include "wtf/Forward.h" |
| 39 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
| 40 #include "wtf/HashSet.h" | 41 #include "wtf/HashSet.h" |
| 41 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
| 42 #include "wtf/ThreadSpecific.h" | 43 #include "wtf/ThreadSpecific.h" |
| 43 #include "wtf/Threading.h" | 44 #include "wtf/Threading.h" |
| 44 #include "wtf/ThreadingPrimitives.h" | 45 #include "wtf/ThreadingPrimitives.h" |
| 45 #include "wtf/text/WTFString.h" | 46 #include "wtf/text/WTFString.h" |
| 46 | 47 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 const size_t numberOfGenerationsToTrack = 8; | 158 const size_t numberOfGenerationsToTrack = 8; |
| 158 const size_t maxHeapObjectAge = numberOfGenerationsToTrack - 1; | 159 const size_t maxHeapObjectAge = numberOfGenerationsToTrack - 1; |
| 159 | 160 |
| 160 struct AgeCounts { | 161 struct AgeCounts { |
| 161 int ages[numberOfGenerationsToTrack]; | 162 int ages[numberOfGenerationsToTrack]; |
| 162 AgeCounts() { std::fill(ages, ages + numberOfGenerationsToTrack, 0); } | 163 AgeCounts() { std::fill(ages, ages + numberOfGenerationsToTrack, 0); } |
| 163 }; | 164 }; |
| 164 typedef HashMap<String, AgeCounts> ClassAgeCountsMap; | 165 typedef HashMap<String, AgeCounts> ClassAgeCountsMap; |
| 165 #endif | 166 #endif |
| 166 | 167 |
| 167 class PLATFORM_EXPORT ThreadState { | 168 class PLATFORM_EXPORT ThreadState : public WebMemoryDumpProvider { |
| 168 WTF_MAKE_NONCOPYABLE(ThreadState); | 169 WTF_MAKE_NONCOPYABLE(ThreadState); |
| 169 public: | 170 public: |
| 170 // When garbage collecting we need to know whether or not there | 171 // When garbage collecting we need to know whether or not there |
| 171 // can be pointers to Blink GC managed objects on the stack for | 172 // can be pointers to Blink GC managed objects on the stack for |
| 172 // each thread. When threads reach a safe point they record | 173 // each thread. When threads reach a safe point they record |
| 173 // whether or not they have pointers on the stack. | 174 // whether or not they have pointers on the stack. |
| 174 enum StackState { | 175 enum StackState { |
| 175 NoHeapPointersOnStack, | 176 NoHeapPointersOnStack, |
| 176 HeapPointersOnStack | 177 HeapPointersOnStack |
| 177 }; | 178 }; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 // Visit local thread stack and trace all pointers conservatively. | 451 // Visit local thread stack and trace all pointers conservatively. |
| 451 void visitStack(Visitor*); | 452 void visitStack(Visitor*); |
| 452 | 453 |
| 453 // Visit the asan fake stack frame corresponding to a slot on the | 454 // Visit the asan fake stack frame corresponding to a slot on the |
| 454 // real machine stack if there is one. | 455 // real machine stack if there is one. |
| 455 void visitAsanFakeStackForPointer(Visitor*, Address); | 456 void visitAsanFakeStackForPointer(Visitor*, Address); |
| 456 | 457 |
| 457 // Visit all persistents allocated on this thread. | 458 // Visit all persistents allocated on this thread. |
| 458 void visitPersistents(Visitor*); | 459 void visitPersistents(Visitor*); |
| 459 | 460 |
| 461 void dumpMemoryIfNecessary(); | |
|
petrcermak
2015/05/21 13:15:57
Maybe add one or two one-line comments explaining
ssid
2015/05/21 16:55:28
Done.
| |
| 462 void dumpMemory(); | |
| 463 | |
| 460 #if ENABLE(GC_PROFILING) | 464 #if ENABLE(GC_PROFILING) |
| 461 const GCInfo* findGCInfo(Address); | 465 const GCInfo* findGCInfo(Address); |
| 462 static const GCInfo* findGCInfoFromAllThreads(Address); | 466 static const GCInfo* findGCInfoFromAllThreads(Address); |
| 463 | 467 |
| 464 struct SnapshotInfo { | 468 struct SnapshotInfo { |
| 465 ThreadState* state; | 469 ThreadState* state; |
| 466 | 470 |
| 467 size_t freeSize; | 471 size_t freeSize; |
| 468 size_t pageCount; | 472 size_t pageCount; |
| 469 | 473 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 return m_heaps[heapIndex]; | 606 return m_heaps[heapIndex]; |
| 603 } | 607 } |
| 604 BaseHeap* expandedVectorBackingHeap(size_t gcInfoIndex); | 608 BaseHeap* expandedVectorBackingHeap(size_t gcInfoIndex); |
| 605 static bool isVectorHeapIndex(int heapIndex) | 609 static bool isVectorHeapIndex(int heapIndex) |
| 606 { | 610 { |
| 607 return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex; | 611 return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex; |
| 608 } | 612 } |
| 609 void allocationPointAdjusted(int heapIndex); | 613 void allocationPointAdjusted(int heapIndex); |
| 610 void promptlyFreed(size_t gcInfoIndex); | 614 void promptlyFreed(size_t gcInfoIndex); |
| 611 | 615 |
| 616 // WebMemoryDumpProvider implementation. | |
| 617 bool onMemoryDump(WebProcessMemoryDump*) override; | |
| 618 | |
| 612 private: | 619 private: |
| 613 ThreadState(); | 620 ThreadState(); |
| 614 ~ThreadState(); | 621 ~ThreadState(); |
| 615 | 622 |
| 616 void enterSafePoint(StackState, void*); | 623 void enterSafePoint(StackState, void*); |
| 617 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); | 624 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); |
| 618 void clearSafePointScopeMarker() | 625 void clearSafePointScopeMarker() |
| 619 { | 626 { |
| 620 m_safePointStackCopy.clear(); | 627 m_safePointStackCopy.clear(); |
| 621 m_safePointScopeMarker = nullptr; | 628 m_safePointScopeMarker = nullptr; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 | 706 |
| 700 v8::Isolate* m_isolate; | 707 v8::Isolate* m_isolate; |
| 701 void (*m_traceDOMWrappers)(v8::Isolate*, Visitor*); | 708 void (*m_traceDOMWrappers)(v8::Isolate*, Visitor*); |
| 702 | 709 |
| 703 #if defined(ADDRESS_SANITIZER) | 710 #if defined(ADDRESS_SANITIZER) |
| 704 void* m_asanFakeStack; | 711 void* m_asanFakeStack; |
| 705 #endif | 712 #endif |
| 706 | 713 |
| 707 Vector<PageMemoryRegion*> m_allocatedRegionsSinceLastGC; | 714 Vector<PageMemoryRegion*> m_allocatedRegionsSinceLastGC; |
| 708 | 715 |
| 716 OwnPtr<WebProcessMemoryDump> m_lastProcessMemoryDump; | |
| 717 | |
| 709 #if ENABLE(GC_PROFILING) | 718 #if ENABLE(GC_PROFILING) |
| 710 double m_nextFreeListSnapshotTime; | 719 double m_nextFreeListSnapshotTime; |
| 711 #endif | 720 #endif |
| 712 // Ideally we want to allocate an array of size |gcInfoTableMax| but it will | 721 // Ideally we want to allocate an array of size |gcInfoTableMax| but it will |
| 713 // waste memory. Thus we limit the array size to 2^8 and share one entry | 722 // waste memory. Thus we limit the array size to 2^8 and share one entry |
| 714 // with multiple types of vectors. This won't be an issue in practice, | 723 // with multiple types of vectors. This won't be an issue in practice, |
| 715 // since there will be less than 2^8 types of objects in common cases. | 724 // since there will be less than 2^8 types of objects in common cases. |
| 716 static const int likelyToBePromptlyFreedArraySize = (1 << 8); | 725 static const int likelyToBePromptlyFreedArraySize = (1 << 8); |
| 717 static const int likelyToBePromptlyFreedArrayMask = likelyToBePromptlyFreedA rraySize - 1; | 726 static const int likelyToBePromptlyFreedArrayMask = likelyToBePromptlyFreedA rraySize - 1; |
| 718 OwnPtr<int[]> m_likelyToBePromptlyFreed; | 727 OwnPtr<int[]> m_likelyToBePromptlyFreed; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 731 }; | 740 }; |
| 732 | 741 |
| 733 template<> class ThreadStateFor<AnyThread> { | 742 template<> class ThreadStateFor<AnyThread> { |
| 734 public: | 743 public: |
| 735 static ThreadState* state() { return ThreadState::current(); } | 744 static ThreadState* state() { return ThreadState::current(); } |
| 736 }; | 745 }; |
| 737 | 746 |
| 738 } // namespace blink | 747 } // namespace blink |
| 739 | 748 |
| 740 #endif // ThreadState_h | 749 #endif // ThreadState_h |
| OLD | NEW |