| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2e97d82 commit 9199808
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,7 @@ class BaseObject : public MemoryRetainer { | |||
| 103 | 103 | ||
| 104 | 104 | private: | |
| 105 | 105 | v8::Local<v8::Object> WrappedObject() const override; | |
| 106 | + bool IsRootNode() const override; | ||
| 106 | 107 | static void DeleteMe(void* data); | |
| 107 | 108 | ||
| 108 | 109 | // persistent_handle_ needs to be at a fixed offset from the start of the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -986,33 +986,16 @@ Environment* Environment::worker_parent_env() const { | |||
| 986 | 986 | return worker_context_->env(); | |
| 987 | 987 | } | |
| 988 | 988 | ||
| 989 | - void MemoryTracker::TrackField(const char* edge_name, | ||
| 990 | - const CleanupHookCallback& value, | ||
| 991 | - const char* node_name) { | ||
| 992 | - HandleScope handle_scope(isolate_); | ||
| 993 | - // Here, we utilize the fact that CleanupHookCallback instances | ||
| 994 | - // are all unique and won't be tracked twice in one BuildEmbedderGraph | ||
| 995 | - // callback. | ||
| 996 | - MemoryRetainerNode* n = | ||
| 997 | - PushNode("CleanupHookCallback", sizeof(value), edge_name); | ||
| 998 | - // TODO(joyeecheung): at the moment only arguments of type BaseObject will be | ||
| 999 | - // identified and tracked here (based on their deleters), | ||
| 1000 | - // but we may convert and track other known types here. | ||
| 1001 | - BaseObject* obj = value.GetBaseObject(); | ||
| 1002 | - if (obj != nullptr && obj->IsDoneInitializing()) { | ||
| 1003 | - TrackField("arg", obj); | ||
| 1004 | - } | ||
| 1005 | - CHECK_EQ(CurrentNode(), n); | ||
| 1006 | - CHECK_NE(n->size_, 0); | ||
| 1007 | - PopNode(); | ||
| 1008 | - } | ||
| 1009 | - | ||
| 1010 | 989 | void Environment::BuildEmbedderGraph(Isolate* isolate, | |
| 1011 | 990 | EmbedderGraph* graph, | |
| 1012 | 991 | void* data) { | |
| 1013 | 992 | MemoryTracker tracker(isolate, graph); | |
| 1014 | 993 | Environment* env = static_cast<Environment*>(data); | |
| 1015 | 994 | tracker.Track(env); | |
| 995 | + env->ForEachBaseObject([&](BaseObject* obj) { | ||
| 996 | + if (obj->IsDoneInitializing()) | ||
| 997 | + tracker.Track(obj); | ||
| 998 | + }); | ||
| 1016 | 999 | } | |
| 1017 | 1000 | ||
| 1018 | 1001 | inline size_t Environment::SelfSize() const { | |
@@ -1042,7 +1025,8 @@ void Environment::MemoryInfo(MemoryTracker* tracker) const { | |||
| 1042 | 1025 | tracker->TrackField("fs_stats_field_array", fs_stats_field_array_); | |
| 1043 | 1026 | tracker->TrackField("fs_stats_field_bigint_array", | |
| 1044 | 1027 | fs_stats_field_bigint_array_); | |
| 1045 | - tracker->TrackField("cleanup_hooks", cleanup_hooks_); | ||
| 1028 | + tracker->TrackFieldWithSize( | ||
| 1029 | + "cleanup_hooks", cleanup_hooks_.size() * sizeof(CleanupHookCallback)); | ||
| 1046 | 1030 | tracker->TrackField("async_hooks", async_hooks_); | |
| 1047 | 1031 | tracker->TrackField("immediate_info", immediate_info_); | |
| 1048 | 1032 | tracker->TrackField("tick_info", tick_info_); | |
@@ -1136,4 +1120,8 @@ Local<Object> BaseObject::WrappedObject() const { | |||
| 1136 | 1120 | return object(); | |
| 1137 | 1121 | } | |
| 1138 | 1122 | ||
| 1123 | + bool BaseObject::IsRootNode() const { | ||
| 1124 | + return !persistent_handle_.IsWeak(); | ||
| 1125 | + } | ||
| 1126 | + | ||
| 1139 | 1127 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,13 +208,6 @@ class MemoryTracker { | |||
| 208 | 208 | inline void TrackField(const char* edge_name, | |
| 209 | 209 | const MallocedBuffer<T>& value, | |
| 210 | 210 | const char* node_name = nullptr); | |
| 211 | - // We do not implement CleanupHookCallback as MemoryRetainer | ||
| 212 | - // but instead specialize the method here to avoid the cost of | ||
| 213 | - // virtual pointers. | ||
| 214 | - // TODO(joyeecheung): do this for BaseObject and remove WrappedObject() | ||
| 215 | - void TrackField(const char* edge_name, | ||
| 216 | - const CleanupHookCallback& value, | ||
| 217 | - const char* node_name = nullptr); | ||
| 218 | 211 | inline void TrackField(const char* edge_name, | |
| 219 | 212 | const uv_buf_t& value, | |
| 220 | 213 | const char* node_name = nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ | |||
| 5 | 5 | ||
| 6 | 6 | require('../common'); | |
| 7 | 7 | const { validateSnapshotNodes } = require('../common/heap'); | |
| 8 | - const assert = require('assert'); | ||
| 9 | 8 | ||
| 10 | 9 | // This is just using ContextifyScript as an example here, it can be replaced | |
| 11 | 10 | // with any BaseObject that we can easily instantiate here and register in | |
@@ -16,51 +15,10 @@ const context = require('vm').createScript('const foo = 123'); | |||
| 16 | 15 | ||
| 17 | 16 | validateSnapshotNodes('Node / Environment', [{ | |
| 18 | 17 | children: [ | |
| 19 | - cleanupHooksFilter, | ||
| 20 | 18 | { node_name: 'Node / cleanup_hooks', edge_name: 'cleanup_hooks' }, | |
| 21 | 19 | { node_name: 'process', edge_name: 'process_object' }, | |
| 22 | 20 | { node_name: 'Node / IsolateData', edge_name: 'isolate_data' }, | |
| 23 | 21 | ] | |
| 24 | 22 | }]); | |
| 25 | 23 | ||
| 26 | - function cleanupHooksFilter(edge) { | ||
| 27 | - if (edge.name !== 'cleanup_hooks') { | ||
| 28 | - return false; | ||
| 29 | - } | ||
| 30 | - if (edge.to.type === 'native') { | ||
| 31 | - verifyCleanupHooksInSnapshot(edge.to); | ||
| 32 | - } else { | ||
| 33 | - verifyCleanupHooksInGraph(edge.to); | ||
| 34 | - } | ||
| 35 | - return true; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - function verifyCleanupHooksInSnapshot(node) { | ||
| 39 | - assert.strictEqual(node.name, 'Node / cleanup_hooks'); | ||
| 40 | - const baseObjects = []; | ||
| 41 | - for (const hook of node.outgoingEdges) { | ||
| 42 | - for (const hookEdge of hook.to.outgoingEdges) { | ||
| 43 | - if (hookEdge.name === 'arg') { | ||
| 44 | - baseObjects.push(hookEdge.to); | ||
| 45 | - } | ||
| 46 | - } | ||
| 47 | - } | ||
| 48 | - // Make sure our ContextifyScript show up. | ||
| 49 | - assert(baseObjects.some((node) => node.name === 'Node / ContextifyScript')); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - function verifyCleanupHooksInGraph(node) { | ||
| 53 | - assert.strictEqual(node.name, 'Node / cleanup_hooks'); | ||
| 54 | - const baseObjects = []; | ||
| 55 | - for (const hook of node.edges) { | ||
| 56 | - for (const hookEdge of hook.to.edges) { | ||
| 57 | - if (hookEdge.name === 'arg') { | ||
| 58 | - baseObjects.push(hookEdge.to); | ||
| 59 | - } | ||
| 60 | - } | ||
| 61 | - } | ||
| 62 | - // Make sure our ContextifyScript show up. | ||
| 63 | - assert(baseObjects.some((node) => node.name === 'Node / ContextifyScript')); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | 24 | console.log(context); // Make sure it's not GC'ed | |
| Back | FazBrowse Home | New Git URL |
0 commit comments