diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-27 15:46:03 -0400 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-04 11:09:29 +0800 |
commit | f59ec2abee82f22822b7b3231ca2056fc028a279 (patch) | |
tree | 3be1fa8fa8b2be425ecc29254b9e8fcb1df111af /src/memory_tracker.h | |
parent | ceb80f415798818a059051537132bba691c68db7 (diff) | |
download | node-new-f59ec2abee82f22822b7b3231ca2056fc028a279.tar.gz |
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/memory_tracker.h')
-rw-r--r-- | src/memory_tracker.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/memory_tracker.h b/src/memory_tracker.h index c5d9b2106f..07b1b47216 100644 --- a/src/memory_tracker.h +++ b/src/memory_tracker.h @@ -35,6 +35,8 @@ namespace crypto { class NodeBIO; } +class CleanupHookCallback; + /* Example: * * class ExampleRetainer : public MemoryRetainer { @@ -179,6 +181,10 @@ class MemoryTracker { inline void TrackField(const char* edge_name, const T& value, const char* node_name = nullptr); + template <typename T> + void TrackField(const char* edge_name, + const v8::Eternal<T>& value, + const char* node_name); template <typename T, typename Traits> inline void TrackField(const char* edge_name, const v8::Persistent<T, Traits>& value, @@ -191,6 +197,13 @@ class MemoryTracker { inline void TrackField(const char* edge_name, const MallocedBuffer<T>& value, const char* node_name = nullptr); + // We do not implement CleanupHookCallback as MemoryRetainer + // but instead specialize the method here to avoid the cost of + // virtual pointers. + // TODO(joyeecheung): do this for BaseObject and remove WrappedObject() + void TrackField(const char* edge_name, + const CleanupHookCallback& value, + const char* node_name = nullptr); inline void TrackField(const char* edge_name, const uv_buf_t& value, const char* node_name = nullptr); |