diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-09-23 17:52:09 -0400 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-10-04 15:32:30 +0200 |
commit | 92fa0fcdb76e2b6cb0040eede97fe3c167c31897 (patch) | |
tree | 5016ac6cbf7e5873421788387a5b2e011c31ac56 /src/heap_utils.cc | |
parent | c0c58d5660aeea93c492877894f66dd55771be2e (diff) | |
download | android-node-v8-92fa0fcdb76e2b6cb0040eede97fe3c167c31897.tar.gz android-node-v8-92fa0fcdb76e2b6cb0040eede97fe3c167c31897.tar.bz2 android-node-v8-92fa0fcdb76e2b6cb0040eede97fe3c167c31897.zip |
src: name EmbededderGraph edges and use class names for nodes
This patch:
- Refactors the `MemoryRetainer` API so that the impementer no longer
calls `TrackThis()` that sets the size of node on the top of the
stack, which may be hard to understand. Instead now they implements
`SelfSize()` to provide their self sizes. Also documents
the API in the header.
- Refactors `MemoryTracker` so it calls `MemoryInfoName()` and
`SelfSize()` of `MemoryRetainer` to retrieve info about them, and
separate `node_names` and `edge_names` so the edges can be properly
named with reference names and the nodes can be named with class
names. (Previously the nodes are named with reference names while the
edges are all indexed and appear as array elements).
- Adds `SET_MEMORY_INFO_NAME()`, `SET_SELF_SIZE()` and
`SET_NO_MEMORY_INFO()` convenience macros
- Fixes a few `MemoryInfo` calls in some `MemoryRetainers` to track
their references properly.
- Refactors the heapdump tests to check both node names and edge names,
distinguishing between wrapped JS nodes (without prefixes)
and embedder wrappers (prefixed with `Node / `).
PR-URL: https://github.com/nodejs/node/pull/23072
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/heap_utils.cc')
-rw-r--r-- | src/heap_utils.cc | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/src/heap_utils.cc b/src/heap_utils.cc index 668dff3451..72ad33c99a 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -103,15 +103,28 @@ class JSGraph : public EmbedderGraph { for (const std::unique_ptr<Node>& n : nodes_) { Local<Object> obj = info_objects[n.get()]; Local<Value> value; - if (!String::NewFromUtf8(isolate_, n->Name(), - v8::NewStringType::kNormal).ToLocal(&value) || + std::string name_str; + const char* prefix = n->NamePrefix(); + if (prefix == nullptr) { + name_str = n->Name(); + } else { + name_str = n->NamePrefix(); + name_str += " "; + name_str += n->Name(); + } + if (!String::NewFromUtf8( + isolate_, name_str.c_str(), v8::NewStringType::kNormal) + .ToLocal(&value) || obj->Set(context, name_string, value).IsNothing() || - obj->Set(context, is_root_string, - Boolean::New(isolate_, n->IsRootNode())).IsNothing() || - obj->Set(context, size_string, - Number::New(isolate_, n->SizeInBytes())).IsNothing() || - obj->Set(context, edges_string, - Array::New(isolate_)).IsNothing()) { + obj->Set(context, + is_root_string, + Boolean::New(isolate_, n->IsRootNode())) + .IsNothing() || + obj->Set(context, + size_string, + Number::New(isolate_, n->SizeInBytes())) + .IsNothing() || + obj->Set(context, edges_string, Array::New(isolate_)).IsNothing()) { return MaybeLocal<Array>(); } if (nodes->Set(context, i++, obj).IsNothing()) @@ -145,20 +158,21 @@ class JSGraph : public EmbedderGraph { size_t j = 0; for (const auto& edge : edge_info.second) { Local<Object> to_object = info_objects[edge.second]; - Local<Object> edge_info = Object::New(isolate_); + Local<Object> edge_obj = Object::New(isolate_); Local<Value> edge_name_value; const char* edge_name = edge.first; - if (edge_name != nullptr && - !String::NewFromUtf8( - isolate_, edge_name, v8::NewStringType::kNormal) - .ToLocal(&edge_name_value)) { - return MaybeLocal<Array>(); + if (edge_name != nullptr) { + if (!String::NewFromUtf8( + isolate_, edge_name, v8::NewStringType::kNormal) + .ToLocal(&edge_name_value)) { + return MaybeLocal<Array>(); + } } else { edge_name_value = Number::New(isolate_, j++); } - if (edge_info->Set(context, name_string, edge_name_value).IsNothing() || - edge_info->Set(context, to_string, to_object).IsNothing() || - edges.As<Array>()->Set(context, i++, edge_info).IsNothing()) { + if (edge_obj->Set(context, name_string, edge_name_value).IsNothing() || + edge_obj->Set(context, to_string, to_object).IsNothing() || + edges.As<Array>()->Set(context, i++, edge_obj).IsNothing()) { return MaybeLocal<Array>(); } } |