From 55be65da1597926416e5546d95ac723419e4c8ef Mon Sep 17 00:00:00 2001 From: Michael Lippautz Date: Fri, 11 Oct 2019 13:58:02 +0200 Subject: [PATCH] api: Rely on v8::Data base type for garbage collection support Use v8::Data as basetype for managed objects that can integrate with v8::EmbedderHeapTracer. Bug: v8:9841 Change-Id: Id3e06701207a23870cea89e1d7d334c48fcd3006 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1856002 Reviewed-by: Ulan Degenbaev Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#64283} --- include/v8.h | 9 +++++---- src/api/api.cc | 9 +++++++++ test/cctest/heap/test-embedder-tracing.cc | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/v8.h b/include/v8.h index 667a487915..1387f74715 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1275,9 +1275,8 @@ class V8_EXPORT SealHandleScope { // --- Special objects --- - /** - * The superclass of values and API object templates. + * The superclass of objects that can reside on V8's heap. */ class V8_EXPORT Data { private: @@ -1424,7 +1423,7 @@ class V8_EXPORT UnboundScript { /** * A compiled JavaScript module, not yet tied to a Context. */ -class V8_EXPORT UnboundModuleScript { +class V8_EXPORT UnboundModuleScript : public Data { // Only used as a container for code caching. }; @@ -1447,7 +1446,7 @@ class V8_EXPORT Location { /** * A compiled JavaScript module. */ -class V8_EXPORT Module { +class V8_EXPORT Module : public Data { public: /** * The different states a module can be in. @@ -7605,7 +7604,9 @@ class V8_EXPORT EmbedderHeapTracer { virtual void RegisterV8References( const std::vector >& embedder_fields) = 0; + V8_DEPRECATE_SOON("Use version taking TracedReferenceBase argument") void RegisterEmbedderReference(const TracedReferenceBase& ref); + void RegisterEmbedderReference(const TracedReferenceBase& ref); /** * Called at the beginning of a GC cycle. diff --git a/src/api/api.cc b/src/api/api.cc index 7088a26841..0d80f986f1 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -10557,6 +10557,15 @@ void EmbedderHeapTracer::DecreaseAllocatedSize(size_t bytes) { } } +void EmbedderHeapTracer::RegisterEmbedderReference( + const TracedReferenceBase& ref) { + if (ref.IsEmpty()) return; + + i::Heap* const heap = reinterpret_cast(isolate_)->heap(); + heap->RegisterExternallyReferencedObject( + reinterpret_cast(ref.val_)); +} + void EmbedderHeapTracer::RegisterEmbedderReference( const TracedReferenceBase& ref) { if (ref.IsEmpty()) return; diff --git a/test/cctest/heap/test-embedder-tracing.cc b/test/cctest/heap/test-embedder-tracing.cc index 11f154f936..8ff4acc05b 100644 --- a/test/cctest/heap/test-embedder-tracing.cc +++ b/test/cctest/heap/test-embedder-tracing.cc @@ -62,7 +62,7 @@ class TestEmbedderHeapTracer final : public v8::EmbedderHeapTracer { bool AdvanceTracing(double deadline_in_ms) final { for (auto global : to_register_with_v8_) { - RegisterEmbedderReference(global->As()); + RegisterEmbedderReference(global->As()); } to_register_with_v8_.clear(); return true;