[api, heap] Avoid deprecated usage of EmbedderHeapTracer

EmbedderRootsHandler is still supported.

Bug: v8:13207
Change-Id: I91107a2ed8c9603b77ae3e487f396c9ba32f3f95
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4111523
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84899}
This commit is contained in:
Michael Lippautz 2022-12-16 12:33:55 +01:00 committed by V8 LUCI CQ
parent b87fd354d1
commit cdc61b447c
2 changed files with 21 additions and 52 deletions

View File

@ -4,6 +4,7 @@
#include "src/heap/embedder-tracing.h"
#include "include/v8-embedder-heap.h"
#include "include/v8-function.h"
#include "include/v8-template.h"
#include "src/handles/global-handles.h"
@ -831,38 +832,20 @@ TEST_F(EmbedderTracingTest, BasicTracedReference) {
namespace {
START_ALLOW_USE_DEPRECATED()
class EmptyEmbedderHeapTracer : public v8::EmbedderHeapTracer {
public:
void RegisterV8References(
const std::vector<std::pair<void*, void*>>& embedder_fields) final {}
bool AdvanceTracing(double deadline_in_ms) final { return true; }
bool IsTracingDone() final { return true; }
void TracePrologue(EmbedderHeapTracer::TraceFlags) final {}
void TraceEpilogue(TraceSummary*) final {}
void EnterFinalPause(EmbedderStackState) final {}
};
END_ALLOW_USE_DEPRECATED()
// EmbedderHeapTracer that can optimize Scavenger handling when used with
// EmbedderRootsHandler that can optimize Scavenger handling when used with
// TracedReference.
class EmbedderHeapTracerNoDestructorNonTracingClearing final
: public EmptyEmbedderHeapTracer {
: public v8::EmbedderRootsHandler {
public:
explicit EmbedderHeapTracerNoDestructorNonTracingClearing(
uint16_t class_id_to_optimize)
: class_id_to_optimize_(class_id_to_optimize) {}
bool IsRootForNonTracingGC(
const v8::TracedReference<v8::Value>& handle) final {
bool IsRoot(const v8::TracedReference<v8::Value>& handle) final {
return handle.WrapperClassId() != class_id_to_optimize_;
}
void ResetHandleInNonTracingGC(
const v8::TracedReference<v8::Value>& handle) final {
void ResetRoot(const v8::TracedReference<v8::Value>& handle) final {
if (handle.WrapperClassId() != class_id_to_optimize_) return;
// Convention (for test): Objects that are optimized have their first field
@ -875,7 +858,7 @@ class EmbedderHeapTracerNoDestructorNonTracingClearing final
}
private:
uint16_t class_id_to_optimize_;
const uint16_t class_id_to_optimize_;
};
template <typename T>
@ -906,10 +889,11 @@ TEST_F(EmbedderTracingTest, TracedReferenceNoDestructorReclaimedOnScavenge) {
ManualGCScope manual_gc(i_isolate());
v8::HandleScope scope(v8_isolate());
constexpr uint16_t kClassIdToOptimize = 23;
EmbedderHeapTracerNoDestructorNonTracingClearing tracer(kClassIdToOptimize);
heap::TemporaryEmbedderHeapTracerScope tracer_scope(v8_isolate(), &tracer);
auto* traced_handles = i_isolate()->traced_handles();
EmbedderHeapTracerNoDestructorNonTracingClearing handler(kClassIdToOptimize);
v8_isolate()->SetEmbedderRootsHandler(&handler);
auto* traced_handles = i_isolate()->traced_handles();
const size_t initial_count = traced_handles->used_node_count();
auto* optimized_handle = new v8::TracedReference<v8::Value>();
auto* non_optimized_handle = new v8::TracedReference<v8::Value>();
@ -924,6 +908,8 @@ TEST_F(EmbedderTracingTest, TracedReferenceNoDestructorReclaimedOnScavenge) {
non_optimized_handle->Reset();
delete non_optimized_handle;
EXPECT_EQ(initial_count, traced_handles->used_node_count());
v8_isolate()->SetEmbedderRootsHandler(nullptr);
}
namespace {

View File

@ -27,6 +27,7 @@
#include "src/handles/global-handles.h"
#include "include/v8-embedder-heap.h"
#include "include/v8-function.h"
#include "src/api/api-inl.h"
#include "src/execution/isolate.h"
@ -47,29 +48,13 @@ struct TracedReferenceWrapper {
v8::TracedReference<v8::Object> handle;
};
START_ALLOW_USE_DEPRECATED()
// Empty v8::EmbedderHeapTracer that never keeps objects alive on Scavenge. See
// |IsRootForNonTracingGC|.
class NonRootingEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
class NonRootingEmbedderRootsHandler final : public v8::EmbedderRootsHandler {
public:
NonRootingEmbedderHeapTracer() = default;
void RegisterV8References(
const std::vector<std::pair<void*, void*>>& embedder_fields) final {}
bool AdvanceTracing(double deadline_in_ms) final { return true; }
bool IsTracingDone() final { return true; }
void TracePrologue(TraceFlags) final {}
void TraceEpilogue(TraceSummary*) final {}
void EnterFinalPause(EmbedderStackState) final {}
bool IsRootForNonTracingGC(
const v8::TracedReference<v8::Value>& handle) final {
bool IsRoot(const v8::TracedReference<v8::Value>& handle) final {
return false;
}
void ResetHandleInNonTracingGC(
const v8::TracedReference<v8::Value>& handle) final {
void ResetRoot(const v8::TracedReference<v8::Value>& handle) final {
for (auto* wrapper : wrappers_) {
if (wrapper->handle == handle) {
wrapper->handle.Reset();
@ -85,8 +70,6 @@ class NonRootingEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
std::vector<TracedReferenceWrapper*> wrappers_;
};
END_ALLOW_USE_DEPRECATED()
void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Number::New(isolate, 0));
@ -184,11 +167,11 @@ class GlobalHandlesTest : public TestWithContext {
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
NonRootingEmbedderHeapTracer tracer;
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
NonRootingEmbedderRootsHandler roots_handler;
v8_isolate()->SetEmbedderRootsHandler(&roots_handler);
auto fp = std::make_unique<TracedReferenceWrapper>();
tracer.Register(fp.get());
roots_handler.Register(fp.get());
construct_function(isolate, context, fp.get());
CHECK(IsNewObjectInCorrectGeneration(isolate, fp->handle));
modifier_function(fp.get());
@ -197,6 +180,8 @@ class GlobalHandlesTest : public TestWithContext {
// handle directly here.
CHECK_IMPLIES(survives == SurvivalMode::kSurvives, !fp->handle.IsEmpty());
CHECK_IMPLIES(survives == SurvivalMode::kDies, fp->handle.IsEmpty());
v8_isolate()->SetEmbedderRootsHandler(nullptr);
}
};
@ -295,8 +280,6 @@ TEST_F(GlobalHandlesTest, WeakPersistentSmi) {
v8::WeakCallbackType::kParameter);
}
START_ALLOW_USE_DEPRECATED()
TEST_F(GlobalHandlesTest, PhantomHandlesWithoutCallbacks) {
v8::Isolate* isolate = v8_isolate();
DisableConservativeStackScanningScopeForTesting no_stack_scanning(