Skip to content

Commit 95efbaf

Browse files
isheludkoV8 LUCI CQ
authored andcommitted
[api] Delete usages of v8::HeapProfile::ObjectNameResolver
... and start deprecation of the class definition. Bug: 333672197 Change-Id: I9517d09cd1e01b9893384cb9408d714affcefdee Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7614327 Commit-Queue: Igor Sheludko <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Cr-Commit-Position: refs/heads/main@{#105492}
1 parent 6830692 commit 95efbaf

6 files changed

Lines changed: 24 additions & 234 deletions

File tree

‎include/v8-profiler.h‎

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ class V8_EXPORT HeapProfiler {
10631063
*
10641064
* This interface will soon be deprecated in favour of ContextNameResolver.
10651065
*/
1066-
class ObjectNameResolver {
1066+
class V8_DEPRECATE_SOON("Use ContextNameResolver instead.")
1067+
ObjectNameResolver {
10671068
public:
10681069
/**
10691070
* Returns name to be used in the heap snapshot for given node. Returned
@@ -1121,24 +1122,13 @@ class V8_EXPORT HeapProfiler {
11211122
// NOLINTNEXTLINE
11221123
HeapSnapshotOptions() {}
11231124

1124-
// TODO(https://crbug.com/333672197): remove once ObjectNameResolver is
1125-
// removed.
1126-
ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(HeapSnapshotOptions)
1127-
11281125
/**
11291126
* The control used to report intermediate progress to.
11301127
*/
11311128
ActivityControl* control = nullptr;
1132-
/**
1133-
* The resolver used by the snapshot generator to get names for V8 objects.
1134-
*/
1135-
V8_DEPRECATED("Use context_name_resolver callback instead.")
1136-
ObjectNameResolver* global_object_name_resolver = nullptr;
11371129
/**
11381130
* The resolver used by the snapshot generator to get names for v8::Context
11391131
* objects.
1140-
* In case both this and |global_object_name_resolver| callbacks are
1141-
* provided, this one will be used.
11421132
*/
11431133
ContextNameResolver* context_name_resolver = nullptr;
11441134
/**
@@ -1170,18 +1160,8 @@ class V8_EXPORT HeapProfiler {
11701160
*
11711161
* \returns the snapshot.
11721162
*/
1173-
V8_DEPRECATED("Use overload with ContextNameResolver* resolver instead.")
1174-
const HeapSnapshot* TakeHeapSnapshot(
1175-
ActivityControl* control, ObjectNameResolver* global_object_name_resolver,
1176-
bool hide_internals = true, bool capture_numeric_value = false);
1177-
const HeapSnapshot* TakeHeapSnapshot(ActivityControl* control,
1178-
ContextNameResolver* resolver,
1179-
bool hide_internals = true,
1180-
bool capture_numeric_value = false);
1181-
// TODO(333672197): remove this version once ObjectNameResolver* overload
1182-
// is removed.
11831163
const HeapSnapshot* TakeHeapSnapshot(ActivityControl* control,
1184-
std::nullptr_t resolver = nullptr,
1164+
ContextNameResolver* resolver = nullptr,
11851165
bool hide_internals = true,
11861166
bool capture_numeric_value = false);
11871167

‎src/api/api.cc‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11834,21 +11834,6 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
1183411834
reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(options));
1183511835
}
1183611836

11837-
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(ActivityControl* control,
11838-
ObjectNameResolver* resolver,
11839-
bool hide_internals,
11840-
bool capture_numeric_value) {
11841-
HeapSnapshotOptions options;
11842-
options.control = control;
11843-
options.global_object_name_resolver = resolver;
11844-
options.snapshot_mode = hide_internals ? HeapSnapshotMode::kRegular
11845-
: HeapSnapshotMode::kExposeInternals;
11846-
options.numerics_mode = capture_numeric_value
11847-
? NumericsMode::kExposeNumericValues
11848-
: NumericsMode::kHideNumericValues;
11849-
return TakeHeapSnapshot(options);
11850-
}
11851-
1185211837
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
1185311838
ActivityControl* control, ContextNameResolver* resolver,
1185411839
bool hide_internals, bool capture_numeric_value) {
@@ -11863,20 +11848,6 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
1186311848
return TakeHeapSnapshot(options);
1186411849
}
1186511850

11866-
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(ActivityControl* control,
11867-
std::nullptr_t resolver,
11868-
bool hide_internals,
11869-
bool capture_numeric_value) {
11870-
HeapSnapshotOptions options;
11871-
options.control = control;
11872-
options.snapshot_mode = hide_internals ? HeapSnapshotMode::kRegular
11873-
: HeapSnapshotMode::kExposeInternals;
11874-
options.numerics_mode = capture_numeric_value
11875-
? NumericsMode::kExposeNumericValues
11876-
: NumericsMode::kHideNumericValues;
11877-
return TakeHeapSnapshot(options);
11878-
}
11879-
1188011851
std::vector<v8::Local<v8::Value>> HeapProfiler::GetDetachedJSWrapperObjects() {
1188111852
return reinterpret_cast<i::HeapProfiler*>(this)
1188211853
->GetDetachedJSWrapperObjects();

‎src/profiler/heap-profiler.cc‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,9 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
146146
use_cpp_class_name.emplace(heap()->cpp_heap());
147147
}
148148

149-
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
150-
// TODO(https://crbug.com/333672197): remove.
151-
START_ALLOW_USE_DEPRECATED()
152-
HeapSnapshotGenerator generator(
153-
result, options.control, options.global_object_name_resolver,
154-
options.context_name_resolver, heap(), options.stack_state);
155-
END_ALLOW_USE_DEPRECATED()
149+
HeapSnapshotGenerator generator(result, options.control,
150+
options.context_name_resolver, heap(),
151+
options.stack_state);
156152
if (!generator.GenerateSnapshot()) {
157153
delete result;
158154
result = nullptr;
@@ -186,13 +182,9 @@ void HeapProfiler::WriteSnapshotToDiskAfterGC(HeapSnapshotMode snapshot_mode) {
186182
v8::HeapProfiler::HeapSnapshotOptions options;
187183
std::unique_ptr<HeapSnapshot> result(
188184
new HeapSnapshot(this, snapshot_mode, options.numerics_mode));
189-
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
190-
// TODO(https://crbug.com/333672197): remove.
191-
START_ALLOW_USE_DEPRECATED()
192-
HeapSnapshotGenerator generator(
193-
result.get(), options.control, options.global_object_name_resolver,
194-
options.context_name_resolver, heap(), options.stack_state);
195-
END_ALLOW_USE_DEPRECATED()
185+
HeapSnapshotGenerator generator(result.get(), options.control,
186+
options.context_name_resolver, heap(),
187+
options.stack_state);
196188
if (!generator.GenerateSnapshotAfterGC()) return;
197189
i::FileOutputStream stream(filename.c_str());
198190
if (stream.IsOpen()) {

‎src/profiler/heap-snapshot-generator.cc‎

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -823,18 +823,16 @@ void HeapObjectsMap::RemoveDeadEntries() {
823823
entries_map_.occupancy());
824824
}
825825

826-
V8HeapExplorer::V8HeapExplorer(
827-
HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress,
828-
v8::HeapProfiler::ObjectNameResolver* resolver,
829-
v8::HeapProfiler::ContextNameResolver* context_resolver)
826+
V8HeapExplorer::V8HeapExplorer(HeapSnapshot* snapshot,
827+
SnapshottingProgressReportingInterface* progress,
828+
v8::HeapProfiler::ContextNameResolver* resolver)
830829
: heap_(snapshot->profiler()->heap_object_map()->heap()),
831830
snapshot_(snapshot),
832831
names_(snapshot_->profiler()->names()),
833832
heap_object_map_(snapshot_->profiler()->heap_object_map()),
834833
progress_(progress),
835834
generator_(nullptr),
836-
global_object_name_resolver_(resolver),
837-
native_context_name_resolver_(context_resolver) {}
835+
native_context_name_resolver_(resolver) {}
838836

839837
HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) {
840838
return AddEntry(
@@ -3027,43 +3025,20 @@ class NativeContextEnumerator : public RootVisitor {
30273025

30283026
V8HeapExplorer::TemporaryNativeContextTags
30293027
V8HeapExplorer::CollectTemporaryNativeContextTags() {
3030-
if (!global_object_name_resolver_ && !native_context_name_resolver_) {
3031-
return {};
3032-
}
3028+
if (!native_context_name_resolver_) return {};
30333029

30343030
Isolate* isolate = heap_->isolate();
30353031
TemporaryNativeContextTags native_context_tags;
30363032
HandleScope scope(isolate);
30373033
NativeContextEnumerator enumerator(
30383034
isolate, [this, isolate, &native_context_tags](
30393035
DirectHandle<NativeContext> native_context) {
3040-
if (native_context_name_resolver_) {
3041-
v8::Local<v8::Context> context = Utils::ToLocal(native_context);
3042-
if (const char* tag =
3043-
native_context_name_resolver_->GetName(context)) {
3044-
native_context_tags.emplace_back(
3045-
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
3046-
context),
3047-
tag);
3048-
native_context_tags.back().first.SetWeak();
3049-
}
3050-
return;
3051-
}
3052-
3053-
DirectHandle<JSObject> global(native_context->global_object(), isolate);
3054-
if (const char* tag =
3055-
global_object_name_resolver_->GetName(Utils::ToLocal(global))) {
3056-
native_context_tags.emplace_back(
3057-
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
3058-
Utils::ToLocal(native_context)),
3059-
tag);
3060-
native_context_tags.back().first.SetWeak();
3061-
return;
3062-
}
3036+
v8::Local<v8::Context> context = Utils::ToLocal(native_context);
3037+
const char* tag = native_context_name_resolver_->GetName(context);
30633038
native_context_tags.emplace_back(
30643039
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
3065-
Utils::ToLocal(native_context)),
3066-
nullptr);
3040+
context),
3041+
tag);
30673042
native_context_tags.back().first.SetWeak();
30683043
});
30693044
isolate->global_handles()->IterateAllRoots(&enumerator);
@@ -3373,12 +3348,11 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
33733348

33743349
HeapSnapshotGenerator::HeapSnapshotGenerator(
33753350
HeapSnapshot* snapshot, v8::ActivityControl* control,
3376-
v8::HeapProfiler::ObjectNameResolver* resolver,
3377-
v8::HeapProfiler::ContextNameResolver* context_resolver, Heap* heap,
3351+
v8::HeapProfiler::ContextNameResolver* resolver, Heap* heap,
33783352
cppgc::EmbedderStackState stack_state)
33793353
: snapshot_(snapshot),
33803354
control_(control),
3381-
v8_heap_explorer_(snapshot_, this, resolver, context_resolver),
3355+
v8_heap_explorer_(snapshot_, this, resolver),
33823356
dom_explorer_(snapshot_, this),
33833357
heap_(heap),
33843358
stack_state_(stack_state) {}

‎src/profiler/heap-snapshot-generator.h‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
413413
public:
414414
V8HeapExplorer(HeapSnapshot* snapshot,
415415
SnapshottingProgressReportingInterface* progress,
416-
v8::HeapProfiler::ObjectNameResolver* resolver,
417-
v8::HeapProfiler::ContextNameResolver* context_resolver);
416+
v8::HeapProfiler::ContextNameResolver* resolver);
418417
~V8HeapExplorer() override = default;
419418
V8HeapExplorer(const V8HeapExplorer&) = delete;
420419
V8HeapExplorer& operator=(const V8HeapExplorer&) = delete;
@@ -610,7 +609,6 @@ class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
610609
native_context_tag_map_;
611610
UnorderedHeapObjectMap<const char*> strong_gc_subroot_names_;
612611
std::unordered_set<Tagged<NativeContext>, Object::Hasher> user_roots_;
613-
v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
614612
v8::HeapProfiler::ContextNameResolver* native_context_name_resolver_;
615613

616614
std::vector<bool> visited_fields_;
@@ -660,11 +658,9 @@ class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface {
660658
// their representations in heap snapshots.
661659
using SmiEntriesMap = std::unordered_map<int, HeapEntry*>;
662660

663-
HeapSnapshotGenerator(
664-
HeapSnapshot* snapshot, v8::ActivityControl* control,
665-
v8::HeapProfiler::ObjectNameResolver* resolver,
666-
v8::HeapProfiler::ContextNameResolver* context_name_resolver, Heap* heap,
667-
cppgc::EmbedderStackState stack_state);
661+
HeapSnapshotGenerator(HeapSnapshot* snapshot, v8::ActivityControl* control,
662+
v8::HeapProfiler::ContextNameResolver* resolver,
663+
Heap* heap, cppgc::EmbedderStackState stack_state);
668664
HeapSnapshotGenerator(const HeapSnapshotGenerator&) = delete;
669665
HeapSnapshotGenerator& operator=(const HeapSnapshotGenerator&) = delete;
670666
bool GenerateSnapshot();

‎test/cctest/test-heap-profiler.cc‎

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,129 +2176,6 @@ TEST(DeleteHeapSnapshot) {
21762176
CHECK(!FindHeapSnapshot(heap_profiler, s3));
21772177
}
21782178

2179-
class NameResolver : public v8::HeapProfiler::ObjectNameResolver {
2180-
public:
2181-
const char* GetName(v8::Local<v8::Object> object) override {
2182-
return "Global object name";
2183-
}
2184-
};
2185-
2186-
TEST(GlobalObjectNameSimple) {
2187-
LocalContext env;
2188-
v8::HandleScope scope(env.isolate());
2189-
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2190-
2191-
CompileRun("document = { URL:\"abcdefgh\" };");
2192-
2193-
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2194-
// TODO(https://crbug.com/333672197): remove.
2195-
START_ALLOW_USE_DEPRECATED()
2196-
NameResolver name_resolver;
2197-
const v8::HeapSnapshot* snapshot =
2198-
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2199-
END_ALLOW_USE_DEPRECATED()
2200-
CHECK(ValidateSnapshot(snapshot));
2201-
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2202-
CHECK_NOT_NULL(native_context);
2203-
CHECK_EQ(std::string("system / NativeContext / Global object name"),
2204-
std::string(GetName(native_context)));
2205-
2206-
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2207-
CHECK_NOT_NULL(global);
2208-
CHECK_EQ(std::string("Object (global*) / Global object name"),
2209-
std::string(GetName(global)));
2210-
2211-
const v8::HeapGraphNode* global_proxy = GetProperty(
2212-
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2213-
CHECK_NOT_NULL(global_proxy);
2214-
CHECK_EQ(std::string("Object (global) / Global object name"),
2215-
std::string(GetName(global_proxy)));
2216-
}
2217-
2218-
TEST(GlobalObjectName) {
2219-
v8::Isolate* isolate = CcTest::isolate();
2220-
v8::HandleScope scope(isolate);
2221-
2222-
v8::Local<v8::FunctionTemplate> global_constructor =
2223-
v8::FunctionTemplate::New(isolate);
2224-
global_constructor->SetClassName(v8_str("MyGlobal"));
2225-
2226-
v8::Local<v8::ObjectTemplate> global_template =
2227-
v8::ObjectTemplate::New(isolate, global_constructor);
2228-
LocalContext env(isolate, nullptr, global_template);
2229-
2230-
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2231-
2232-
CompileRun("document = { URL:\"abcdefgh\" };");
2233-
2234-
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2235-
// TODO(https://crbug.com/333672197): remove.
2236-
START_ALLOW_USE_DEPRECATED()
2237-
NameResolver name_resolver;
2238-
const v8::HeapSnapshot* snapshot =
2239-
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2240-
END_ALLOW_USE_DEPRECATED()
2241-
CHECK(ValidateSnapshot(snapshot));
2242-
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2243-
CHECK_NOT_NULL(native_context);
2244-
CHECK_EQ(std::string("system / NativeContext / Global object name"),
2245-
std::string(GetName(native_context)));
2246-
2247-
const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
2248-
CHECK_NOT_NULL(global);
2249-
CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
2250-
std::string(GetName(global)));
2251-
2252-
const v8::HeapGraphNode* global_proxy = GetProperty(
2253-
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2254-
CHECK_NOT_NULL(global_proxy);
2255-
CHECK_EQ(std::string("MyGlobal (global) / Global object name"),
2256-
std::string(GetName(global_proxy)));
2257-
}
2258-
2259-
TEST(GlobalObjectNameDetached) {
2260-
v8::Isolate* isolate = CcTest::isolate();
2261-
v8::HandleScope scope(isolate);
2262-
2263-
v8::Local<v8::FunctionTemplate> global_constructor =
2264-
v8::FunctionTemplate::New(isolate);
2265-
global_constructor->SetClassName(v8_str("MyGlobal"));
2266-
2267-
v8::Local<v8::ObjectTemplate> global_template =
2268-
v8::ObjectTemplate::New(isolate, global_constructor);
2269-
LocalContext env(isolate, nullptr, global_template);
2270-
2271-
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2272-
2273-
CompileRun("document = { URL:\"abcdefgh\" };");
2274-
2275-
env->DetachGlobal();
2276-
2277-
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2278-
// TODO(https://crbug.com/333672197): remove.
2279-
START_ALLOW_USE_DEPRECATED()
2280-
NameResolver name_resolver;
2281-
const v8::HeapSnapshot* snapshot =
2282-
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2283-
END_ALLOW_USE_DEPRECATED()
2284-
CHECK(ValidateSnapshot(snapshot));
2285-
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2286-
CHECK_NOT_NULL(native_context);
2287-
CHECK_EQ(std::string("system / NativeContext / Global object name"),
2288-
std::string(GetName(native_context)));
2289-
2290-
const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
2291-
CHECK_NOT_NULL(global);
2292-
CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
2293-
std::string(GetName(global)));
2294-
2295-
const v8::HeapGraphNode* global_proxy = GetProperty(
2296-
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2297-
CHECK_NOT_NULL(global_proxy);
2298-
CHECK_EQ(std::string("Object (global) / <detached>"),
2299-
std::string(GetName(global_proxy)));
2300-
}
2301-
23022179
class ContextNameResolver : public v8::HeapProfiler::ContextNameResolver {
23032180
public:
23042181
const char* GetName(v8::Local<v8::Context> context) override {

0 commit comments

Comments
 (0)