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

Unified Diff: src/inspector/v8-debugger.cc

Issue 2579403002: [inspector] introduce limit for amount of stored async stacks (Closed)
Patch Set: maps.. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« src/inspector/v8-debugger.h ('K') | « src/inspector/v8-debugger.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/v8-debugger.cc
diff --git a/src/inspector/v8-debugger.cc b/src/inspector/v8-debugger.cc
index 3d3f18189440609a561c57157cae8a681db0db1c..251bb15bf1a4ba0e8c5ccb3c70e7ea01cf5c2029 100644
--- a/src/inspector/v8-debugger.cc
+++ b/src/inspector/v8-debugger.cc
@@ -26,6 +26,11 @@ static const char v8AsyncTaskEventWillHandle[] = "willHandle";
static const char v8AsyncTaskEventDidHandle[] = "didHandle";
static const char v8AsyncTaskEventCancel[] = "cancel";
+// Based on DevTools frontend measurement, with asyncCallStackDepth = 4,
+// average async call stack tail requires ~1 Kb. Let's reserve ~ 128 Mb
+// for async stacks.
+static const int kMaxAsyncTaskStacks = 128 * 1024;
+
inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) {
return value ? v8::True(isolate) : v8::False(isolate);
}
@@ -55,6 +60,7 @@ V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
m_breakpointsActivated(true),
m_runningNestedMessageLoop(false),
m_ignoreScriptParsedEventsCounter(0),
+ m_lastId(0),
m_maxAsyncCallStackDepth(0),
m_pauseOnExceptionsState(v8::debug::NoBreakOnException),
m_wasmTranslation(isolate) {}
@@ -901,6 +907,13 @@ void V8Debugger::asyncTaskScheduled(const String16& taskName, void* task,
if (chain) {
m_asyncTaskStacks[task] = std::move(chain);
if (recurring) m_recurringTasks.insert(task);
+ int id = ++m_lastId;
+ m_rawIdToId[task] = id;
+ m_idToRawId[id] = task;
+ while (m_idToRawId.size() > kMaxAsyncTaskStacks) {
dgozman 2016/12/16 23:59:49 while -> if ?
kozy 2016/12/17 01:12:41 Done.
+ void* taskToRemove = m_idToRawId.begin()->second;
+ asyncTaskCanceled(taskToRemove);
+ }
}
}
@@ -908,6 +921,9 @@ void V8Debugger::asyncTaskCanceled(void* task) {
if (!m_maxAsyncCallStackDepth) return;
m_asyncTaskStacks.erase(task);
m_recurringTasks.erase(task);
+ auto it = m_rawIdToId.find(task);
+ m_idToRawId.erase(it->second);
+ m_rawIdToId.erase(it);
}
void V8Debugger::asyncTaskStarted(void* task) {
@@ -936,8 +952,12 @@ void V8Debugger::asyncTaskFinished(void* task) {
m_currentTasks.pop_back();
m_currentStacks.pop_back();
- if (m_recurringTasks.find(task) == m_recurringTasks.end())
+ if (m_recurringTasks.find(task) == m_recurringTasks.end()) {
m_asyncTaskStacks.erase(task);
+ auto it = m_rawIdToId.find(task);
+ m_idToRawId.erase(it->second);
+ m_rawIdToId.erase(it);
+ }
}
void V8Debugger::allAsyncTasksCanceled() {
@@ -945,6 +965,9 @@ void V8Debugger::allAsyncTasksCanceled() {
m_recurringTasks.clear();
m_currentStacks.clear();
m_currentTasks.clear();
+ m_idToRawId.clear();
+ m_rawIdToId.clear();
+ m_lastId = 0;
}
void V8Debugger::muteScriptParsedEvents() {
« src/inspector/v8-debugger.h ('K') | « src/inspector/v8-debugger.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698