diff --git a/include/v8-isolate.h b/include/v8-isolate.h index 18855b772..22377d60a 100644 --- a/include/v8-isolate.h +++ b/include/v8-isolate.h @@ -1590,6 +1590,12 @@ class V8_EXPORT Isolate { */ void VisitExternalResources(ExternalResourceVisitor* visitor); + /** + * Iterates through all the persistent handles in the current isolate's heap + * that have class_ids. + */ + void VisitHandlesWithClassIds(PersistentHandleVisitor* visitor); + /** * Check if this isolate is in use. * True if at least one thread Enter'ed this isolate. diff --git a/src/api/api.cc b/src/api/api.cc index a510fe68e..20946a0a7 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -10306,6 +10306,12 @@ bool Isolate::IsInUse() { return i_isolate->IsInUse(); } +void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { + i::Isolate* i_isolate = reinterpret_cast(this); + i::DisallowGarbageCollection no_gc; + i_isolate->global_handles()->IterateAllRootsWithClassIds(visitor); +} + void Isolate::SetAllowAtomicsWait(bool allow) { i::Isolate* i_isolate = reinterpret_cast(this); i_isolate->set_allow_atomics_wait(allow); diff --git a/src/handles/global-handles.cc b/src/handles/global-handles.cc index ca4fdd2db..6a1fe21ec 100644 --- a/src/handles/global-handles.cc +++ b/src/handles/global-handles.cc @@ -944,10 +944,10 @@ void GlobalHandles::ApplyPersistentHandleVisitor( node->wrapper_class_id()); } -void GlobalHandles::IterateAllRootsForTesting( +void GlobalHandles::IterateAllRootsWithClassIds( v8::PersistentHandleVisitor* visitor) { for (Node* node : *regular_nodes_) { - if (node->IsWeakOrStrongRetainer()) { + if (node->IsWeakOrStrongRetainer() && node->has_wrapper_class_id()) { ApplyPersistentHandleVisitor(visitor, node); } } diff --git a/src/handles/global-handles.h b/src/handles/global-handles.h index 3781d440e..234b3caca 100644 --- a/src/handles/global-handles.h +++ b/src/handles/global-handles.h @@ -125,7 +125,7 @@ class V8_EXPORT_PRIVATE GlobalHandles final { size_t handles_count() const; size_t last_gc_custom_callbacks() const { return last_gc_custom_callbacks_; } - void IterateAllRootsForTesting(v8::PersistentHandleVisitor* v); + void IterateAllRootsWithClassIds(v8::PersistentHandleVisitor* v); #ifdef DEBUG void PrintStats(); diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 2100dbc4d..bbbdef310 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -1615,7 +1615,7 @@ class EmbedderGraphBuilder : public v8::PersistentHandleVisitor { EmbedderGraphBuilder builder(isolate, graph); reinterpret_cast(isolate) ->global_handles() - ->IterateAllRootsForTesting(&builder); + ->IterateAllRootsWithClassIds(&builder); } void VisitPersistentHandle(v8::Persistent* value,