Commit 5622bc15 authored by mlippautz's avatar mlippautz Committed by Commit bot

Reland of "[heap] Report wrappers after processing the marking deque incrementally"

We need to report cached wrappers within v8 to the embedder after each atomic
phase of v8 marking because the embedder can invalidate the wrappers in-between
v8 marking steps.

E.g., in Chrome, a conservative GC might need to wipe dead wrappables from
the wrapper tracing marking deque.

BUG=chromium:676700, chromium:468240

Review-Url: https://codereview.chromium.org/2610563002
Cr-Commit-Position: refs/heads/master@{#42011}
parent 45aa1351
......@@ -41,7 +41,7 @@ bool LocalEmbedderHeapTracer::Trace(
double deadline, EmbedderHeapTracer::AdvanceTracingActions actions) {
if (!InUse()) return false;
RegisterWrappersWithRemoteTracer();
DCHECK_EQ(0, NumberOfCachedWrappersToTrace());
return remote_tracer_->AdvanceTracing(deadline, actions);
}
......
......@@ -1610,8 +1610,6 @@ void Heap::Scavenge() {
scavenge_collector_->SelectScavengingVisitorsTable();
local_embedder_heap_tracer()->RegisterWrappersWithRemoteTracer();
// Flip the semispaces. After flipping, to space is empty, from space has
// live objects.
new_space_->Flip();
......@@ -1719,6 +1717,10 @@ void Heap::Scavenge() {
IncrementYoungSurvivorsCounter(PromotedSpaceSizeOfObjects() +
new_space_->Size() - survived_watermark);
// Scavenger may find new wrappers by iterating objects promoted onto a black
// page.
local_embedder_heap_tracer()->RegisterWrappersWithRemoteTracer();
LOG(isolate_, ResourceEvent("scavenge", "end"));
SetGCState(NOT_IN_GC);
......
......@@ -892,6 +892,11 @@ intptr_t IncrementalMarking::ProcessMarkingDeque(
VisitObject(map, obj, size);
bytes_processed += size - unscanned_bytes_of_large_object_;
}
// Report all found wrappers to the embedder. This is necessary as the
// embedder could potentially invalidate wrappers as soon as V8 is done
// with its incremental marking processing. Any cached wrappers could
// result in broken pointers at this point.
heap_->local_embedder_heap_tracer()->RegisterWrappersWithRemoteTracer();
return bytes_processed;
}
......@@ -1033,6 +1038,8 @@ double IncrementalMarking::AdvanceIncrementalMarking(
TRACE_EVENT0("v8", "V8.GCIncrementalMarking");
TRACE_GC(heap_->tracer(), GCTracer::Scope::MC_INCREMENTAL);
DCHECK(!IsStopped());
DCHECK_EQ(
0, heap_->local_embedder_heap_tracer()->NumberOfCachedWrappersToTrace());
double remaining_time_in_ms = 0.0;
intptr_t step_size_in_bytes = GCIdleTimeHandler::EstimateMarkingStepSize(
......
......@@ -2136,6 +2136,7 @@ void MarkCompactCollector::ProcessEphemeralMarking(
if (!only_process_harmony_weak_collections) {
if (heap_->local_embedder_heap_tracer()->InUse()) {
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_WRAPPER_TRACING);
heap_->local_embedder_heap_tracer()->RegisterWrappersWithRemoteTracer();
heap_->local_embedder_heap_tracer()->Trace(
0,
EmbedderHeapTracer::AdvanceTracingActions(
......
......@@ -135,6 +135,7 @@ TEST(LocalEmbedderHeapTracer, TraceFinishes) {
local_tracer.AddWrapperToTrace(CreateWrapperInfo());
EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace());
EXPECT_CALL(remote_tracer, RegisterV8References(_));
local_tracer.RegisterWrappersWithRemoteTracer();
EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(false));
EXPECT_FALSE(local_tracer.Trace(
0, EmbedderHeapTracer::AdvanceTracingActions(
......@@ -149,6 +150,7 @@ TEST(LocalEmbedderHeapTracer, TraceDoesNotFinish) {
local_tracer.AddWrapperToTrace(CreateWrapperInfo());
EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace());
EXPECT_CALL(remote_tracer, RegisterV8References(_));
local_tracer.RegisterWrappersWithRemoteTracer();
EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(true));
EXPECT_TRUE(local_tracer.Trace(
0, EmbedderHeapTracer::AdvanceTracingActions(
......
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