| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 } | 57 } |
| 58 | 58 |
| 59 namespace blink { | 59 namespace blink { |
| 60 | 60 |
| 61 template <class K> | 61 template <class K> |
| 62 class AsyncCallStackTracker::AsyncCallChainMap final { | 62 class AsyncCallStackTracker::AsyncCallChainMap final { |
| 63 ALLOW_ONLY_INLINE_ALLOCATION(); | 63 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 64 public: | 64 public: |
| 65 using MapType = WillBeHeapHashMap<K, RefPtrWillBeMember<AsyncCallStackTracke
r::AsyncCallChain>>; | 65 using MapType = WillBeHeapHashMap<K, RefPtrWillBeMember<AsyncCallStackTracke
r::AsyncCallChain>>; |
| 66 explicit AsyncCallChainMap(AsyncCallStackTracker* tracker) : m_tracker(track
er) { } | 66 explicit AsyncCallChainMap(AsyncCallStackTracker* tracker) |
| 67 : m_tracker(tracker) |
| 68 { |
| 69 } |
| 67 | 70 |
| 68 ~AsyncCallChainMap() | 71 ~AsyncCallChainMap() |
| 69 { | 72 { |
| 73 // Verify that this object has been explicitly cleared already. |
| 74 ASSERT(!m_tracker); |
| 75 } |
| 76 |
| 77 void dispose() |
| 78 { |
| 70 clear(); | 79 clear(); |
| 80 m_tracker = nullptr; |
| 71 } | 81 } |
| 72 | 82 |
| 73 void clear() | 83 void clear() |
| 74 { | 84 { |
| 85 ASSERT(m_tracker); |
| 75 for (auto it : m_asyncCallChains) { | 86 for (auto it : m_asyncCallChains) { |
| 76 if (AsyncCallStackTracker::Listener* listener = m_tracker->m_listene
r) | 87 if (AsyncCallStackTracker::Listener* listener = m_tracker->m_listene
r) |
| 77 listener->didRemoveAsyncCallChain(it.value.get()); | 88 listener->didRemoveAsyncCallChain(it.value.get()); |
| 78 else | 89 else |
| 79 break; | 90 break; |
| 80 } | 91 } |
| 81 m_asyncCallChains.clear(); | 92 m_asyncCallChains.clear(); |
| 82 } | 93 } |
| 83 | 94 |
| 84 void set(typename MapType::KeyPeekInType key, PassRefPtrWillBeRawPtr<AsyncCa
llChain> chain) | 95 void set(typename MapType::KeyPeekInType key, PassRefPtrWillBeRawPtr<AsyncCa
llChain> chain) |
| 85 { | 96 { |
| 86 m_asyncCallChains.set(key, chain); | 97 m_asyncCallChains.set(key, chain); |
| 87 } | 98 } |
| 88 | 99 |
| 89 bool contains(typename MapType::KeyPeekInType key) const | 100 bool contains(typename MapType::KeyPeekInType key) const |
| 90 { | 101 { |
| 91 return m_asyncCallChains.contains(key); | 102 return m_asyncCallChains.contains(key); |
| 92 } | 103 } |
| 93 | 104 |
| 94 PassRefPtrWillBeRawPtr<AsyncCallChain> get(typename MapType::KeyPeekInType k
ey) const | 105 PassRefPtrWillBeRawPtr<AsyncCallChain> get(typename MapType::KeyPeekInType k
ey) const |
| 95 { | 106 { |
| 96 return m_asyncCallChains.get(key); | 107 return m_asyncCallChains.get(key); |
| 97 } | 108 } |
| 98 | 109 |
| 99 void remove(typename MapType::KeyPeekInType key) | 110 void remove(typename MapType::KeyPeekInType key) |
| 100 { | 111 { |
| 112 ASSERT(m_tracker); |
| 101 RefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> chain = m_asyn
cCallChains.take(key); | 113 RefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> chain = m_asyn
cCallChains.take(key); |
| 102 if (chain && m_tracker->m_listener) | 114 if (chain && m_tracker->m_listener) |
| 103 m_tracker->m_listener->didRemoveAsyncCallChain(chain.get()); | 115 m_tracker->m_listener->didRemoveAsyncCallChain(chain.get()); |
| 104 } | 116 } |
| 105 | 117 |
| 106 void trace(Visitor* visitor) | 118 void trace(Visitor* visitor) |
| 107 { | 119 { |
| 120 visitor->trace(m_tracker); |
| 108 visitor->trace(m_asyncCallChains); | 121 visitor->trace(m_asyncCallChains); |
| 109 } | 122 } |
| 110 | 123 |
| 111 private: | 124 private: |
| 112 AsyncCallStackTracker* m_tracker; | 125 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; |
| 113 MapType m_asyncCallChains; | 126 MapType m_asyncCallChains; |
| 114 }; | 127 }; |
| 115 | 128 |
| 116 class AsyncCallStackTracker::ExecutionContextData final : public NoBaseWillBeGar
bageCollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver { | 129 class AsyncCallStackTracker::ExecutionContextData final : public NoBaseWillBeGar
bageCollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver { |
| 117 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | 130 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 118 public: | 131 public: |
| 119 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu
tionContext) | 132 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu
tionContext) |
| 120 : ContextLifecycleObserver(executionContext) | 133 : ContextLifecycleObserver(executionContext) |
| 121 , m_tracker(tracker) | 134 , m_tracker(tracker) |
| 122 , m_timerCallChains(tracker) | 135 , m_timerCallChains(tracker) |
| 123 , m_animationFrameCallChains(tracker) | 136 , m_animationFrameCallChains(tracker) |
| 124 , m_eventCallChains(tracker) | 137 , m_eventCallChains(tracker) |
| 125 , m_xhrCallChains(tracker) | 138 , m_xhrCallChains(tracker) |
| 126 , m_mutationObserverCallChains(tracker) | 139 , m_mutationObserverCallChains(tracker) |
| 127 , m_executionContextTaskCallChains(tracker) | 140 , m_executionContextTaskCallChains(tracker) |
| 128 , m_v8AsyncTaskCallChains(tracker) | 141 , m_v8AsyncTaskCallChains(tracker) |
| 129 , m_asyncOperationCallChains(tracker) | 142 , m_asyncOperationCallChains(tracker) |
| 130 , m_circularSequentialId(0) | 143 , m_circularSequentialId(0) |
| 131 { | 144 { |
| 132 } | 145 } |
| 133 | 146 |
| 134 virtual void contextDestroyed() override | 147 virtual void contextDestroyed() override |
| 135 { | 148 { |
| 136 ASSERT(executionContext()); | 149 ASSERT(executionContext()); |
| 137 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo
ntextDataMap.take(executionContext()); | 150 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo
ntextDataMap.take(executionContext()); |
| 138 ASSERT_UNUSED(self, self == this); | 151 ASSERT_UNUSED(self, self == this); |
| 139 ContextLifecycleObserver::contextDestroyed(); | 152 ContextLifecycleObserver::contextDestroyed(); |
| 153 dispose(); |
| 140 } | 154 } |
| 141 | 155 |
| 142 int nextAsyncOperationUniqueId() | 156 int nextAsyncOperationUniqueId() |
| 143 { | 157 { |
| 144 do { | 158 do { |
| 145 ++m_circularSequentialId; | 159 ++m_circularSequentialId; |
| 146 if (m_circularSequentialId <= 0) | 160 if (m_circularSequentialId <= 0) |
| 147 m_circularSequentialId = 1; | 161 m_circularSequentialId = 1; |
| 148 } while (m_asyncOperationCallChains.contains(m_circularSequentialId)); | 162 } while (m_asyncOperationCallChains.contains(m_circularSequentialId)); |
| 149 return m_circularSequentialId; | 163 return m_circularSequentialId; |
| 150 } | 164 } |
| 151 | 165 |
| 152 void trace(Visitor* visitor) | 166 void trace(Visitor* visitor) |
| 153 { | 167 { |
| 154 visitor->trace(m_tracker); | 168 visitor->trace(m_tracker); |
| 155 #if ENABLE(OILPAN) | 169 #if ENABLE(OILPAN) |
| 156 visitor->trace(m_timerCallChains); | 170 visitor->trace(m_timerCallChains); |
| 157 visitor->trace(m_animationFrameCallChains); | 171 visitor->trace(m_animationFrameCallChains); |
| 158 visitor->trace(m_eventCallChains); | 172 visitor->trace(m_eventCallChains); |
| 159 visitor->trace(m_xhrCallChains); | 173 visitor->trace(m_xhrCallChains); |
| 160 visitor->trace(m_mutationObserverCallChains); | 174 visitor->trace(m_mutationObserverCallChains); |
| 161 visitor->trace(m_executionContextTaskCallChains); | 175 visitor->trace(m_executionContextTaskCallChains); |
| 162 visitor->trace(m_v8AsyncTaskCallChains); | 176 visitor->trace(m_v8AsyncTaskCallChains); |
| 163 visitor->trace(m_asyncOperationCallChains); | 177 visitor->trace(m_asyncOperationCallChains); |
| 164 #endif | 178 #endif |
| 165 } | 179 } |
| 166 | 180 |
| 181 void dispose() |
| 182 { |
| 183 m_timerCallChains.dispose(); |
| 184 m_animationFrameCallChains.dispose(); |
| 185 m_eventCallChains.dispose(); |
| 186 m_xhrCallChains.dispose(); |
| 187 m_mutationObserverCallChains.dispose(); |
| 188 m_executionContextTaskCallChains.dispose(); |
| 189 m_v8AsyncTaskCallChains.dispose(); |
| 190 m_asyncOperationCallChains.dispose(); |
| 191 } |
| 192 |
| 167 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; | 193 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; |
| 168 HashSet<int> m_intervalTimerIds; | 194 HashSet<int> m_intervalTimerIds; |
| 169 AsyncCallChainMap<int> m_timerCallChains; | 195 AsyncCallChainMap<int> m_timerCallChains; |
| 170 AsyncCallChainMap<int> m_animationFrameCallChains; | 196 AsyncCallChainMap<int> m_animationFrameCallChains; |
| 171 AsyncCallChainMap<RawPtrWillBeMember<Event> > m_eventCallChains; | 197 AsyncCallChainMap<RawPtrWillBeMember<Event> > m_eventCallChains; |
| 172 AsyncCallChainMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains; | 198 AsyncCallChainMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains; |
| 173 AsyncCallChainMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC
allChains; | 199 AsyncCallChainMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC
allChains; |
| 174 AsyncCallChainMap<ExecutionContextTask*> m_executionContextTaskCallChains; | 200 AsyncCallChainMap<ExecutionContextTask*> m_executionContextTaskCallChains; |
| 175 AsyncCallChainMap<String> m_v8AsyncTaskCallChains; | 201 AsyncCallChainMap<String> m_v8AsyncTaskCallChains; |
| 176 AsyncCallChainMap<int> m_asyncOperationCallChains; | 202 AsyncCallChainMap<int> m_asyncOperationCallChains; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy
ncCallStackTracker::ExecutionContextData(this, context))) | 617 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy
ncCallStackTracker::ExecutionContextData(this, context))) |
| 592 .storedValue->value.get(); | 618 .storedValue->value.get(); |
| 593 } | 619 } |
| 594 return data; | 620 return data; |
| 595 } | 621 } |
| 596 | 622 |
| 597 void AsyncCallStackTracker::clear() | 623 void AsyncCallStackTracker::clear() |
| 598 { | 624 { |
| 599 m_currentAsyncCallChain.clear(); | 625 m_currentAsyncCallChain.clear(); |
| 600 m_nestedAsyncCallCount = 0; | 626 m_nestedAsyncCallCount = 0; |
| 627 for (auto& it : m_executionContextDataMap) |
| 628 it.value->dispose(); |
| 601 m_executionContextDataMap.clear(); | 629 m_executionContextDataMap.clear(); |
| 602 } | 630 } |
| 603 | 631 |
| 604 void AsyncCallStackTracker::trace(Visitor* visitor) | 632 void AsyncCallStackTracker::trace(Visitor* visitor) |
| 605 { | 633 { |
| 606 visitor->trace(m_currentAsyncCallChain); | 634 visitor->trace(m_currentAsyncCallChain); |
| 607 #if ENABLE(OILPAN) | 635 #if ENABLE(OILPAN) |
| 608 visitor->trace(m_executionContextDataMap); | 636 visitor->trace(m_executionContextDataMap); |
| 609 #endif | 637 #endif |
| 610 } | 638 } |
| 611 | 639 |
| 612 } // namespace blink | 640 } // namespace blink |
| OLD | NEW |