Commit 8e01d664 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap/api: EmbedderHeapTracer: Pass along memory reducing mode

Change-Id: I55e8e42b88c8df1f75ff05f22b39d69e9dc586ce
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1588457
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61097}
parent 9d7b0f1c
......@@ -7171,6 +7171,11 @@ enum class MemoryPressureLevel { kNone, kModerate, kCritical };
*/
class V8_EXPORT EmbedderHeapTracer {
public:
enum class TraceFlags : uint64_t {
kNoFlags = 0,
kReduceMemory = 1 << 0,
};
// Indicator for the stack state of the embedder.
enum EmbedderStackState {
kUnknown,
......@@ -7209,7 +7214,8 @@ class V8_EXPORT EmbedderHeapTracer {
/**
* Called at the beginning of a GC cycle.
*/
virtual void TracePrologue() = 0;
V8_DEPRECATE_SOON("Use version with flags.", virtual void TracePrologue()) {}
virtual void TracePrologue(TraceFlags flags);
/**
* Called to advance tracing in the embedder.
......@@ -7283,6 +7289,18 @@ class V8_EXPORT EmbedderHeapTracer {
friend class internal::LocalEmbedderHeapTracer;
};
constexpr EmbedderHeapTracer::TraceFlags operator&(
EmbedderHeapTracer::TraceFlags lhs, EmbedderHeapTracer::TraceFlags rhs) {
return static_cast<EmbedderHeapTracer::TraceFlags>(
static_cast<uint64_t>(lhs) & static_cast<uint64_t>(rhs));
}
constexpr EmbedderHeapTracer::TraceFlags operator|(
EmbedderHeapTracer::TraceFlags lhs, EmbedderHeapTracer::TraceFlags rhs) {
return static_cast<EmbedderHeapTracer::TraceFlags>(
static_cast<uint64_t>(lhs) | static_cast<uint64_t>(rhs));
}
/**
* Callback and supporting data used in SnapshotCreator to implement embedder
* logic to serialize internal fields.
......
......@@ -10502,6 +10502,17 @@ void Testing::DeoptimizeAll(Isolate* isolate) {
i::Deoptimizer::DeoptimizeAll(i_isolate);
}
void EmbedderHeapTracer::TracePrologue(TraceFlags flags) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
TracePrologue();
#if __clang__
#pragma clang diagnostic pop
#endif
}
void EmbedderHeapTracer::FinalizeTracing() {
if (isolate_) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
......
......@@ -19,12 +19,13 @@ void LocalEmbedderHeapTracer::SetRemoteTracer(EmbedderHeapTracer* tracer) {
remote_tracer_->isolate_ = reinterpret_cast<v8::Isolate*>(isolate_);
}
void LocalEmbedderHeapTracer::TracePrologue() {
void LocalEmbedderHeapTracer::TracePrologue(
EmbedderHeapTracer::TraceFlags flags) {
if (!InUse()) return;
num_v8_marking_worklist_was_empty_ = 0;
embedder_worklist_empty_ = false;
remote_tracer_->TracePrologue();
remote_tracer_->TracePrologue(flags);
}
void LocalEmbedderHeapTracer::TraceEpilogue() {
......
......@@ -48,7 +48,7 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
EmbedderHeapTracer* remote_tracer() const { return remote_tracer_; }
void SetRemoteTracer(EmbedderHeapTracer* tracer);
void TracePrologue();
void TracePrologue(EmbedderHeapTracer::TraceFlags flags);
void TraceEpilogue();
void EnterFinalPause();
bool Trace(double deadline);
......
......@@ -4813,6 +4813,12 @@ EmbedderHeapTracer* Heap::GetEmbedderHeapTracer() const {
return local_embedder_heap_tracer()->remote_tracer();
}
EmbedderHeapTracer::TraceFlags Heap::flags_for_embedder_tracer() const {
if (ShouldReduceMemory())
return EmbedderHeapTracer::TraceFlags::kReduceMemory;
return EmbedderHeapTracer::TraceFlags::kNoFlags;
}
void Heap::RegisterExternallyReferencedObject(Address* location) {
// The embedder is not aware of whether numbers are materialized as heap
// objects are just passed around as Smis.
......
......@@ -936,6 +936,8 @@ class Heap {
void SetEmbedderStackStateForNextFinalizaton(
EmbedderHeapTracer::EmbedderStackState stack_state);
EmbedderHeapTracer::TraceFlags flags_for_embedder_tracer() const;
// ===========================================================================
// External string table API. ================================================
// ===========================================================================
......
......@@ -385,7 +385,8 @@ void IncrementalMarking::StartMarking() {
// marking (including write barriers) is fully set up.
TRACE_GC(heap()->tracer(),
GCTracer::Scope::MC_INCREMENTAL_EMBEDDER_PROLOGUE);
heap_->local_embedder_heap_tracer()->TracePrologue();
heap_->local_embedder_heap_tracer()->TracePrologue(
heap_->flags_for_embedder_tracer());
}
}
......
......@@ -796,7 +796,8 @@ void MarkCompactCollector::Prepare() {
if (!was_marked_incrementally_) {
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_EMBEDDER_PROLOGUE);
heap_->local_embedder_heap_tracer()->TracePrologue();
heap_->local_embedder_heap_tracer()->TracePrologue(
heap_->flags_for_embedder_tracer());
}
// Don't start compaction if we are in the middle of incremental
......
......@@ -69,7 +69,7 @@ class TestEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
bool IsTracingDone() final { return to_register_with_v8_.empty(); }
void TracePrologue() final {
void TracePrologue(EmbedderHeapTracer::TraceFlags) final {
if (prologue_behavior_ == TracePrologueBehavior::kCallV8WriteBarrier) {
auto local = array_.Get(isolate());
local->Set(local->CreationContext(), 0, v8::Object::New(isolate()))
......
......@@ -31,7 +31,7 @@ LocalEmbedderHeapTracer::WrapperInfo CreateWrapperInfo() {
class MockEmbedderHeapTracer : public EmbedderHeapTracer {
public:
MOCK_METHOD0(TracePrologue, void());
MOCK_METHOD1(TracePrologue, void(EmbedderHeapTracer::TraceFlags));
MOCK_METHOD0(TraceEpilogue, void());
MOCK_METHOD1(EnterFinalPause, void(EmbedderHeapTracer::EmbedderStackState));
MOCK_METHOD0(IsTracingDone, bool());
......@@ -52,7 +52,7 @@ TEST(LocalEmbedderHeapTracer, NoRemoteTracer) {
// We should be able to call all functions without a remote tracer being
// attached.
EXPECT_FALSE(local_tracer.InUse());
local_tracer.TracePrologue();
local_tracer.TracePrologue(EmbedderHeapTracer::TraceFlags::kNoFlags);
local_tracer.EnterFinalPause();
bool done = local_tracer.Trace(std::numeric_limits<double>::infinity());
EXPECT_TRUE(done);
......@@ -63,8 +63,17 @@ TEST(LocalEmbedderHeapTracer, TracePrologueForwards) {
StrictMock<MockEmbedderHeapTracer> remote_tracer;
LocalEmbedderHeapTracer local_tracer(nullptr);
local_tracer.SetRemoteTracer(&remote_tracer);
EXPECT_CALL(remote_tracer, TracePrologue());
local_tracer.TracePrologue();
EXPECT_CALL(remote_tracer, TracePrologue(_));
local_tracer.TracePrologue(EmbedderHeapTracer::TraceFlags::kNoFlags);
}
TEST(LocalEmbedderHeapTracer, TracePrologueForwardsMemoryReducingFlag) {
StrictMock<MockEmbedderHeapTracer> remote_tracer;
LocalEmbedderHeapTracer local_tracer(nullptr);
local_tracer.SetRemoteTracer(&remote_tracer);
EXPECT_CALL(remote_tracer,
TracePrologue(EmbedderHeapTracer::TraceFlags::kReduceMemory));
local_tracer.TracePrologue(EmbedderHeapTracer::TraceFlags::kReduceMemory);
}
TEST(LocalEmbedderHeapTracer, TraceEpilogueForwards) {
......
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