| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f8dddd3 commit 83aaad7
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 | |
|---|---|---|---|
@@ -1030,33 +1030,16 @@ Environment* Environment::worker_parent_env() const { | |||
| 1030 | 1030 | return worker_context()->env(); | |
| 1031 | 1031 | } | |
| 1032 | 1032 | ||
| 1033 | - void MemoryTracker::TrackField(const char* edge_name, | ||
| 1034 | - const CleanupHookCallback& value, | ||
| 1035 | - const char* node_name) { | ||
| 1036 | - HandleScope handle_scope(isolate_); | ||
| 1037 | - // Here, we utilize the fact that CleanupHookCallback instances | ||
| 1038 | - // are all unique and won't be tracked twice in one BuildEmbedderGraph | ||
| 1039 | - // callback. | ||
| 1040 | - MemoryRetainerNode* n = | ||
| 1041 | - PushNode("CleanupHookCallback", sizeof(value), edge_name); | ||
| 1042 | - // TODO(joyeecheung): at the moment only arguments of type BaseObject will be | ||
| 1043 | - // identified and tracked here (based on their deleters), | ||
| 1044 | - // but we may convert and track other known types here. | ||
| 1045 | - BaseObject* obj = value.GetBaseObject(); | ||
| 1046 | - if (obj != nullptr && obj->IsDoneInitializing()) { | ||
| 1047 | - TrackField("arg", obj); | ||
| 1048 | - } | ||
| 1049 | - CHECK_EQ(CurrentNode(), n); | ||
| 1050 | - CHECK_NE(n->size_, 0); | ||
| 1051 | - PopNode(); | ||
| 1052 | - } | ||
| 1053 | - | ||
| 1054 | 1033 | void Environment::BuildEmbedderGraph(Isolate* isolate, | |
| 1055 | 1034 | EmbedderGraph* graph, | |
| 1056 | 1035 | void* data) { | |
| 1057 | 1036 | MemoryTracker tracker(isolate, graph); | |
| 1058 | 1037 | Environment* env = static_cast<Environment*>(data); | |
| 1059 | 1038 | tracker.Track(env); | |
| 1039 | + env->ForEachBaseObject([&](BaseObject* obj) { | ||
| 1040 | + if (obj->IsDoneInitializing()) | ||
| 1041 | + tracker.Track(obj); | ||
| 1042 | + }); | ||
| 1060 | 1043 | } | |
| 1061 | 1044 | ||
| 1062 | 1045 | inline size_t Environment::SelfSize() const { | |
@@ -1083,7 +1066,8 @@ void Environment::MemoryInfo(MemoryTracker* tracker) const { | |||
| 1083 | 1066 | tracker->TrackField("should_abort_on_uncaught_toggle", | |
| 1084 | 1067 | should_abort_on_uncaught_toggle_); | |
| 1085 | 1068 | tracker->TrackField("stream_base_state", stream_base_state_); | |
| 1086 | - tracker->TrackField("cleanup_hooks", cleanup_hooks_); | ||
| 1069 | + tracker->TrackFieldWithSize( | ||
| 1070 | + "cleanup_hooks", cleanup_hooks_.size() * sizeof(CleanupHookCallback)); | ||
| 1087 | 1071 | tracker->TrackField("async_hooks", async_hooks_); | |
| 1088 | 1072 | tracker->TrackField("immediate_info", immediate_info_); | |
| 1089 | 1073 | tracker->TrackField("tick_info", tick_info_); | |
@@ -1124,4 +1108,8 @@ Local<Object> BaseObject::WrappedObject() const { | |||
| 1124 | 1108 | return object(); | |
| 1125 | 1109 | } | |
| 1126 | 1110 | ||
| 1111 | + bool BaseObject::IsRootNode() const { | ||
| 1112 | + return !persistent_handle_.IsWeak(); | ||
| 1113 | + } | ||
| 1114 | + | ||
| 1127 | 1115 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -216,13 +216,6 @@ class MemoryTracker { | |||
| 216 | 216 | inline void TrackField(const char* edge_name, | |
| 217 | 217 | const v8::BackingStore* value, | |
| 218 | 218 | const char* node_name = nullptr); | |
| 219 | - // We do not implement CleanupHookCallback as MemoryRetainer | ||
| 220 | - // but instead specialize the method here to avoid the cost of | ||
| 221 | - // virtual pointers. | ||
| 222 | - // TODO(joyeecheung): do this for BaseObject and remove WrappedObject() | ||
| 223 | - void TrackField(const char* edge_name, | ||
| 224 | - const CleanupHookCallback& value, | ||
| 225 | - const char* node_name = nullptr); | ||
| 226 | 219 | inline void TrackField(const char* edge_name, | |
| 227 | 220 | const uv_buf_t& value, | |
| 228 | 221 | 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