Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Update TTD for locations where AsyncHooks passes hidden state. #252

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,18 @@ void AsyncWrap::Initialize(Local<Object> target,
isolate,
uid_fields_ptr,
uid_fields_count * sizeof(*uid_fields_ptr));
Local<Float64Array> 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is AsyncWrap a singleton? If not, is this a memory leak since I never see a JsRelease anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is a singleton, nevermind.

env->async_hooks()->uid_fields_ttdRef = *farray;
}
#endif

Local<Object> constants = Object::New(isolate);
#define SET_HOOKS_CONSTANT(name) \
Expand Down
30 changes: 29 additions & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand All @@ -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(
Expand Down Expand Up @@ -430,7 +443,13 @@ inline std::vector<double>* 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() {
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down