| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 static const char setTimeoutName[] = "setTimeout"; | 49 static const char setTimeoutName[] = "setTimeout"; |
| 50 static const char setIntervalName[] = "setInterval"; | 50 static const char setIntervalName[] = "setInterval"; |
| 51 static const char requestAnimationFrameName[] = "requestAnimationFrame"; | 51 static const char requestAnimationFrameName[] = "requestAnimationFrame"; |
| 52 static const char xhrSendName[] = "XMLHttpRequest.send"; | 52 static const char xhrSendName[] = "XMLHttpRequest.send"; |
| 53 static const char enqueueMutationRecordName[] = "Mutation"; | 53 static const char enqueueMutationRecordName[] = "Mutation"; |
| 54 | 54 |
| 55 } | 55 } |
| 56 | 56 |
| 57 namespace blink { | 57 namespace blink { |
| 58 | 58 |
| 59 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl
eObserver { | 59 class AsyncCallStackTracker::ExecutionContextData FINAL : public NoBaseWillBeGar
bageCollectedFinalized<AsyncCallStackTracker::ExecutionContextData>, public Cont
extLifecycleObserver { |
| 60 WTF_MAKE_FAST_ALLOCATED; | 60 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 61 public: | 61 public: |
| 62 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu
tionContext) | 62 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu
tionContext) |
| 63 : ContextLifecycleObserver(executionContext) | 63 : ContextLifecycleObserver(executionContext) |
| 64 , m_circularSequentialID(0) | 64 , m_circularSequentialID(0) |
| 65 , m_tracker(tracker) | 65 , m_tracker(tracker) |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void contextDestroyed() OVERRIDE | 69 virtual void contextDestroyed() OVERRIDE |
| 70 { | 70 { |
| 71 ASSERT(executionContext()); | 71 ASSERT(executionContext()); |
| 72 ExecutionContextData* self = m_tracker->m_executionContextDataMap.take(e
xecutionContext()); | 72 ExecutionContextData* self = m_tracker->m_executionContextDataMap.take(e
xecutionContext()); |
| 73 ASSERT(self == this); | 73 ASSERT(self == this); |
| 74 ContextLifecycleObserver::contextDestroyed(); | 74 ContextLifecycleObserver::contextDestroyed(); |
| 75 delete self; | 75 delete self; |
| 76 } | 76 } |
| 77 | 77 |
| 78 int circularSequentialID() | 78 int circularSequentialID() |
| 79 { | 79 { |
| 80 ++m_circularSequentialID; | 80 ++m_circularSequentialID; |
| 81 if (m_circularSequentialID <= 0) | 81 if (m_circularSequentialID <= 0) |
| 82 m_circularSequentialID = 1; | 82 m_circularSequentialID = 1; |
| 83 return m_circularSequentialID; | 83 return m_circularSequentialID; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void trace(Visitor* visitor) |
| 87 { |
| 88 visitor->trace(m_tracker); |
| 89 visitor->trace(m_timerCallChains); |
| 90 visitor->trace(m_animationFrameCallChains); |
| 91 visitor->trace(m_eventCallChains); |
| 92 visitor->trace(m_xhrCallChains); |
| 93 visitor->trace(m_mutationObserverCallChains); |
| 94 visitor->trace(m_executionContextTaskCallChains); |
| 95 visitor->trace(m_v8AsyncTaskCallChains); |
| 96 visitor->trace(m_asyncOperationCallChains); |
| 97 } |
| 98 |
| 86 private: | 99 private: |
| 87 int m_circularSequentialID; | 100 int m_circularSequentialID; |
| 88 | 101 |
| 89 public: | 102 public: |
| 90 AsyncCallStackTracker* m_tracker; | 103 RawPtrWillBeMember<AsyncCallStackTracker> m_tracker; |
| 91 HashSet<int> m_intervalTimerIds; | 104 HashSet<int> m_intervalTimerIds; |
| 92 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains; | 105 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_timerCallChain
s; |
| 93 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains; | 106 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_animationFrame
CallChains; |
| 94 HashMap<Event*, RefPtr<AsyncCallChain> > m_eventCallChains; | 107 WillBeHeapHashMap<RawPtrWillBeMember<Event>, RefPtrWillBeMember<AsyncCallCha
in> > m_eventCallChains; |
| 95 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains; | 108 WillBeHeapHashMap<RawPtrWillBeMember<EventTarget>, RefPtrWillBeMember<AsyncC
allChain> > m_xhrCallChains; |
| 96 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh
ains; | 109 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, RefPtrWillBeMember<A
syncCallChain> > m_mutationObserverCallChains; |
| 97 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_executionContextTa
skCallChains; | 110 WillBeHeapHashMap<ExecutionContextTask*, RefPtrWillBeMember<AsyncCallChain>
> m_executionContextTaskCallChains; |
| 98 HashMap<String, RefPtr<AsyncCallChain> > m_v8AsyncTaskCallChains; | 111 WillBeHeapHashMap<String, RefPtrWillBeMember<AsyncCallChain> > m_v8AsyncTask
CallChains; |
| 99 HashMap<int, RefPtr<AsyncCallChain> > m_asyncOperationCallChains; | 112 WillBeHeapHashMap<int, RefPtrWillBeMember<AsyncCallChain> > m_asyncOperation
CallChains; |
| 100 }; | 113 }; |
| 101 | 114 |
| 102 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) | 115 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) |
| 103 { | 116 { |
| 104 const AtomicString& interfaceName = eventTarget->interfaceName(); | 117 const AtomicString& interfaceName = eventTarget->interfaceName(); |
| 105 if (interfaceName == EventTargetNames::XMLHttpRequest) | 118 if (interfaceName == EventTargetNames::XMLHttpRequest) |
| 106 return static_cast<XMLHttpRequest*>(eventTarget); | 119 return static_cast<XMLHttpRequest*>(eventTarget); |
| 107 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) | 120 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) |
| 108 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; | 121 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; |
| 109 return 0; | 122 return 0; |
| 110 } | 123 } |
| 111 | 124 |
| 125 void AsyncCallStackTracker::AsyncCallChain::trace(Visitor* visitor) |
| 126 { |
| 127 visitor->trace(m_callStacks); |
| 128 } |
| 129 |
| 112 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const String& description,
const ScriptValue& callFrames) | 130 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const String& description,
const ScriptValue& callFrames) |
| 113 : m_description(description) | 131 : m_description(description) |
| 114 , m_callFrames(callFrames) | 132 , m_callFrames(callFrames) |
| 115 { | 133 { |
| 116 } | 134 } |
| 117 | 135 |
| 118 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack() | 136 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack() |
| 119 { | 137 { |
| 120 } | 138 } |
| 121 | 139 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 setCurrentAsyncCallChain(context, operationId > 0 ? data->m_asyncOperati
onCallChains.get(operationId) : nullptr); | 422 setCurrentAsyncCallChain(context, operationId > 0 ? data->m_asyncOperati
onCallChains.get(operationId) : nullptr); |
| 405 else | 423 else |
| 406 setCurrentAsyncCallChain(context, nullptr); | 424 setCurrentAsyncCallChain(context, nullptr); |
| 407 } | 425 } |
| 408 | 426 |
| 409 void AsyncCallStackTracker::didFireAsyncCall() | 427 void AsyncCallStackTracker::didFireAsyncCall() |
| 410 { | 428 { |
| 411 clearCurrentAsyncCallChain(); | 429 clearCurrentAsyncCallChain(); |
| 412 } | 430 } |
| 413 | 431 |
| 414 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA
syncCallChain(const String& description, const ScriptValue& callFrames) | 432 PassRefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTrac
ker::createAsyncCallChain(const String& description, const ScriptValue& callFram
es) |
| 415 { | 433 { |
| 416 if (callFrames.isEmpty()) { | 434 if (callFrames.isEmpty()) { |
| 417 ASSERT(m_currentAsyncCallChain); | 435 ASSERT(m_currentAsyncCallChain); |
| 418 return m_currentAsyncCallChain; // Propogate async call stack chain. | 436 return m_currentAsyncCallChain; // Propogate async call stack chain. |
| 419 } | 437 } |
| 420 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC
allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr
acker::AsyncCallChain()); | 438 RefPtrWillBeRawPtr<AsyncCallChain> chain = adoptRefWillBeNoop(m_currentAsync
CallChain ? new AsyncCallStackTracker::AsyncCallChain(*m_currentAsyncCallChain)
: new AsyncCallStackTracker::AsyncCallChain()); |
| 421 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); | 439 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); |
| 422 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta
ck(description, callFrames))); | 440 chain->m_callStacks.prepend(adoptRefWillBeNoop(new AsyncCallStackTracker::As
yncCallStack(description, callFrames))); |
| 423 return chain.release(); | 441 return chain.release(); |
| 424 } | 442 } |
| 425 | 443 |
| 426 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context,
PassRefPtr<AsyncCallChain> chain) | 444 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context,
PassRefPtrWillBeRawPtr<AsyncCallChain> chain) |
| 427 { | 445 { |
| 428 if (chain && !V8RecursionScope::recursionLevel(toIsolate(context))) { | 446 if (chain && !V8RecursionScope::recursionLevel(toIsolate(context))) { |
| 429 // Current AsyncCallChain corresponds to the bottommost JS call frame. | 447 // Current AsyncCallChain corresponds to the bottommost JS call frame. |
| 430 m_currentAsyncCallChain = chain; | 448 m_currentAsyncCallChain = chain; |
| 431 m_nestedAsyncCallCount = 1; | 449 m_nestedAsyncCallCount = 1; |
| 432 } else { | 450 } else { |
| 433 if (m_currentAsyncCallChain) | 451 if (m_currentAsyncCallChain) |
| 434 ++m_nestedAsyncCallCount; | 452 ++m_nestedAsyncCallCount; |
| 435 } | 453 } |
| 436 } | 454 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 void AsyncCallStackTracker::clear() | 486 void AsyncCallStackTracker::clear() |
| 469 { | 487 { |
| 470 m_currentAsyncCallChain.clear(); | 488 m_currentAsyncCallChain.clear(); |
| 471 m_nestedAsyncCallCount = 0; | 489 m_nestedAsyncCallCount = 0; |
| 472 ExecutionContextDataMap copy; | 490 ExecutionContextDataMap copy; |
| 473 m_executionContextDataMap.swap(copy); | 491 m_executionContextDataMap.swap(copy); |
| 474 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) | 492 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e
nd(); ++it) |
| 475 delete it->value; | 493 delete it->value; |
| 476 } | 494 } |
| 477 | 495 |
| 496 void AsyncCallStackTracker::trace(Visitor* visitor) |
| 497 { |
| 498 visitor->trace(m_currentAsyncCallChain); |
| 499 visitor->trace(m_executionContextDataMap); |
| 500 } |
| 501 |
| 478 } // namespace blink | 502 } // namespace blink |
| OLD | NEW |