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 dispose() |
aandrey
2014/12/12 10:18:53
turns out, we also need clear(), see comment below
sof
2014/12/12 10:32:47
Done.
| |
74 { | 78 { |
79 ASSERT(m_tracker); | |
75 for (auto it : m_asyncCallChains) { | 80 for (auto it : m_asyncCallChains) { |
76 if (AsyncCallStackTracker::Listener* listener = m_tracker->m_listene r) | 81 if (AsyncCallStackTracker::Listener* listener = m_tracker->m_listene r) |
77 listener->didRemoveAsyncCallChain(it.value.get()); | 82 listener->didRemoveAsyncCallChain(it.value.get()); |
78 else | 83 else |
79 break; | 84 break; |
80 } | 85 } |
81 m_asyncCallChains.clear(); | 86 m_asyncCallChains.clear(); |
87 m_tracker = nullptr; | |
82 } | 88 } |
83 | 89 |
84 void set(typename MapType::KeyPeekInType key, PassRefPtrWillBeRawPtr<AsyncCa llChain> chain) | 90 void set(typename MapType::KeyPeekInType key, PassRefPtrWillBeRawPtr<AsyncCa llChain> chain) |
85 { | 91 { |
86 m_asyncCallChains.set(key, chain); | 92 m_asyncCallChains.set(key, chain); |
87 } | 93 } |
88 | 94 |
89 bool contains(typename MapType::KeyPeekInType key) const | 95 bool contains(typename MapType::KeyPeekInType key) const |
90 { | 96 { |
91 return m_asyncCallChains.contains(key); | 97 return m_asyncCallChains.contains(key); |
92 } | 98 } |
93 | 99 |
94 PassRefPtrWillBeRawPtr<AsyncCallChain> get(typename MapType::KeyPeekInType k ey) const | 100 PassRefPtrWillBeRawPtr<AsyncCallChain> get(typename MapType::KeyPeekInType k ey) const |
95 { | 101 { |
96 return m_asyncCallChains.get(key); | 102 return m_asyncCallChains.get(key); |
97 } | 103 } |
98 | 104 |
99 void remove(typename MapType::KeyPeekInType key) | 105 void remove(typename MapType::KeyPeekInType key) |
100 { | 106 { |
107 ASSERT(m_tracker); | |
101 RefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> chain = m_asyn cCallChains.take(key); | 108 RefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> chain = m_asyn cCallChains.take(key); |
102 if (chain && m_tracker->m_listener) | 109 if (chain && m_tracker->m_listener) |
103 m_tracker->m_listener->didRemoveAsyncCallChain(chain.get()); | 110 m_tracker->m_listener->didRemoveAsyncCallChain(chain.get()); |
104 } | 111 } |
105 | 112 |
106 void trace(Visitor* visitor) | 113 void trace(Visitor* visitor) |
107 { | 114 { |
115 visitor->trace(m_tracker); | |
108 visitor->trace(m_asyncCallChains); | 116 visitor->trace(m_asyncCallChains); |
109 } | 117 } |
110 | 118 |
111 private: | 119 private: |
112 AsyncCallStackTracker* m_tracker; | 120 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; |
113 MapType m_asyncCallChains; | 121 MapType m_asyncCallChains; |
114 }; | 122 }; |
115 | 123 |
116 class AsyncCallStackTracker::ExecutionContextData final : public NoBaseWillBeGar bageCollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver { | 124 class AsyncCallStackTracker::ExecutionContextData final : public NoBaseWillBeGar bageCollectedFinalized<ExecutionContextData>, public ContextLifecycleObserver { |
117 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | 125 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
118 public: | 126 public: |
119 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu tionContext) | 127 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu tionContext) |
120 : ContextLifecycleObserver(executionContext) | 128 : ContextLifecycleObserver(executionContext) |
121 , m_tracker(tracker) | 129 , m_tracker(tracker) |
122 , m_timerCallChains(tracker) | 130 , m_timerCallChains(tracker) |
123 , m_animationFrameCallChains(tracker) | 131 , m_animationFrameCallChains(tracker) |
124 , m_eventCallChains(tracker) | 132 , m_eventCallChains(tracker) |
125 , m_xhrCallChains(tracker) | 133 , m_xhrCallChains(tracker) |
126 , m_mutationObserverCallChains(tracker) | 134 , m_mutationObserverCallChains(tracker) |
127 , m_executionContextTaskCallChains(tracker) | 135 , m_executionContextTaskCallChains(tracker) |
128 , m_v8AsyncTaskCallChains(tracker) | 136 , m_v8AsyncTaskCallChains(tracker) |
129 , m_asyncOperationCallChains(tracker) | 137 , m_asyncOperationCallChains(tracker) |
130 , m_circularSequentialId(0) | 138 , m_circularSequentialId(0) |
131 { | 139 { |
132 } | 140 } |
133 | 141 |
134 virtual void contextDestroyed() override | 142 virtual void contextDestroyed() override |
135 { | 143 { |
136 ASSERT(executionContext()); | 144 ASSERT(executionContext()); |
137 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo ntextDataMap.take(executionContext()); | 145 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionCo ntextDataMap.take(executionContext()); |
138 ASSERT_UNUSED(self, self == this); | 146 ASSERT_UNUSED(self, self == this); |
139 ContextLifecycleObserver::contextDestroyed(); | 147 ContextLifecycleObserver::contextDestroyed(); |
148 dispose(); | |
140 } | 149 } |
141 | 150 |
142 int nextAsyncOperationUniqueId() | 151 int nextAsyncOperationUniqueId() |
143 { | 152 { |
144 do { | 153 do { |
145 ++m_circularSequentialId; | 154 ++m_circularSequentialId; |
146 if (m_circularSequentialId <= 0) | 155 if (m_circularSequentialId <= 0) |
147 m_circularSequentialId = 1; | 156 m_circularSequentialId = 1; |
148 } while (m_asyncOperationCallChains.contains(m_circularSequentialId)); | 157 } while (m_asyncOperationCallChains.contains(m_circularSequentialId)); |
149 return m_circularSequentialId; | 158 return m_circularSequentialId; |
150 } | 159 } |
151 | 160 |
152 void trace(Visitor* visitor) | 161 void trace(Visitor* visitor) |
153 { | 162 { |
154 visitor->trace(m_tracker); | 163 visitor->trace(m_tracker); |
155 #if ENABLE(OILPAN) | 164 #if ENABLE(OILPAN) |
156 visitor->trace(m_timerCallChains); | 165 visitor->trace(m_timerCallChains); |
157 visitor->trace(m_animationFrameCallChains); | 166 visitor->trace(m_animationFrameCallChains); |
158 visitor->trace(m_eventCallChains); | 167 visitor->trace(m_eventCallChains); |
159 visitor->trace(m_xhrCallChains); | 168 visitor->trace(m_xhrCallChains); |
160 visitor->trace(m_mutationObserverCallChains); | 169 visitor->trace(m_mutationObserverCallChains); |
161 visitor->trace(m_executionContextTaskCallChains); | 170 visitor->trace(m_executionContextTaskCallChains); |
162 visitor->trace(m_v8AsyncTaskCallChains); | 171 visitor->trace(m_v8AsyncTaskCallChains); |
163 visitor->trace(m_asyncOperationCallChains); | 172 visitor->trace(m_asyncOperationCallChains); |
164 #endif | 173 #endif |
165 } | 174 } |
166 | 175 |
176 void dispose() | |
177 { | |
178 m_timerCallChains.dispose(); | |
179 m_animationFrameCallChains.dispose(); | |
180 m_eventCallChains.dispose(); | |
181 m_xhrCallChains.dispose(); | |
182 m_mutationObserverCallChains.dispose(); | |
183 m_executionContextTaskCallChains.dispose(); | |
184 m_v8AsyncTaskCallChains.dispose(); | |
185 m_asyncOperationCallChains.dispose(); | |
186 } | |
187 | |
167 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; | 188 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; |
168 HashSet<int> m_intervalTimerIds; | 189 HashSet<int> m_intervalTimerIds; |
169 AsyncCallChainMap<int> m_timerCallChains; | 190 AsyncCallChainMap<int> m_timerCallChains; |
170 AsyncCallChainMap<int> m_animationFrameCallChains; | 191 AsyncCallChainMap<int> m_animationFrameCallChains; |
171 AsyncCallChainMap<RawPtrWillBeMember<Event> > m_eventCallChains; | 192 AsyncCallChainMap<RawPtrWillBeMember<Event> > m_eventCallChains; |
172 AsyncCallChainMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains; | 193 AsyncCallChainMap<RawPtrWillBeMember<EventTarget> > m_xhrCallChains; |
173 AsyncCallChainMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC allChains; | 194 AsyncCallChainMap<RawPtrWillBeMember<MutationObserver> > m_mutationObserverC allChains; |
174 AsyncCallChainMap<ExecutionContextTask*> m_executionContextTaskCallChains; | 195 AsyncCallChainMap<ExecutionContextTask*> m_executionContextTaskCallChains; |
175 AsyncCallChainMap<String> m_v8AsyncTaskCallChains; | 196 AsyncCallChainMap<String> m_v8AsyncTaskCallChains; |
176 AsyncCallChainMap<int> m_asyncOperationCallChains; | 197 AsyncCallChainMap<int> m_asyncOperationCallChains; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 return; | 448 return; |
428 ExecutionContextData* data = createContextDataIfNeeded(context); | 449 ExecutionContextData* data = createContextDataIfNeeded(context); |
429 data->m_executionContextTaskCallChains.set(task, createAsyncCallChain(task-> taskNameForInstrumentation(), callFrames)); | 450 data->m_executionContextTaskCallChains.set(task, createAsyncCallChain(task-> taskNameForInstrumentation(), callFrames)); |
430 } | 451 } |
431 | 452 |
432 void AsyncCallStackTracker::didKillAllExecutionContextTasks(ExecutionContext* co ntext) | 453 void AsyncCallStackTracker::didKillAllExecutionContextTasks(ExecutionContext* co ntext) |
433 { | 454 { |
434 ASSERT(context); | 455 ASSERT(context); |
435 ASSERT(isEnabled()); | 456 ASSERT(isEnabled()); |
436 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 457 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
437 data->m_executionContextTaskCallChains.clear(); | 458 data->m_executionContextTaskCallChains.dispose(); |
aandrey
2014/12/12 10:18:53
this should be clear() and leave m_executionContex
sof
2014/12/12 10:26:06
Seems like the null check in clear() wasn't such a
sof
2014/12/12 10:32:47
Done.
| |
438 } | 459 } |
439 | 460 |
440 void AsyncCallStackTracker::willPerformExecutionContextTask(ExecutionContext* co ntext, ExecutionContextTask* task) | 461 void AsyncCallStackTracker::willPerformExecutionContextTask(ExecutionContext* co ntext, ExecutionContextTask* task) |
441 { | 462 { |
442 ASSERT(context); | 463 ASSERT(context); |
443 ASSERT(isEnabled()); | 464 ASSERT(isEnabled()); |
444 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { | 465 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { |
445 setCurrentAsyncCallChain(context, data->m_executionContextTaskCallChains .get(task)); | 466 setCurrentAsyncCallChain(context, data->m_executionContextTaskCallChains .get(task)); |
446 data->m_executionContextTaskCallChains.remove(task); | 467 data->m_executionContextTaskCallChains.remove(task); |
447 } else { | 468 } else { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy ncCallStackTracker::ExecutionContextData(this, context))) | 612 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy ncCallStackTracker::ExecutionContextData(this, context))) |
592 .storedValue->value.get(); | 613 .storedValue->value.get(); |
593 } | 614 } |
594 return data; | 615 return data; |
595 } | 616 } |
596 | 617 |
597 void AsyncCallStackTracker::clear() | 618 void AsyncCallStackTracker::clear() |
598 { | 619 { |
599 m_currentAsyncCallChain.clear(); | 620 m_currentAsyncCallChain.clear(); |
600 m_nestedAsyncCallCount = 0; | 621 m_nestedAsyncCallCount = 0; |
622 for (auto& it : m_executionContextDataMap) | |
623 it.value->dispose(); | |
601 m_executionContextDataMap.clear(); | 624 m_executionContextDataMap.clear(); |
602 } | 625 } |
603 | 626 |
604 void AsyncCallStackTracker::trace(Visitor* visitor) | 627 void AsyncCallStackTracker::trace(Visitor* visitor) |
605 { | 628 { |
606 visitor->trace(m_currentAsyncCallChain); | 629 visitor->trace(m_currentAsyncCallChain); |
607 #if ENABLE(OILPAN) | 630 #if ENABLE(OILPAN) |
608 visitor->trace(m_executionContextDataMap); | 631 visitor->trace(m_executionContextDataMap); |
609 #endif | 632 #endif |
610 } | 633 } |
611 | 634 |
612 } // namespace blink | 635 } // namespace blink |
OLD | NEW |