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