cppgc-js: Expose size for C++ types with a human-readable name

A human-readable name is in Blink only available for C++ types with
JS wrapper objects and for manually annotated types that are interesting
for the snapshot. Return the proper C++ shallow size of the object in
this case. (Merge nodes will have their JS+C++ sizes added.)

Bug: chromium:1228411, chromium:1056170
Change-Id: Ib2b1b7b9dec80e5cccccb1aad8c4c035715612ec
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3021169
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75698}
This commit is contained in:
Michael Lippautz 2021-07-13 11:20:12 +02:00 committed by V8 LUCI CQ
parent 0ea917e71e
commit 7ff9cd15bb
2 changed files with 9 additions and 13 deletions

View File

@ -91,7 +91,7 @@ class NameTrait final : public NameTraitBase {
static const HeapObjectName leaky_name =
GetNameFromTypeSignature(PRETTY_FUNCTION_VALUE);
return leaky_name;
return {leaky_name, false};
#undef PRETTY_FUNCTION_VALUE

View File

@ -6,6 +6,7 @@
#include <memory>
#include "include/cppgc/internal/name-trait.h"
#include "include/cppgc/trace-trait.h"
#include "include/v8-cppgc.h"
#include "include/v8-profiler.h"
@ -34,20 +35,14 @@ using cppgc::internal::HeapObjectHeader;
// Node representing a C++ object on the heap.
class EmbedderNode : public v8::EmbedderGraph::Node {
public:
explicit EmbedderNode(const char* name, size_t size)
EmbedderNode(cppgc::internal::HeapObjectName name, size_t size)
: name_(name), size_(size) {
USE(size_);
}
~EmbedderNode() override = default;
const char* Name() final { return name_; }
size_t SizeInBytes() final {
#if CPPGC_SUPPORTS_OBJECT_NAMES
return size_;
#else // !CPPGC_SUPPORTS_OBJECT_NAMES
return 0;
#endif // !CPPGC_SUPPORTS_OBJECT_NAMES
}
const char* Name() final { return name_.value; }
size_t SizeInBytes() final { return name_.name_was_hidden ? 0 : size_; }
void SetWrapperNode(v8::EmbedderGraph::Node* wrapper_node) {
wrapper_node_ = wrapper_node;
@ -70,7 +65,7 @@ class EmbedderNode : public v8::EmbedderGraph::Node {
}
private:
const char* name_;
cppgc::internal::HeapObjectName name_;
size_t size_;
Node* wrapper_node_ = nullptr;
Detachedness detachedness_ = Detachedness::kUnknown;
@ -80,7 +75,8 @@ class EmbedderNode : public v8::EmbedderGraph::Node {
// Node representing an artificial root group, e.g., set of Persistent handles.
class EmbedderRootNode final : public EmbedderNode {
public:
explicit EmbedderRootNode(const char* name) : EmbedderNode(name, 0) {}
explicit EmbedderRootNode(const char* name)
: EmbedderNode({name, false}, 0) {}
~EmbedderRootNode() final = default;
bool IsRootNode() final { return true; }
@ -411,7 +407,7 @@ class CppGraphBuilderImpl final {
EmbedderNode* AddNode(const HeapObjectHeader& header) {
return static_cast<EmbedderNode*>(
graph_.AddNode(std::unique_ptr<v8::EmbedderGraph::Node>{
new EmbedderNode(header.GetName().value, header.AllocatedSize())}));
new EmbedderNode(header.GetName(), header.AllocatedSize())}));
}
void AddEdge(State& parent, const HeapObjectHeader& header,