From 9c95606ad996a6a3fc5b09237be67f2a32e5c1d3 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 31 Jan 2017 09:56:09 -0800 Subject: [PATCH 1/4] src: declare v8_platform.platform_ unconditionally v8_platform.platform_ is referenced by node::Start without regard to the value of NODE_USE_V8_PLATFORM, so it should be declared unconditionally, otherwise Node fails to compile when !NODE_USE_V8_PLATFORM. --- src/node.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 90eee0fb9fe289..4a577071324fbb 100644 --- a/src/node.cc +++ b/src/node.cc @@ -228,7 +228,6 @@ static struct { } #endif // HAVE_INSPECTOR - v8::Platform* platform_; #else // !NODE_USE_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} @@ -239,6 +238,8 @@ static struct { return false; // make compiler happy } #endif // !NODE_USE_V8_PLATFORM + + v8::Platform* platform_; } v8_platform; #ifdef __POSIX__ From e619725faada46e2949faee17a4c791d5c7497c1 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 31 Jan 2017 10:03:53 -0800 Subject: [PATCH 2/4] src: update v8_platform.StartInspector signature The call signature of v8_platform.StartInspector needs to be the same whether or not NODE_USE_V8_PLATFORM, otherwise Node will fail to compile if HAVE_INSPECTOR and !NODE_USE_V8_PLATFORM. --- src/node.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 4a577071324fbb..904310dfe11430 100644 --- a/src/node.cc +++ b/src/node.cc @@ -233,7 +233,7 @@ static struct { void PumpMessageLoop(Isolate* isolate) {} void Dispose() {} bool StartInspector(Environment *env, const char* script_path, - int port, bool wait) { + const node::DebugOptions& options) { env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0"); return false; // make compiler happy } From 0e9c0cb7fa3ec9994724a991db8d067e70cb22fb Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Wed, 1 Feb 2017 14:09:42 -0800 Subject: [PATCH 3/4] src: don't call tracing_agent->Start w/nullptr node::tracing::Agent::Start can't accept a nullptr argument to its platform parameter, so don't call it when Node is compiled with NODE_USE_V8_PLATFORM=0. --- src/node.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index 904310dfe11430..1b15120279d894 100644 --- a/src/node.cc +++ b/src/node.cc @@ -228,6 +228,16 @@ static struct { } #endif // HAVE_INSPECTOR + void StartTracingAgent() { + tracing_agent = new tracing::Agent(); + tracing_agent->Start(platform_, trace_enabled_categories); + } + + void StopTracingAgent() { + tracing_agent->Stop(); + } + + v8::Platform* platform_; #else // !NODE_USE_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} @@ -237,9 +247,13 @@ static struct { env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0"); return false; // make compiler happy } -#endif // !NODE_USE_V8_PLATFORM - v8::Platform* platform_; + void StartTracingAgent() { + fprintf(stderr, "Node compiled with NODE_USE_V8_PLATFORM=0, " + "so event tracing is not available.\n"); + } + void StopTracingAgent() {} +#endif // !NODE_USE_V8_PLATFORM } v8_platform; #ifdef __POSIX__ @@ -4534,15 +4548,14 @@ int Start(int argc, char** argv) { if (trace_enabled) { fprintf(stderr, "Warning: Trace event is an experimental feature " "and could change at any time.\n"); - tracing_agent = new tracing::Agent(); - tracing_agent->Start(v8_platform.platform_, trace_enabled_categories); + v8_platform.StartTracingAgent(); } V8::Initialize(); v8_initialized = true; const int exit_code = Start(uv_default_loop(), argc, argv, exec_argc, exec_argv); if (trace_enabled) { - tracing_agent->Stop(); + v8_platform.StopTracingAgent(); } v8_initialized = false; V8::Dispose(); From b93584b6e32cd137ec32f0e90085991b1fcfa0ff Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Thu, 2 Feb 2017 08:37:59 -0800 Subject: [PATCH 4/4] src: refactor tracing_agent into v8_platform Move tracing_agent global into the v8_platform struct, renaming it to tracing_agent_; CHECK(tracing_agent_ == nullptr) in StartTracingAgent() to detect double calls; and relace another tracing_agent->Stop() call with a call to StopTracingAgent(). --- src/node.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index 1b15120279d894..a678c177f3db79 100644 --- a/src/node.cc +++ b/src/node.cc @@ -200,7 +200,6 @@ static uv_async_t dispatch_debug_messages_async; static Mutex node_isolate_mutex; static v8::Isolate* node_isolate; -static tracing::Agent* tracing_agent; static node::DebugOptions debug_options; @@ -229,15 +228,17 @@ static struct { #endif // HAVE_INSPECTOR void StartTracingAgent() { - tracing_agent = new tracing::Agent(); - tracing_agent->Start(platform_, trace_enabled_categories); + CHECK(tracing_agent_ == nullptr); + tracing_agent_ = new tracing::Agent(); + tracing_agent_->Start(platform_, trace_enabled_categories); } void StopTracingAgent() { - tracing_agent->Stop(); + tracing_agent_->Stop(); } v8::Platform* platform_; + tracing::Agent* tracing_agent_; #else // !NODE_USE_V8_PLATFORM void Initialize(int thread_pool_size) {} void PumpMessageLoop(Isolate* isolate) {} @@ -3401,7 +3402,7 @@ void SetupProcessObject(Environment* env, void SignalExit(int signo) { uv_tty_reset_mode(); if (trace_enabled) { - tracing_agent->Stop(); + v8_platform.StopTracingAgent(); } #ifdef __FreeBSD__ // FreeBSD has a nasty bug, see RegisterSignalHandler for details