Commit 3f96cbe7 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[DevTools] avoid async task id collisions

V8 internally uses odd numbers as task id, blink should always send
even numbers only.
This CL fixes ids for network related async tasks.

R=pfeldman@chromium.org

Bug: none
Change-Id: I44a68b65f5992066bca4fb8a69566db66feaf143
Reviewed-on: https://chromium-review.googlesource.com/764514Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515807}
parent 2b74d964
...@@ -50,6 +50,7 @@ namespace blink { ...@@ -50,6 +50,7 @@ namespace blink {
namespace { namespace {
void* AsyncId(unsigned long identifier) { void* AsyncId(unsigned long identifier) {
// This value should be odd to avoid collisions with regular pointers.
return reinterpret_cast<void*>((identifier << 1) | 1); return reinterpret_cast<void*>((identifier << 1) | 1);
} }
......
...@@ -82,11 +82,13 @@ void ThreadDebugger::IdleFinished(v8::Isolate* isolate) { ...@@ -82,11 +82,13 @@ void ThreadDebugger::IdleFinished(v8::Isolate* isolate) {
void ThreadDebugger::AsyncTaskScheduled(const String& operation_name, void ThreadDebugger::AsyncTaskScheduled(const String& operation_name,
void* task, void* task,
bool recurring) { bool recurring) {
DCHECK_EQ(reinterpret_cast<intptr_t>(task) % 2, 0);
v8_inspector_->asyncTaskScheduled(ToV8InspectorStringView(operation_name), v8_inspector_->asyncTaskScheduled(ToV8InspectorStringView(operation_name),
task, recurring); task, recurring);
} }
void ThreadDebugger::AsyncTaskCanceled(void* task) { void ThreadDebugger::AsyncTaskCanceled(void* task) {
DCHECK_EQ(reinterpret_cast<intptr_t>(task) % 2, 0);
v8_inspector_->asyncTaskCanceled(task); v8_inspector_->asyncTaskCanceled(task);
} }
...@@ -95,10 +97,12 @@ void ThreadDebugger::AllAsyncTasksCanceled() { ...@@ -95,10 +97,12 @@ void ThreadDebugger::AllAsyncTasksCanceled() {
} }
void ThreadDebugger::AsyncTaskStarted(void* task) { void ThreadDebugger::AsyncTaskStarted(void* task) {
DCHECK_EQ(reinterpret_cast<intptr_t>(task) % 2, 0);
v8_inspector_->asyncTaskStarted(task); v8_inspector_->asyncTaskStarted(task);
} }
void ThreadDebugger::AsyncTaskFinished(void* task) { void ThreadDebugger::AsyncTaskFinished(void* task) {
DCHECK_EQ(reinterpret_cast<intptr_t>(task) % 2, 0);
v8_inspector_->asyncTaskFinished(task); v8_inspector_->asyncTaskFinished(task);
} }
......
...@@ -50,12 +50,21 @@ ...@@ -50,12 +50,21 @@
namespace blink { namespace blink {
namespace probe { namespace probe {
namespace {
void* AsyncId(void* task) {
// Blink uses odd ids for network requests and even ids for everything else.
// We should make all of them even before reporting to V8 to avoid collisions
// with internal V8 async events.
return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(task) << 1);
}
} // namespace
AsyncTask::AsyncTask(ExecutionContext* context, AsyncTask::AsyncTask(ExecutionContext* context,
void* task, void* task,
const char* step, const char* step,
bool enabled) bool enabled)
: debugger_(enabled ? ThreadDebugger::From(ToIsolate(context)) : nullptr), : debugger_(enabled ? ThreadDebugger::From(ToIsolate(context)) : nullptr),
task_(task), task_(AsyncId(task)),
recurring_(step) { recurring_(step) {
if (recurring_) { if (recurring_) {
TRACE_EVENT_FLOW_STEP0("devtools.timeline.async", "AsyncTask", TRACE_EVENT_FLOW_STEP0("devtools.timeline.async", "AsyncTask",
...@@ -84,7 +93,7 @@ void AsyncTaskScheduled(ExecutionContext* context, ...@@ -84,7 +93,7 @@ void AsyncTaskScheduled(ExecutionContext* context,
TRACE_ID_LOCAL(reinterpret_cast<uintptr_t>(task)), TRACE_ID_LOCAL(reinterpret_cast<uintptr_t>(task)),
"data", InspectorAsyncTask::Data(name)); "data", InspectorAsyncTask::Data(name));
if (ThreadDebugger* debugger = ThreadDebugger::From(ToIsolate(context))) if (ThreadDebugger* debugger = ThreadDebugger::From(ToIsolate(context)))
debugger->AsyncTaskScheduled(name, task, true); debugger->AsyncTaskScheduled(name, AsyncId(task), true);
} }
void AsyncTaskScheduledBreakable(ExecutionContext* context, void AsyncTaskScheduledBreakable(ExecutionContext* context,
...@@ -96,7 +105,7 @@ void AsyncTaskScheduledBreakable(ExecutionContext* context, ...@@ -96,7 +105,7 @@ void AsyncTaskScheduledBreakable(ExecutionContext* context,
void AsyncTaskCanceled(ExecutionContext* context, void* task) { void AsyncTaskCanceled(ExecutionContext* context, void* task) {
if (ThreadDebugger* debugger = ThreadDebugger::From(ToIsolate(context))) if (ThreadDebugger* debugger = ThreadDebugger::From(ToIsolate(context)))
debugger->AsyncTaskCanceled(task); debugger->AsyncTaskCanceled(AsyncId(task));
TRACE_EVENT_FLOW_END0("devtools.timeline.async", "AsyncTask", TRACE_EVENT_FLOW_END0("devtools.timeline.async", "AsyncTask",
TRACE_ID_LOCAL(reinterpret_cast<uintptr_t>(task))); TRACE_ID_LOCAL(reinterpret_cast<uintptr_t>(task)));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment