summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2018-09-18 14:04:45 -0700
committerRich Trott <rtrott@gmail.com>2018-10-06 06:05:17 -0700
commit68b3e46fbf88ad81f50f68c7f0c725dc06c8beb0 (patch)
tree318535e61c5dba9f7efb65daa4193d9438d65bac
parent635161ae98ae0a88a354f749fecc3b62da3203b9 (diff)
downloadandroid-node-v8-68b3e46fbf88ad81f50f68c7f0c725dc06c8beb0.tar.gz
android-node-v8-68b3e46fbf88ad81f50f68c7f0c725dc06c8beb0.tar.bz2
android-node-v8-68b3e46fbf88ad81f50f68c7f0c725dc06c8beb0.zip
trace_events: destroy platform before tracing
For safer shutdown, we should destroy the platform – and background threads - before the tracing infrastructure is destroyed. This change fixes the relative order of NodePlatform disposition and the tracing agent shutting down. This matches the nesting order for startup. Make the tracing agent own the tracing controller instead of platform to match the above. Fixes: https://github.com/nodejs/node/issues/22865 PR-URL: https://github.com/nodejs/node/pull/22938 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
-rw-r--r--src/node.cc5
-rw-r--r--src/node_platform.cc7
-rw-r--r--src/node_platform.h2
-rw-r--r--src/tracing/agent.cc11
-rw-r--r--src/tracing/agent.h6
5 files changed, 17 insertions, 14 deletions
diff --git a/src/node.cc b/src/node.cc
index b8da26fa73..6250acfd5d 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -292,15 +292,18 @@ static struct {
controller->AddTraceStateObserver(new NodeTraceStateObserver(controller));
tracing::TraceEventHelper::SetTracingController(controller);
StartTracingAgent();
+ // Tracing must be initialized before platform threads are created.
platform_ = new NodePlatform(thread_pool_size, controller);
V8::InitializePlatform(platform_);
}
void Dispose() {
- tracing_agent_.reset(nullptr);
platform_->Shutdown();
delete platform_;
platform_ = nullptr;
+ // Destroy tracing after the platform (and platform threads) have been
+ // stopped.
+ tracing_agent_.reset(nullptr);
}
void DrainVMTasks(Isolate* isolate) {
diff --git a/src/node_platform.cc b/src/node_platform.cc
index b583ce8542..278c168483 100644
--- a/src/node_platform.cc
+++ b/src/node_platform.cc
@@ -283,10 +283,9 @@ int PerIsolatePlatformData::unref() {
NodePlatform::NodePlatform(int thread_pool_size,
TracingController* tracing_controller) {
if (tracing_controller) {
- tracing_controller_.reset(tracing_controller);
+ tracing_controller_ = tracing_controller;
} else {
- TracingController* controller = new TracingController();
- tracing_controller_.reset(controller);
+ tracing_controller_ = new TracingController();
}
worker_thread_task_runner_ =
std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size);
@@ -456,7 +455,7 @@ double NodePlatform::CurrentClockTimeMillis() {
}
TracingController* NodePlatform::GetTracingController() {
- return tracing_controller_.get();
+ return tracing_controller_;
}
template <class T>
diff --git a/src/node_platform.h b/src/node_platform.h
index 197d5cee39..c926c17852 100644
--- a/src/node_platform.h
+++ b/src/node_platform.h
@@ -158,7 +158,7 @@ class NodePlatform : public MultiIsolatePlatform {
std::unordered_map<v8::Isolate*,
std::shared_ptr<PerIsolatePlatformData>> per_isolate_;
- std::unique_ptr<v8::TracingController> tracing_controller_;
+ v8::TracingController* tracing_controller_;
std::shared_ptr<WorkerThreadsTaskRunner> worker_thread_task_runner_;
};
diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc
index 5a4d637bda..fd5cb3387b 100644
--- a/src/tracing/agent.cc
+++ b/src/tracing/agent.cc
@@ -48,8 +48,7 @@ using v8::platform::tracing::TraceConfig;
using v8::platform::tracing::TraceWriter;
using std::string;
-Agent::Agent() {
- tracing_controller_ = new TracingController();
+Agent::Agent() : tracing_controller_(new TracingController()) {
tracing_controller_->Initialize(nullptr);
CHECK_EQ(uv_loop_init(&tracing_loop_), 0);
@@ -117,7 +116,7 @@ AgentWriterHandle Agent::AddClient(
use_categories = &categories_with_default;
}
- ScopedSuspendTracing suspend(tracing_controller_, this);
+ ScopedSuspendTracing suspend(tracing_controller_.get(), this);
int id = next_writer_id_++;
AsyncTraceWriter* raw = writer.get();
writers_[id] = std::move(writer);
@@ -157,7 +156,7 @@ void Agent::Disconnect(int client) {
Mutex::ScopedLock lock(initialize_writer_mutex_);
to_be_initialized_.erase(writers_[client].get());
}
- ScopedSuspendTracing suspend(tracing_controller_, this);
+ ScopedSuspendTracing suspend(tracing_controller_.get(), this);
writers_.erase(client);
categories_.erase(client);
}
@@ -166,13 +165,13 @@ void Agent::Enable(int id, const std::set<std::string>& categories) {
if (categories.empty())
return;
- ScopedSuspendTracing suspend(tracing_controller_, this,
+ ScopedSuspendTracing suspend(tracing_controller_.get(), this,
id != kDefaultHandleId);
categories_[id].insert(categories.begin(), categories.end());
}
void Agent::Disable(int id, const std::set<std::string>& categories) {
- ScopedSuspendTracing suspend(tracing_controller_, this,
+ ScopedSuspendTracing suspend(tracing_controller_.get(), this,
id != kDefaultHandleId);
std::multiset<std::string>& writer_categories = categories_[id];
for (const std::string& category : categories) {
diff --git a/src/tracing/agent.h b/src/tracing/agent.h
index e79480a036..e9f52abe64 100644
--- a/src/tracing/agent.h
+++ b/src/tracing/agent.h
@@ -70,7 +70,9 @@ class Agent {
Agent();
~Agent();
- TracingController* GetTracingController() { return tracing_controller_; }
+ TracingController* GetTracingController() {
+ return tracing_controller_.get();
+ }
enum UseDefaultCategoryMode {
kUseDefaultCategories,
@@ -121,7 +123,7 @@ class Agent {
// These maps store the original arguments to AddClient(), by id.
std::unordered_map<int, std::multiset<std::string>> categories_;
std::unordered_map<int, std::unique_ptr<AsyncTraceWriter>> writers_;
- TracingController* tracing_controller_ = nullptr;
+ std::unique_ptr<TracingController> tracing_controller_;
// Variables related to initializing per-event-loop properties of individual
// writers, such as libuv handles.