Skip to content

Commit af5e7be

Browse files
committed
deps: V8: cherry-pick 639edaed92fb
Original commit message: [heap-profiler]: expose QueryObjects() to v8::HeapProfiler This allows embedders to use this API for testing memory leaks more reliably. Refs: v8/v8@639edae
1 parent ce9d264 commit af5e7be

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.14',
39+
'v8_embedder_string': '-node.15',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/include/v8-profiler.h

+10
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,22 @@ class V8_EXPORT EmbedderGraph {
921921
virtual ~EmbedderGraph() = default;
922922
};
923923

924+
class QueryObjectPredicate {
925+
public:
926+
virtual ~QueryObjectPredicate() = default;
927+
virtual bool Filter(v8::Local<v8::Object> object) = 0;
928+
};
929+
924930
/**
925931
* Interface for controlling heap profiling. Instance of the
926932
* profiler can be retrieved using v8::Isolate::GetHeapProfiler.
927933
*/
928934
class V8_EXPORT HeapProfiler {
929935
public:
936+
void QueryObjects(v8::Local<v8::Context> context,
937+
QueryObjectPredicate* predicate,
938+
std::vector<v8::Global<v8::Object>>* objects);
939+
930940
enum SamplingFlags {
931941
kSamplingNoFlags = 0,
932942
kSamplingForceGC = 1 << 0,

deps/v8/src/api/api.cc

+10
Original file line numberDiff line numberDiff line change
@@ -10901,6 +10901,16 @@ int HeapProfiler::GetSnapshotCount() {
1090110901
return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
1090210902
}
1090310903

10904+
void HeapProfiler::QueryObjects(Local<Context> v8_context,
10905+
QueryObjectPredicate* predicate,
10906+
std::vector<Global<Object>>* objects) {
10907+
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate());
10908+
i::HeapProfiler* profiler = reinterpret_cast<i::HeapProfiler*>(this);
10909+
DCHECK_EQ(isolate, profiler->isolate());
10910+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
10911+
profiler->QueryObjects(Utils::OpenHandle(*v8_context), predicate, objects);
10912+
}
10913+
1090410914
const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
1090510915
return reinterpret_cast<const HeapSnapshot*>(
1090610916
reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));

deps/v8/src/debug/debug-interface.cc

-9
Original file line numberDiff line numberDiff line change
@@ -1211,15 +1211,6 @@ v8::MaybeLocal<v8::Value> EvaluateGlobalForTesting(
12111211
RETURN_ESCAPED(result);
12121212
}
12131213

1214-
void QueryObjects(v8::Local<v8::Context> v8_context,
1215-
QueryObjectPredicate* predicate,
1216-
std::vector<v8::Global<v8::Object>>* objects) {
1217-
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate());
1218-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1219-
isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context),
1220-
predicate, objects);
1221-
}
1222-
12231214
void GlobalLexicalScopeNames(v8::Local<v8::Context> v8_context,
12241215
std::vector<v8::Global<v8::String>>* names) {
12251216
i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);

deps/v8/src/debug/debug-interface.h

-10
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,6 @@ class V8_EXPORT_PRIVATE StackTraceIterator {
530530
bool throw_on_side_effect) = 0;
531531
};
532532

533-
class QueryObjectPredicate {
534-
public:
535-
virtual ~QueryObjectPredicate() = default;
536-
virtual bool Filter(v8::Local<v8::Object> object) = 0;
537-
};
538-
539-
void QueryObjects(v8::Local<v8::Context> context,
540-
QueryObjectPredicate* predicate,
541-
std::vector<v8::Global<v8::Object>>* objects);
542-
543533
void GlobalLexicalScopeNames(v8::Local<v8::Context> context,
544534
std::vector<v8::Global<v8::String>>* names);
545535

deps/v8/src/inspector/v8-debugger.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "include/v8-context.h"
99
#include "include/v8-function.h"
1010
#include "include/v8-microtask-queue.h"
11+
#include "include/v8-profiler.h"
1112
#include "include/v8-util.h"
1213
#include "src/inspector/inspected-context.h"
1314
#include "src/inspector/protocol/Protocol.h"
@@ -38,7 +39,7 @@ void cleanupExpiredWeakPointers(Map& map) {
3839
}
3940
}
4041

41-
class MatchPrototypePredicate : public v8::debug::QueryObjectPredicate {
42+
class MatchPrototypePredicate : public v8::QueryObjectPredicate {
4243
public:
4344
MatchPrototypePredicate(V8InspectorImpl* inspector,
4445
v8::Local<v8::Context> context,
@@ -994,7 +995,7 @@ v8::Local<v8::Array> V8Debugger::queryObjects(v8::Local<v8::Context> context,
994995
v8::Isolate* isolate = context->GetIsolate();
995996
std::vector<v8::Global<v8::Object>> v8_objects;
996997
MatchPrototypePredicate predicate(m_inspector, context, prototype);
997-
v8::debug::QueryObjects(context, &predicate, &v8_objects);
998+
isolate->GetHeapProfiler()->QueryObjects(context, &predicate, &v8_objects);
998999

9991000
v8::MicrotasksScope microtasksScope(context,
10001001
v8::MicrotasksScope::kDoNotRunMicrotasks);

deps/v8/src/profiler/heap-profiler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Heap* HeapProfiler::heap() const { return ids_->heap(); }
247247
Isolate* HeapProfiler::isolate() const { return heap()->isolate(); }
248248

249249
void HeapProfiler::QueryObjects(Handle<Context> context,
250-
debug::QueryObjectPredicate* predicate,
250+
v8::QueryObjectPredicate* predicate,
251251
std::vector<v8::Global<v8::Object>>* objects) {
252252
// We need a stack marker here to allow deterministic passes over the stack.
253253
// The garbage collection and the two object heap iterators should scan the

deps/v8/src/profiler/heap-profiler.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class StringsStorage;
3030
// generate consistent IDs for moved objects.
3131
class HeapProfilerNativeMoveListener {
3232
public:
33-
HeapProfilerNativeMoveListener(HeapProfiler* profiler)
33+
explicit HeapProfilerNativeMoveListener(HeapProfiler* profiler)
3434
: profiler_(profiler) {}
3535
HeapProfilerNativeMoveListener(const HeapProfilerNativeMoveListener& other) =
3636
delete;
@@ -116,8 +116,7 @@ class HeapProfiler : public HeapObjectAllocationTracker {
116116

117117
Isolate* isolate() const;
118118

119-
void QueryObjects(Handle<Context> context,
120-
debug::QueryObjectPredicate* predicate,
119+
void QueryObjects(Handle<Context> context, QueryObjectPredicate* predicate,
121120
std::vector<v8::Global<v8::Object>>* objects);
122121
void set_native_move_listener(
123122
std::unique_ptr<HeapProfilerNativeMoveListener> listener) {

0 commit comments

Comments
 (0)