diff --git a/include/v8.h b/include/v8.h index 851065b922..3f9f8d8f44 100644 --- a/include/v8.h +++ b/include/v8.h @@ -7685,6 +7685,11 @@ class V8_EXPORT Isolate { */ void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); + /* + * Gets the currently active heap tracer for the isolate. + */ + EmbedderHeapTracer* GetEmbedderHeapTracer(); + /** * Use for |AtomicsWaitCallback| to indicate the type of event it receives. */ diff --git a/src/api.cc b/src/api.cc index f338cdb569..abf4a1b950 100644 --- a/src/api.cc +++ b/src/api.cc @@ -8094,6 +8094,11 @@ void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) { isolate->heap()->SetEmbedderHeapTracer(tracer); } +EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() { + i::Isolate* isolate = reinterpret_cast(this); + return isolate->heap()->GetEmbedderHeapTracer(); +} + void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback( GetExternallyAllocatedMemoryInBytesCallback callback) { i::Isolate* isolate = reinterpret_cast(this); diff --git a/src/heap/embedder-tracing.h b/src/heap/embedder-tracing.h index 8597c6baf5..2588200db9 100644 --- a/src/heap/embedder-tracing.h +++ b/src/heap/embedder-tracing.h @@ -24,6 +24,8 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final { if (remote_tracer_) remote_tracer_->isolate_ = nullptr; } + EmbedderHeapTracer* remote_tracer() const { return remote_tracer_; } + void SetRemoteTracer(EmbedderHeapTracer* tracer) { if (remote_tracer_) remote_tracer_->isolate_ = nullptr; diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 646504f637..c302f9b5b0 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -4665,6 +4665,10 @@ void Heap::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) { local_embedder_heap_tracer()->SetRemoteTracer(tracer); } +EmbedderHeapTracer* Heap::GetEmbedderHeapTracer() const { + return local_embedder_heap_tracer()->remote_tracer(); +} + void Heap::TracePossibleWrapper(JSObject* js_object) { DCHECK(js_object->IsApiWrapper()); if (js_object->GetEmbedderFieldCount() >= 2 && diff --git a/src/heap/heap.h b/src/heap/heap.h index d1eac4385d..49763a5601 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -1038,10 +1038,13 @@ class Heap { // Embedder heap tracer support. ============================================= // =========================================================================== - LocalEmbedderHeapTracer* local_embedder_heap_tracer() { + LocalEmbedderHeapTracer* local_embedder_heap_tracer() const { return local_embedder_heap_tracer_; } + void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); + EmbedderHeapTracer* GetEmbedderHeapTracer() const; + void TracePossibleWrapper(JSObject* js_object); void RegisterExternallyReferencedObject(Object** object); void SetEmbedderStackStateForNextFinalizaton(