From eb9ac9a4fb6a79235ac52dbaade5806488cdd801 Mon Sep 17 00:00:00 2001 From: Mark Marron Date: Mon, 29 May 2017 12:06:12 -0700 Subject: [PATCH] Update TTD for locations where AsyncHooks passes hidden state. --- src/async-wrap.cc | 11 ++++++++++- src/env-inl.h | 30 +++++++++++++++++++++++++++++- src/env.h | 12 ++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index d3776c73334..bd497626e57 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -443,9 +443,18 @@ void AsyncWrap::Initialize(Local target, isolate, uid_fields_ptr, uid_fields_count * sizeof(*uid_fields_ptr)); + Local farray = Float64Array::New(uid_fields_ab, 0, uid_fields_count); FORCE_SET_TARGET_FIELD(target, "async_uid_fields", - Float64Array::New(uid_fields_ab, 0, uid_fields_count)); + farray); + +#if ENABLE_TTD_NODE + if (s_doTTRecord || s_doTTReplay) { + unsigned int refcount = 0; + JsAddRef(*farray, &refcount); + env->async_hooks()->uid_fields_ttdRef = *farray; + } +#endif Local constants = Object::New(isolate); #define SET_HOOKS_CONSTANT(name) \ diff --git a/src/env-inl.h b/src/env-inl.h index c56e91aa52e..a87e5ad6cda 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -134,6 +134,10 @@ inline void Environment::AsyncHooks::push_ids(double async_id, uid_fields_[kCurrentTriggerId] }); uid_fields_[kCurrentAsyncId] = async_id; uid_fields_[kCurrentTriggerId] = trigger_id; + +#if ENABLE_TTD_NODE + this->AsyncWrapId_TTDRecord(); +#endif } inline bool Environment::AsyncHooks::pop_ids(double async_id) { @@ -163,6 +167,11 @@ inline bool Environment::AsyncHooks::pop_ids(double async_id) { ids_stack_.pop(); uid_fields_[kCurrentAsyncId] = ids.async_id; uid_fields_[kCurrentTriggerId] = ids.trigger_id; + +#if ENABLE_TTD_NODE + this->AsyncWrapId_TTDRecord(); +#endif + return !ids_stack_.empty(); } @@ -171,6 +180,10 @@ inline void Environment::AsyncHooks::clear_id_stack() { ids_stack_.pop(); uid_fields_[kCurrentAsyncId] = 0; uid_fields_[kCurrentTriggerId] = 0; + +#if ENABLE_TTD_NODE + this->AsyncWrapId_TTDRecord(); +#endif } inline Environment::AsyncHooks::InitScope::InitScope( @@ -430,7 +443,13 @@ inline std::vector* Environment::destroy_ids_list() { } inline double Environment::new_async_id() { - return ++async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr]; + double res = ++async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr]; + +#if ENABLE_TTD_NODE + this->async_hooks()->AsyncWrapId_TTDRecord(); +#endif + + return res; } inline double Environment::current_async_id() { @@ -445,12 +464,21 @@ inline double Environment::get_init_trigger_id() { double* uid_fields = async_hooks()->uid_fields(); double tid = uid_fields[AsyncHooks::kInitTriggerId]; uid_fields[AsyncHooks::kInitTriggerId] = 0; + +#if ENABLE_TTD_NODE + this->async_hooks()->AsyncWrapId_TTDRecord(); +#endif + if (tid <= 0) tid = current_async_id(); return tid; } inline void Environment::set_init_trigger_id(const double id) { async_hooks()->uid_fields()[AsyncHooks::kInitTriggerId] = id; + +#if ENABLE_TTD_NODE + this->async_hooks()->AsyncWrapId_TTDRecord(); +#endif } inline double* Environment::heap_statistics_buffer() const { diff --git a/src/env.h b/src/env.h index 86f8d7235bd..d88a7700e74 100644 --- a/src/env.h +++ b/src/env.h @@ -357,6 +357,18 @@ class Environment { kUidFieldsCount, }; +#if ENABLE_TTD_NODE + //Work around AsyncHooks id hack + v8::Float64Array* uid_fields_ttdRef; + + void AsyncWrapId_TTDRecord() { + if (s_doTTRecord || s_doTTReplay) { + const int modlength = kUidFieldsCount * sizeof(double); + uid_fields_ttdRef->Buffer()->TTDRawBufferModifyNotifySync(0, modlength); + } + } +#endif + AsyncHooks() = delete; inline uint32_t* fields();