Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: Source/core/inspector/AsyncCallStackTracker.cpp

Issue 422273002: Oilpan: Prepare moving AsyncCallStackTracker to Oilpan (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/inspector/AsyncCallStackTracker.h" 32 #include "core/inspector/AsyncCallStackTracker.h"
33 33
34 #include "bindings/core/v8/V8Binding.h" 34 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8RecursionScope.h" 35 #include "bindings/core/v8/V8RecursionScope.h"
36 #include "core/dom/ContextLifecycleObserver.h"
37 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
38 #include "core/dom/ExecutionContextTask.h" 37 #include "core/dom/ExecutionContextTask.h"
39 #include "core/events/Event.h" 38 #include "core/events/Event.h"
40 #include "core/events/EventTarget.h" 39 #include "core/events/EventTarget.h"
41 #include "core/xml/XMLHttpRequest.h" 40 #include "core/xml/XMLHttpRequest.h"
42 #include "core/xml/XMLHttpRequestUpload.h" 41 #include "core/xml/XMLHttpRequestUpload.h"
43 #include "wtf/text/StringBuilder.h" 42 #include "wtf/text/StringBuilder.h"
44 #include "wtf/text/StringHash.h" 43 #include "wtf/text/StringHash.h"
45 #include <v8.h> 44 #include <v8.h>
46 45
47 namespace { 46 namespace {
48 47
49 static const char setTimeoutName[] = "setTimeout"; 48 static const char setTimeoutName[] = "setTimeout";
50 static const char setIntervalName[] = "setInterval"; 49 static const char setIntervalName[] = "setInterval";
51 static const char requestAnimationFrameName[] = "requestAnimationFrame"; 50 static const char requestAnimationFrameName[] = "requestAnimationFrame";
52 static const char xhrSendName[] = "XMLHttpRequest.send"; 51 static const char xhrSendName[] = "XMLHttpRequest.send";
53 static const char enqueueMutationRecordName[] = "Mutation"; 52 static const char enqueueMutationRecordName[] = "Mutation";
54 53
55 } 54 }
56 55
57 namespace blink { 56 namespace blink {
58 57
59 class AsyncCallStackTracker::ExecutionContextData FINAL : public ContextLifecycl eObserver { 58 void AsyncCallStackTracker::ExecutionContextData::contextDestroyed()
60 WTF_MAKE_FAST_ALLOCATED; 59 {
61 public: 60 ASSERT(executionContext());
62 ExecutionContextData(AsyncCallStackTracker* tracker, ExecutionContext* execu tionContext) 61 OwnPtrWillBeRawPtr<ExecutionContextData> self = m_tracker->m_executionContex tDataMap.take(executionContext());
63 : ContextLifecycleObserver(executionContext) 62 ASSERT(self == this);
64 , m_circularSequentialID(0) 63 ContextLifecycleObserver::contextDestroyed();
65 , m_tracker(tracker) 64 }
66 {
67 }
68 65
69 virtual void contextDestroyed() OVERRIDE 66 int AsyncCallStackTracker::ExecutionContextData::circularSequentialID()
70 { 67 {
71 ASSERT(executionContext()); 68 ++m_circularSequentialID;
72 ExecutionContextData* self = m_tracker->m_executionContextDataMap.take(e xecutionContext()); 69 if (m_circularSequentialID <= 0)
73 ASSERT(self == this); 70 m_circularSequentialID = 1;
74 ContextLifecycleObserver::contextDestroyed(); 71 return m_circularSequentialID;
75 delete self; 72 }
76 }
77 73
78 int circularSequentialID() 74 void AsyncCallStackTracker::ExecutionContextData::trace(Visitor* visitor)
79 { 75 {
80 ++m_circularSequentialID; 76 visitor->trace(m_tracker);
81 if (m_circularSequentialID <= 0) 77 #if ENABLE(OILPAN)
82 m_circularSequentialID = 1; 78 visitor->trace(m_timerCallChains);
83 return m_circularSequentialID; 79 visitor->trace(m_animationFrameCallChains);
84 } 80 visitor->trace(m_eventCallChains);
85 81 visitor->trace(m_xhrCallChains);
86 private: 82 visitor->trace(m_mutationObserverCallChains);
87 int m_circularSequentialID; 83 visitor->trace(m_executionContextTaskCallChains);
88 84 visitor->trace(m_v8AsyncTaskCallChains);
89 public: 85 visitor->trace(m_asyncOperationCallChains);
90 AsyncCallStackTracker* m_tracker; 86 #endif
91 HashSet<int> m_intervalTimerIds; 87 }
92 HashMap<int, RefPtr<AsyncCallChain> > m_timerCallChains;
93 HashMap<int, RefPtr<AsyncCallChain> > m_animationFrameCallChains;
94 HashMap<Event*, RefPtr<AsyncCallChain> > m_eventCallChains;
95 HashMap<EventTarget*, RefPtr<AsyncCallChain> > m_xhrCallChains;
96 HashMap<MutationObserver*, RefPtr<AsyncCallChain> > m_mutationObserverCallCh ains;
97 HashMap<ExecutionContextTask*, RefPtr<AsyncCallChain> > m_executionContextTa skCallChains;
98 HashMap<String, RefPtr<AsyncCallChain> > m_v8AsyncTaskCallChains;
99 HashMap<int, RefPtr<AsyncCallChain> > m_asyncOperationCallChains;
100 };
101 88
102 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) 89 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget)
103 { 90 {
104 const AtomicString& interfaceName = eventTarget->interfaceName(); 91 const AtomicString& interfaceName = eventTarget->interfaceName();
105 if (interfaceName == EventTargetNames::XMLHttpRequest) 92 if (interfaceName == EventTargetNames::XMLHttpRequest)
106 return static_cast<XMLHttpRequest*>(eventTarget); 93 return static_cast<XMLHttpRequest*>(eventTarget);
107 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) 94 if (interfaceName == EventTargetNames::XMLHttpRequestUpload)
108 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest() ; 95 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest() ;
109 return 0; 96 return 0;
110 } 97 }
111 98
99 void AsyncCallStackTracker::AsyncCallChain::trace(Visitor* visitor)
100 {
101 visitor->trace(m_callStacks);
102 }
103
112 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const String& description, const ScriptValue& callFrames) 104 AsyncCallStackTracker::AsyncCallStack::AsyncCallStack(const String& description, const ScriptValue& callFrames)
113 : m_description(description) 105 : m_description(description)
114 , m_callFrames(callFrames) 106 , m_callFrames(callFrames)
115 { 107 {
116 } 108 }
117 109
118 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack() 110 AsyncCallStackTracker::AsyncCallStack::~AsyncCallStack()
119 { 111 {
120 } 112 }
121 113
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 setCurrentAsyncCallChain(context, operationId > 0 ? data->m_asyncOperati onCallChains.get(operationId) : nullptr); 396 setCurrentAsyncCallChain(context, operationId > 0 ? data->m_asyncOperati onCallChains.get(operationId) : nullptr);
405 else 397 else
406 setCurrentAsyncCallChain(context, nullptr); 398 setCurrentAsyncCallChain(context, nullptr);
407 } 399 }
408 400
409 void AsyncCallStackTracker::didFireAsyncCall() 401 void AsyncCallStackTracker::didFireAsyncCall()
410 { 402 {
411 clearCurrentAsyncCallChain(); 403 clearCurrentAsyncCallChain();
412 } 404 }
413 405
414 PassRefPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTracker::createA syncCallChain(const String& description, const ScriptValue& callFrames) 406 PassRefPtrWillBeRawPtr<AsyncCallStackTracker::AsyncCallChain> AsyncCallStackTrac ker::createAsyncCallChain(const String& description, const ScriptValue& callFram es)
415 { 407 {
416 if (callFrames.isEmpty()) { 408 if (callFrames.isEmpty()) {
417 ASSERT(m_currentAsyncCallChain); 409 ASSERT(m_currentAsyncCallChain);
418 return m_currentAsyncCallChain; // Propogate async call stack chain. 410 return m_currentAsyncCallChain; // Propogate async call stack chain.
419 } 411 }
420 RefPtr<AsyncCallChain> chain = adoptRef(m_currentAsyncCallChain ? new AsyncC allStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTr acker::AsyncCallChain()); 412 RefPtrWillBeRawPtr<AsyncCallChain> chain = adoptRefWillBeNoop(m_currentAsync CallChain ? new AsyncCallStackTracker::AsyncCallChain(*m_currentAsyncCallChain) : new AsyncCallStackTracker::AsyncCallChain());
421 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1); 413 ensureMaxAsyncCallChainDepth(chain.get(), m_maxAsyncCallStackDepth - 1);
422 chain->m_callStacks.prepend(adoptRef(new AsyncCallStackTracker::AsyncCallSta ck(description, callFrames))); 414 chain->m_callStacks.prepend(adoptRefWillBeNoop(new AsyncCallStackTracker::As yncCallStack(description, callFrames)));
423 return chain.release(); 415 return chain.release();
424 } 416 }
425 417
426 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context, PassRefPtr<AsyncCallChain> chain) 418 void AsyncCallStackTracker::setCurrentAsyncCallChain(ExecutionContext* context, PassRefPtrWillBeRawPtr<AsyncCallChain> chain)
427 { 419 {
428 if (chain && !V8RecursionScope::recursionLevel(toIsolate(context))) { 420 if (chain && !V8RecursionScope::recursionLevel(toIsolate(context))) {
429 // Current AsyncCallChain corresponds to the bottommost JS call frame. 421 // Current AsyncCallChain corresponds to the bottommost JS call frame.
430 m_currentAsyncCallChain = chain; 422 m_currentAsyncCallChain = chain;
431 m_nestedAsyncCallCount = 1; 423 m_nestedAsyncCallCount = 1;
432 } else { 424 } else {
433 if (m_currentAsyncCallChain) 425 if (m_currentAsyncCallChain)
434 ++m_nestedAsyncCallCount; 426 ++m_nestedAsyncCallCount;
435 } 427 }
436 } 428 }
(...skipping 15 matching lines...) Expand all
452 444
453 bool AsyncCallStackTracker::validateCallFrames(const ScriptValue& callFrames) 445 bool AsyncCallStackTracker::validateCallFrames(const ScriptValue& callFrames)
454 { 446 {
455 return !callFrames.isEmpty() || m_currentAsyncCallChain; 447 return !callFrames.isEmpty() || m_currentAsyncCallChain;
456 } 448 }
457 449
458 AsyncCallStackTracker::ExecutionContextData* AsyncCallStackTracker::createContex tDataIfNeeded(ExecutionContext* context) 450 AsyncCallStackTracker::ExecutionContextData* AsyncCallStackTracker::createContex tDataIfNeeded(ExecutionContext* context)
459 { 451 {
460 ExecutionContextData* data = m_executionContextDataMap.get(context); 452 ExecutionContextData* data = m_executionContextDataMap.get(context);
461 if (!data) { 453 if (!data) {
462 data = new AsyncCallStackTracker::ExecutionContextData(this, context); 454 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy ncCallStackTracker::ExecutionContextData(this, context)))
463 m_executionContextDataMap.set(context, data); 455 .storedValue->value.get();
464 } 456 }
465 return data; 457 return data;
466 } 458 }
467 459
468 void AsyncCallStackTracker::clear() 460 void AsyncCallStackTracker::clear()
469 { 461 {
470 m_currentAsyncCallChain.clear(); 462 m_currentAsyncCallChain.clear();
471 m_nestedAsyncCallCount = 0; 463 m_nestedAsyncCallCount = 0;
472 ExecutionContextDataMap copy; 464 m_executionContextDataMap.clear();
473 m_executionContextDataMap.swap(copy); 465 }
474 for (ExecutionContextDataMap::const_iterator it = copy.begin(); it != copy.e nd(); ++it) 466
475 delete it->value; 467 void AsyncCallStackTracker::trace(Visitor* visitor)
468 {
469 visitor->trace(m_currentAsyncCallChain);
470 #if ENABLE(OILPAN)
471 visitor->trace(m_executionContextDataMap);
472 #endif
476 } 473 }
477 474
478 } // namespace blink 475 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698