Commit bf5e3a8a authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

[api, heap] Deprecate v8::EmbedderHeapTracer

Users should rely on CppHeap which is the only supported way of using
v8::TracedReference in going forward.

Bug: v8:13207
Change-Id: Idd03f458167c74b06f285bb568e5c77ad46003fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3849037Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82681}
parent 0cbfcede
......@@ -5,7 +5,6 @@
#ifndef INCLUDE_CPPGC_COMMON_H_
#define INCLUDE_CPPGC_COMMON_H_
// TODO(chromium:1056170): Remove dependency on v8.
#include "v8config.h" // NOLINT(build/include_directory)
namespace cppgc {
......
......@@ -69,7 +69,12 @@ class V8_EXPORT EmbedderRootsHandler {
* trace through its heap and use reporter to report each JavaScript object
* reachable from any of the given wrappers.
*/
class V8_EXPORT EmbedderHeapTracer {
class V8_EXPORT
// GCC doesn't like combining __attribute__(()) with [[deprecated]].
#ifdef __clang__
V8_DEPRECATE_SOON("Use CppHeap when working with v8::TracedReference.")
#endif // __clang__
EmbedderHeapTracer {
public:
using EmbedderStackState = cppgc::EmbedderStackState;
......
......@@ -194,6 +194,11 @@ enum RAILMode : unsigned {
*/
enum class MemoryPressureLevel { kNone, kModerate, kCritical };
/**
* Indicator for the stack state.
*/
using StackState = cppgc::EmbedderStackState;
/**
* Isolate represents an isolated instance of the V8 engine. V8 isolates have
* completely separate states. Objects from one isolate must not be used in
......@@ -922,6 +927,7 @@ class V8_EXPORT Isolate {
void RemoveGCPrologueCallback(GCCallbackWithData, void* data = nullptr);
void RemoveGCPrologueCallback(GCCallback callback);
START_ALLOW_USE_DEPRECATED()
/**
* Sets the embedder heap tracer for the isolate.
* SetEmbedderHeapTracer cannot be used simultaneously with AttachCppHeap.
......@@ -933,6 +939,7 @@ class V8_EXPORT Isolate {
* SetEmbedderHeapTracer.
*/
EmbedderHeapTracer* GetEmbedderHeapTracer();
END_ALLOW_USE_DEPRECATED()
/**
* Sets an embedder roots handle that V8 should consider when performing
......@@ -1158,9 +1165,8 @@ class V8_EXPORT Isolate {
* LowMemoryNotification() instead to influence the garbage collection
* schedule.
*/
void RequestGarbageCollectionForTesting(
GarbageCollectionType type,
EmbedderHeapTracer::EmbedderStackState stack_state);
void RequestGarbageCollectionForTesting(GarbageCollectionType type,
StackState stack_state);
/**
* Set the callback to invoke for logging event.
......
......@@ -8518,6 +8518,8 @@ void Isolate::RemoveGCEpilogueCallback(GCCallback callback) {
RemoveGCEpilogueCallback(CallGCCallbackWithoutData, data);
}
START_ALLOW_USE_DEPRECATED()
void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
CHECK_NULL(i_isolate->heap()->cpp_heap());
......@@ -8529,6 +8531,8 @@ EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() {
return i_isolate->heap()->GetEmbedderHeapTracer();
}
END_ALLOW_USE_DEPRECATED()
void Isolate::SetEmbedderRootsHandler(EmbedderRootsHandler* handler) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
i_isolate->heap()->SetEmbedderRootsHandler(handler);
......@@ -8602,9 +8606,8 @@ void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
}
}
void Isolate::RequestGarbageCollectionForTesting(
GarbageCollectionType type,
EmbedderHeapTracer::EmbedderStackState stack_state) {
void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type,
StackState stack_state) {
base::Optional<i::EmbedderStackStateScope> stack_scope;
if (type == kFullGarbageCollection) {
stack_scope.emplace(reinterpret_cast<i::Isolate*>(this)->heap(),
......
......@@ -756,9 +756,7 @@ void RemoveBreakpoint(Isolate* v8_isolate, BreakpointId id) {
Platform* GetCurrentPlatform() { return i::V8::GetCurrentPlatform(); }
void ForceGarbageCollection(
Isolate* isolate,
EmbedderHeapTracer::EmbedderStackState embedder_stack_state) {
void ForceGarbageCollection(Isolate* isolate, StackState embedder_stack_state) {
i::EmbedderStackStateScope stack_scope(
reinterpret_cast<i::Isolate*>(isolate)->heap(),
i::EmbedderStackStateScope::kImplicitThroughTask, embedder_stack_state);
......
......@@ -11,6 +11,7 @@
#include "include/v8-date.h"
#include "include/v8-debug.h"
#include "include/v8-embedder-heap.h"
#include "include/v8-isolate.h"
#include "include/v8-local-handle.h"
#include "include/v8-memory-span.h"
#include "include/v8-promise.h"
......@@ -610,9 +611,8 @@ bool SetFunctionBreakpoint(v8::Local<v8::Function> function,
v8::Platform* GetCurrentPlatform();
void ForceGarbageCollection(
v8::Isolate* isolate,
v8::EmbedderHeapTracer::EmbedderStackState embedder_stack_state);
void ForceGarbageCollection(v8::Isolate* isolate,
v8::StackState embedder_stack_state);
class V8_NODISCARD PostponeInterruptsScope {
public:
......
......@@ -93,9 +93,8 @@ void InvokeGC(v8::Isolate* isolate, ExecutionType execution_type,
? EmbedderStackStateScope::kImplicitThroughTask
: EmbedderStackStateScope::kExplicitInvocation,
execution_type == ExecutionType::kAsync
? v8::EmbedderHeapTracer::EmbedderStackState::kNoHeapPointers
: v8::EmbedderHeapTracer::EmbedderStackState::
kMayContainHeapPointers);
? StackState::kNoHeapPointers
: StackState::kMayContainHeapPointers);
heap->PreciseCollectAllGarbage(i::Heap::kNoGCFlags,
i::GarbageCollectionReason::kTesting,
kGCCallbackFlagForced);
......
......@@ -1319,6 +1319,8 @@ GlobalHandles::NodeBounds GlobalHandles::GetTracedNodeBounds() const {
return traced_nodes_->GetNodeBlockBounds();
}
START_ALLOW_USE_DEPRECATED()
DISABLE_CFI_PERF void GlobalHandles::IterateTracedNodes(
v8::EmbedderHeapTracer::TracedGlobalHandleVisitor* visitor) {
for (TracedNode* node : *traced_nodes_) {
......@@ -1330,6 +1332,8 @@ DISABLE_CFI_PERF void GlobalHandles::IterateTracedNodes(
}
}
END_ALLOW_USE_DEPRECATED()
void GlobalHandles::RecordStats(HeapStats* stats) {
*stats->global_handle_count = 0;
*stats->weak_global_handle_count = 0;
......
......@@ -113,10 +113,14 @@ class V8_EXPORT_PRIVATE GlobalHandles final {
void IterateAllRoots(RootVisitor* v);
void IterateAllYoungRoots(RootVisitor* v);
START_ALLOW_USE_DEPRECATED()
// Iterates over all traces handles represented by `v8::TracedReferenceBase`.
void IterateTracedNodes(
v8::EmbedderHeapTracer::TracedGlobalHandleVisitor* visitor);
END_ALLOW_USE_DEPRECATED()
// Marks handles that are phantom or have callbacks based on the predicate
// |should_reset_handle| as pending.
void IterateWeakRootsForPhantomHandles(
......
......@@ -56,6 +56,8 @@ namespace v8 {
namespace {
START_ALLOW_USE_DEPRECATED()
class V8ToCppGCReferencesVisitor final
: public v8::EmbedderHeapTracer::TracedGlobalHandleVisitor {
public:
......@@ -96,6 +98,8 @@ class V8ToCppGCReferencesVisitor final
const v8::WrapperDescriptor& wrapper_descriptor_;
};
END_ALLOW_USE_DEPRECATED()
void TraceV8ToCppGCReferences(
v8::internal::Isolate* isolate,
cppgc::internal::MutatorMarkingState& marking_state,
......
......@@ -11,8 +11,9 @@
#include "src/heap/gc-tracer.h"
#include "src/heap/marking-worklist-inl.h"
namespace v8 {
namespace internal {
namespace v8::internal {
START_ALLOW_USE_DEPRECATED()
void LocalEmbedderHeapTracer::SetRemoteTracer(EmbedderHeapTracer* tracer) {
CHECK_NULL(cpp_heap_);
......@@ -208,5 +209,6 @@ void DefaultEmbedderRootsHandler::ResetRoot(
tracer_->ResetHandleInNonTracingGC(handle);
}
} // namespace internal
} // namespace v8
END_ALLOW_USE_DEPRECATED()
} // namespace v8::internal
......@@ -21,6 +21,8 @@ namespace internal {
class Heap;
class JSObject;
START_ALLOW_USE_DEPRECATED()
class V8_EXPORT_PRIVATE DefaultEmbedderRootsHandler final
: public EmbedderRootsHandler {
public:
......@@ -220,6 +222,8 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
friend class EmbedderStackStateScope;
};
END_ALLOW_USE_DEPRECATED()
} // namespace internal
} // namespace v8
......
......@@ -1782,7 +1782,7 @@ bool Heap::CollectGarbage(AllocationSpace space,
// their own state on the stack and recursively trigger GC.
EmbedderStackStateScope embedder_scope(
this, EmbedderStackStateScope::kExplicitInvocation,
EmbedderHeapTracer::EmbedderStackState::kMayContainHeapPointers);
StackState::kMayContainHeapPointers);
if (scope.CheckReenter()) {
AllowGarbageCollection allow_gc;
AllowJavascriptExecution allow_js(isolate());
......@@ -5957,6 +5957,8 @@ void Heap::NotifyOldGenerationExpansion(AllocationSpace space,
}
}
START_ALLOW_USE_DEPRECATED()
void Heap::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
DCHECK_EQ(gc_state(), HeapState::NOT_IN_GC);
// Setting a tracer is only supported when CppHeap is not used.
......@@ -5964,6 +5966,21 @@ void Heap::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
local_embedder_heap_tracer()->SetRemoteTracer(tracer);
}
EmbedderHeapTracer* Heap::GetEmbedderHeapTracer() const {
return local_embedder_heap_tracer()->remote_tracer();
}
EmbedderHeapTracer::TraceFlags Heap::flags_for_embedder_tracer() const {
if (is_current_gc_forced()) {
return EmbedderHeapTracer::TraceFlags::kForced;
} else if (ShouldReduceMemory()) {
return EmbedderHeapTracer::TraceFlags::kReduceMemory;
}
return EmbedderHeapTracer::TraceFlags::kNoFlags;
}
END_ALLOW_USE_DEPRECATED()
void Heap::SetEmbedderRootsHandler(EmbedderRootsHandler* handler) {
embedder_roots_handler_ = handler;
}
......@@ -5972,10 +5989,6 @@ EmbedderRootsHandler* Heap::GetEmbedderRootsHandler() const {
return embedder_roots_handler_;
}
EmbedderHeapTracer* Heap::GetEmbedderHeapTracer() const {
return local_embedder_heap_tracer()->remote_tracer();
}
void Heap::AttachCppHeap(v8::CppHeap* cpp_heap) {
CppHeap::From(cpp_heap)->AttachIsolate(isolate());
cpp_heap_ = cpp_heap;
......@@ -5988,15 +6001,6 @@ void Heap::DetachCppHeap() {
local_embedder_heap_tracer()->SetCppHeap(nullptr);
}
EmbedderHeapTracer::TraceFlags Heap::flags_for_embedder_tracer() const {
if (is_current_gc_forced()) {
return EmbedderHeapTracer::TraceFlags::kForced;
} else if (ShouldReduceMemory()) {
return EmbedderHeapTracer::TraceFlags::kReduceMemory;
}
return EmbedderHeapTracer::TraceFlags::kNoFlags;
}
const cppgc::EmbedderStackState* Heap::overriden_stack_state() const {
const auto* cpp_heap = CppHeap::From(cpp_heap_);
return cpp_heap ? cpp_heap->override_stack_state() : nullptr;
......@@ -7542,9 +7546,8 @@ void Heap::set_allocation_timeout(int allocation_timeout) {
}
#endif // V8_ENABLE_ALLOCATION_TIMEOUT
EmbedderStackStateScope::EmbedderStackStateScope(
Heap* heap, Origin origin,
EmbedderHeapTracer::EmbedderStackState stack_state)
EmbedderStackStateScope::EmbedderStackStateScope(Heap* heap, Origin origin,
StackState stack_state)
: local_tracer_(heap->local_embedder_heap_tracer()),
old_stack_state_(local_tracer_->embedder_stack_state_) {
if (origin == kImplicitThroughTask && heap->overriden_stack_state()) {
......@@ -7556,14 +7559,12 @@ EmbedderStackStateScope::EmbedderStackStateScope(
// static
EmbedderStackStateScope EmbedderStackStateScope::ExplicitScopeForTesting(
LocalEmbedderHeapTracer* local_tracer,
EmbedderHeapTracer::EmbedderStackState stack_state) {
LocalEmbedderHeapTracer* local_tracer, StackState stack_state) {
return EmbedderStackStateScope(local_tracer, stack_state);
}
EmbedderStackStateScope::EmbedderStackStateScope(
LocalEmbedderHeapTracer* local_tracer,
EmbedderHeapTracer::EmbedderStackState stack_state)
LocalEmbedderHeapTracer* local_tracer, StackState stack_state)
: local_tracer_(local_tracer),
old_stack_state_(local_tracer_->embedder_stack_state_) {
local_tracer_->embedder_stack_state_ = stack_state;
......
......@@ -1185,12 +1185,15 @@ class Heap {
return local_embedder_heap_tracer_.get();
}
START_ALLOW_USE_DEPRECATED()
V8_EXPORT_PRIVATE void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer);
EmbedderHeapTracer* GetEmbedderHeapTracer() const;
EmbedderHeapTracer::TraceFlags flags_for_embedder_tracer() const;
void RegisterExternallyReferencedObject(Address* location);
END_ALLOW_USE_DEPRECATED()
EmbedderHeapTracer::TraceFlags flags_for_embedder_tracer() const;
void RegisterExternallyReferencedObject(Address* location);
// ===========================================================================
// Unified heap (C++) support. ===============================================
......@@ -2879,19 +2882,17 @@ class V8_EXPORT_PRIVATE V8_NODISCARD EmbedderStackStateScope final {
// Only used for testing where the Origin is always an explicit invocation.
static EmbedderStackStateScope ExplicitScopeForTesting(
LocalEmbedderHeapTracer* local_tracer,
EmbedderHeapTracer::EmbedderStackState stack_state);
LocalEmbedderHeapTracer* local_tracer, StackState stack_state);
EmbedderStackStateScope(Heap* heap, Origin origin,
EmbedderHeapTracer::EmbedderStackState stack_state);
EmbedderStackStateScope(Heap* heap, Origin origin, StackState stack_state);
~EmbedderStackStateScope();
private:
EmbedderStackStateScope(LocalEmbedderHeapTracer* local_tracer,
EmbedderHeapTracer::EmbedderStackState stack_state);
StackState stack_state);
LocalEmbedderHeapTracer* const local_tracer_;
const EmbedderHeapTracer::EmbedderStackState old_stack_state_;
const StackState old_stack_state_;
};
class V8_NODISCARD CppClassNamesAsHeapObjectNameScope final {
......
......@@ -20,8 +20,7 @@ namespace internal {
class IncrementalMarkingJob::Task : public CancelableTask {
public:
Task(Isolate* isolate, IncrementalMarkingJob* job,
EmbedderHeapTracer::EmbedderStackState stack_state)
Task(Isolate* isolate, IncrementalMarkingJob* job, StackState stack_state)
: CancelableTask(isolate),
isolate_(isolate),
job_(job),
......@@ -35,7 +34,7 @@ class IncrementalMarkingJob::Task : public CancelableTask {
private:
Isolate* const isolate_;
IncrementalMarkingJob* const job_;
const EmbedderHeapTracer::EmbedderStackState stack_state_;
const StackState stack_state_;
};
void IncrementalMarkingJob::ScheduleTask() {
......@@ -50,10 +49,9 @@ void IncrementalMarkingJob::ScheduleTask() {
is_task_pending_ = true;
auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate);
const EmbedderHeapTracer::EmbedderStackState stack_state =
taskrunner->NonNestableTasksEnabled()
? EmbedderHeapTracer::EmbedderStackState::kNoHeapPointers
: EmbedderHeapTracer::EmbedderStackState::kMayContainHeapPointers;
const auto stack_state = taskrunner->NonNestableTasksEnabled()
? StackState::kNoHeapPointers
: StackState::kMayContainHeapPointers;
auto task = std::make_unique<Task>(heap_->isolate(), this, stack_state);
......
......@@ -166,8 +166,8 @@ class V8HeapProfilerAgentImpl::GCTask : public v8::Task {
if (!async_gc) return;
v8::base::MutexGuard lock(&async_gc->m_mutex);
if (async_gc->m_canceled) return;
v8::debug::ForceGarbageCollection(
m_isolate, v8::EmbedderHeapTracer::EmbedderStackState::kNoHeapPointers);
v8::debug::ForceGarbageCollection(m_isolate,
v8::StackState::kNoHeapPointers);
for (auto& callback : async_gc->m_pending_callbacks) {
callback->sendSuccess();
}
......
......@@ -12,6 +12,8 @@ namespace v8 {
namespace internal {
namespace heap {
START_ALLOW_USE_DEPRECATED()
class V8_NODISCARD TemporaryEmbedderHeapTracerScope {
public:
TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
......@@ -28,6 +30,8 @@ class V8_NODISCARD TemporaryEmbedderHeapTracerScope {
v8::Isolate* const isolate_;
};
END_ALLOW_USE_DEPRECATED()
void SealCurrentObjects(Heap* heap);
int FixedArrayLenFromSize(int size);
......
......@@ -45,6 +45,8 @@ 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 {
......@@ -81,6 +83,8 @@ class NonRootingEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
std::vector<TracedReferenceWrapper*> wrappers_;
};
END_ALLOW_USE_DEPRECATED()
void InvokeScavenge() { CcTest::CollectGarbage(i::NEW_SPACE); }
void InvokeMarkSweep() { CcTest::CollectAllGarbage(); }
......
......@@ -168,7 +168,7 @@ TEST_F(UnifiedHeapDetachedTest, AllocationBeforeConfigureHeap) {
{
EmbedderStackStateScope stack_scope(
&js_heap, EmbedderStackStateScope::kExplicitInvocation,
EmbedderHeapTracer::EmbedderStackState::kNoHeapPointers);
StackState::kNoHeapPointers);
CollectGarbage(OLD_SPACE);
cpp_heap.AsBase().sweeper().FinishIfRunning();
EXPECT_FALSE(weak_holder);
......
......@@ -31,7 +31,7 @@ void UnifiedHeapTest::CollectGarbageWithEmbedderStack(
cppgc::Heap::SweepingType sweeping_type) {
EmbedderStackStateScope stack_scope(
heap(), EmbedderStackStateScope::kExplicitInvocation,
EmbedderHeapTracer::EmbedderStackState::kMayContainHeapPointers);
StackState::kMayContainHeapPointers);
CollectGarbage(OLD_SPACE);
if (sweeping_type == cppgc::Heap::SweepingType::kAtomic) {
cpp_heap().AsBase().sweeper().FinishIfRunning();
......@@ -42,7 +42,7 @@ void UnifiedHeapTest::CollectGarbageWithoutEmbedderStack(
cppgc::Heap::SweepingType sweeping_type) {
EmbedderStackStateScope stack_scope(
heap(), EmbedderStackStateScope::kExplicitInvocation,
EmbedderHeapTracer::EmbedderStackState::kNoHeapPointers);
StackState::kNoHeapPointers);
CollectGarbage(OLD_SPACE);
if (sweeping_type == cppgc::Heap::SweepingType::kAtomic) {
cpp_heap().AsBase().sweeper().FinishIfRunning();
......
......@@ -35,6 +35,7 @@ LocalEmbedderHeapTracer::WrapperInfo CreateWrapperInfo() {
} // namespace
START_ALLOW_USE_DEPRECATED()
class MockEmbedderHeapTracer : public EmbedderHeapTracer {
public:
MOCK_METHOD(void, TracePrologue, (EmbedderHeapTracer::TraceFlags),
......@@ -49,6 +50,8 @@ class MockEmbedderHeapTracer : public EmbedderHeapTracer {
MOCK_METHOD(bool, AdvanceTracing, (double deadline_in_ms), (override));
};
END_ALLOW_USE_DEPRECATED()
TEST(LocalEmbedderHeapTracer, InUse) {
MockEmbedderHeapTracer mock_remote_tracer;
LocalEmbedderHeapTracer local_tracer(nullptr);
......@@ -264,6 +267,8 @@ v8::Local<v8::Object> ConstructTraceableJSApiObject(
enum class TracePrologueBehavior { kNoop, kCallV8WriteBarrier };
START_ALLOW_USE_DEPRECATED()
class TestEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
public:
TestEmbedderHeapTracer() = default;
......@@ -354,6 +359,8 @@ class V8_NODISCARD TemporaryEmbedderHeapTracerScope final {
v8::Isolate* const isolate_;
};
END_ALLOW_USE_DEPRECATED()
} // namespace
using EmbedderTracingTest = TestWithHeapInternalsAndContext;
......@@ -726,6 +733,8 @@ TEST_F(EmbedderTracingTest, TracedReferenceHandlesDoNotLeak) {
namespace {
START_ALLOW_USE_DEPRECATED()
class TracedReferenceVisitor final
: public v8::EmbedderHeapTracer::TracedGlobalHandleVisitor {
public:
......@@ -743,6 +752,8 @@ class TracedReferenceVisitor final
size_t count_ = 0;
};
END_ALLOW_USE_DEPRECATED()
} // namespace
TEST_F(EmbedderTracingTest, TracedReferenceIteration) {
......@@ -824,6 +835,8 @@ TEST_F(EmbedderTracingTest, BasicTracedReference) {
namespace {
START_ALLOW_USE_DEPRECATED()
class EmptyEmbedderHeapTracer : public v8::EmbedderHeapTracer {
public:
void RegisterV8References(
......@@ -836,6 +849,8 @@ class EmptyEmbedderHeapTracer : public v8::EmbedderHeapTracer {
void EnterFinalPause(EmbedderStackState) final {}
};
END_ALLOW_USE_DEPRECATED()
// EmbedderHeapTracer that can optimize Scavenger handling when used with
// TracedReference.
class EmbedderHeapTracerNoDestructorNonTracingClearing final
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment