OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-debugger.h" | 5 #include "src/inspector/v8-debugger.h" |
6 | 6 |
7 #include "src/inspector/debugger-script.h" | 7 #include "src/inspector/debugger-script.h" |
8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
10 #include "src/inspector/script-breakpoint.h" | 10 #include "src/inspector/script-breakpoint.h" |
11 #include "src/inspector/string-util.h" | 11 #include "src/inspector/string-util.h" |
12 #include "src/inspector/v8-debugger-agent-impl.h" | 12 #include "src/inspector/v8-debugger-agent-impl.h" |
13 #include "src/inspector/v8-inspector-impl.h" | 13 #include "src/inspector/v8-inspector-impl.h" |
14 #include "src/inspector/v8-internal-value-type.h" | 14 #include "src/inspector/v8-internal-value-type.h" |
15 #include "src/inspector/v8-stack-trace-impl.h" | 15 #include "src/inspector/v8-stack-trace-impl.h" |
16 #include "src/inspector/v8-value-copier.h" | 16 #include "src/inspector/v8-value-copier.h" |
17 | 17 |
18 #include "include/v8-util.h" | 18 #include "include/v8-util.h" |
19 | 19 |
20 namespace v8_inspector { | 20 namespace v8_inspector { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 static const int kMaxAsyncTaskStacks = 1024 * 1024; | 24 static const int kMaxAsyncTaskStacks = 128 * 1024; |
25 | 25 |
26 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { | 26 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { |
27 return value ? v8::True(isolate) : v8::False(isolate); | 27 return value ? v8::True(isolate) : v8::False(isolate); |
28 } | 28 } |
29 | 29 |
30 V8DebuggerAgentImpl* agentForScript(V8InspectorImpl* inspector, | 30 V8DebuggerAgentImpl* agentForScript(V8InspectorImpl* inspector, |
31 v8::Local<v8::debug::Script> script) { | 31 v8::Local<v8::debug::Script> script) { |
32 v8::Local<v8::Value> contextData; | 32 v8::Local<v8::Value> contextData; |
33 if (!script->ContextData().ToLocal(&contextData) || !contextData->IsInt32()) { | 33 if (!script->ContextData().ToLocal(&contextData) || !contextData->IsInt32()) { |
34 return nullptr; | 34 return nullptr; |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 void V8Debugger::collectOldAsyncStacksIfNeeded() { | 1016 void V8Debugger::collectOldAsyncStacksIfNeeded() { |
1017 if (m_asyncStacksCount <= m_maxAsyncCallStacks) return; | 1017 if (m_asyncStacksCount <= m_maxAsyncCallStacks) return; |
1018 int halfOfLimitRoundedUp = | 1018 int halfOfLimitRoundedUp = |
1019 m_maxAsyncCallStacks / 2 + m_maxAsyncCallStacks % 2; | 1019 m_maxAsyncCallStacks / 2 + m_maxAsyncCallStacks % 2; |
1020 while (m_asyncStacksCount > halfOfLimitRoundedUp) { | 1020 while (m_asyncStacksCount > halfOfLimitRoundedUp) { |
1021 m_allAsyncStacks.pop_front(); | 1021 m_allAsyncStacks.pop_front(); |
1022 --m_asyncStacksCount; | 1022 --m_asyncStacksCount; |
1023 } | 1023 } |
1024 removeOldAsyncTasks(m_asyncTaskStacks); | 1024 removeOldAsyncTasks(m_asyncTaskStacks); |
1025 removeOldAsyncTasks(m_asyncTaskCreationStacks); | 1025 removeOldAsyncTasks(m_asyncTaskCreationStacks); |
| 1026 protocol::HashSet<void*> recurringLeft; |
| 1027 for (auto task : m_recurringTasks) { |
| 1028 if (m_asyncTaskStacks.find(task) == m_asyncTaskStacks.end()) continue; |
| 1029 recurringLeft.insert(task); |
| 1030 } |
| 1031 m_recurringTasks.swap(recurringLeft); |
| 1032 protocol::HashMap<void*, void*> parentLeft; |
| 1033 for (auto it : m_parentTask) { |
| 1034 if (m_asyncTaskStacks.find(it.first) == m_asyncTaskStacks.end()) continue; |
| 1035 parentLeft.insert(it); |
| 1036 } |
| 1037 m_parentTask.swap(parentLeft); |
1026 } | 1038 } |
1027 | 1039 |
1028 void V8Debugger::removeOldAsyncTasks(AsyncTaskToStackTrace& map) { | 1040 void V8Debugger::removeOldAsyncTasks(AsyncTaskToStackTrace& map) { |
1029 AsyncTaskToStackTrace cleanCopy; | 1041 AsyncTaskToStackTrace cleanCopy; |
1030 for (auto it : map) { | 1042 for (auto it : map) { |
1031 if (!it.second.expired()) cleanCopy.insert(it); | 1043 if (!it.second.expired()) cleanCopy.insert(it); |
1032 } | 1044 } |
1033 map.swap(cleanCopy); | 1045 map.swap(cleanCopy); |
1034 } | 1046 } |
1035 | 1047 |
1036 std::shared_ptr<StackFrame> V8Debugger::lookupFrame(int frameId) { | 1048 std::shared_ptr<StackFrame> V8Debugger::lookupFrame(int frameId) { |
1037 auto it = m_framesCache.find(frameId); | 1049 auto it = m_framesCache.find(frameId); |
1038 if (it != m_framesCache.end()) return it->second.lock(); | 1050 if (it != m_framesCache.end()) return it->second.lock(); |
1039 return nullptr; | 1051 return nullptr; |
1040 } | 1052 } |
1041 | 1053 |
1042 void V8Debugger::storeFrame(int frameId, std::shared_ptr<StackFrame> frame) { | 1054 void V8Debugger::storeFrame(int frameId, std::shared_ptr<StackFrame> frame) { |
1043 m_framesCache[frameId] = frame; | 1055 m_framesCache[frameId] = frame; |
1044 } | 1056 } |
1045 | 1057 |
1046 void V8Debugger::setMaxAsyncTaskStacksForTest(int limit) { | 1058 void V8Debugger::setMaxAsyncTaskStacksForTest(int limit) { |
1047 m_maxAsyncCallStacks = 0; | 1059 m_maxAsyncCallStacks = 0; |
1048 collectOldAsyncStacksIfNeeded(); | 1060 collectOldAsyncStacksIfNeeded(); |
1049 m_maxAsyncCallStacks = limit; | 1061 m_maxAsyncCallStacks = limit; |
1050 } | 1062 } |
1051 | 1063 |
1052 } // namespace v8_inspector | 1064 } // namespace v8_inspector |
OLD | NEW |