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