From f59ec2abee82f22822b7b3231ca2056fc028a279 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 27 Mar 2019 15:46:03 -0400 Subject: src: implement MemoryRetainer in Environment This allows us to track the essentially-global objects in Environment in the heap snapshot. Note that this patch only tracks the fields that can be tracked correctly. There are still several types of fields that cannot be tracked: - v8::Data including v8::Private, v8::ObjectTemplate etc. - Internal types that do not implement MemoryRetainer yet - STL containers with MemoryRetainer* inside - STL containers with numeric types inside that should not have their nodes elided e.g. numeric keys in maps. The `BaseObject`s are now no longer globals. They are tracked as arguments in CleanupHookCallbacks referenced by the Environment node. This model is closer to how their lifetime is managed internally. To track the per-environment strong persistent properties, this patch divides them into those that are also `v8::Value` and those that are just `v8::Data`. The values can be tracked by the current memory tracker while the data cannot. This patch also implements the `MemoryRetainer` interface in several internal classes so that they can be tracked in the heap snapshot. PR-URL: https://github.com/nodejs/node/pull/27018 Refs: https://github.com/nodejs/node/issues/26776 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/env-inl.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/env-inl.h') diff --git a/src/env-inl.h b/src/env-inl.h index bce36c0f69..ef054be4cb 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -980,17 +980,17 @@ void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) { cleanup_hooks_.erase(search); } -size_t Environment::CleanupHookCallback::Hash::operator()( +size_t CleanupHookCallback::Hash::operator()( const CleanupHookCallback& cb) const { return std::hash()(cb.arg_); } -bool Environment::CleanupHookCallback::Equal::operator()( +bool CleanupHookCallback::Equal::operator()( const CleanupHookCallback& a, const CleanupHookCallback& b) const { return a.fn_ == b.fn_ && a.arg_ == b.arg_; } -BaseObject* Environment::CleanupHookCallback::GetBaseObject() const { +BaseObject* CleanupHookCallback::GetBaseObject() const { if (fn_ == BaseObject::DeleteMe) return static_cast(arg_); else @@ -1054,6 +1054,7 @@ void AsyncRequest::set_stopped(bool flag) { PropertyName ## _.Reset(isolate(), value); \ } ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) + ENVIRONMENT_STRONG_PERSISTENT_VALUES(V) #undef V } // namespace node -- cgit v1.2.3