Commit dcd91455 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Do not scan main thread handles when starting marking

We do not need to scan main thread handles when starting incremental
marking. This reduces the time to start incremental marking.

Bug: v8:11645
Change-Id: Ib99a13e7875f50fbfe5346ac0e186d8960ea1337
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2826124Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73994}
parent c685df32
...@@ -4493,8 +4493,10 @@ void Heap::IterateRoots(RootVisitor* v, base::EnumSet<SkipRoot> options) { ...@@ -4493,8 +4493,10 @@ void Heap::IterateRoots(RootVisitor* v, base::EnumSet<SkipRoot> options) {
// Iterate over local handles in handle scopes. // Iterate over local handles in handle scopes.
FixStaleLeftTrimmedHandlesVisitor left_trim_visitor(this); FixStaleLeftTrimmedHandlesVisitor left_trim_visitor(this);
#ifndef V8_ENABLE_CONSERVATIVE_STACK_SCANNING #ifndef V8_ENABLE_CONSERVATIVE_STACK_SCANNING
isolate_->handle_scope_implementer()->Iterate(&left_trim_visitor); if (!options.contains(SkipRoot::kMainThreadHandles)) {
isolate_->handle_scope_implementer()->Iterate(v); isolate_->handle_scope_implementer()->Iterate(&left_trim_visitor);
isolate_->handle_scope_implementer()->Iterate(v);
}
#endif #endif
safepoint_->Iterate(&left_trim_visitor); safepoint_->Iterate(&left_trim_visitor);
......
...@@ -176,6 +176,7 @@ enum class SkipRoot { ...@@ -176,6 +176,7 @@ enum class SkipRoot {
kGlobalHandles, kGlobalHandles,
kOldGeneration, kOldGeneration,
kStack, kStack,
kMainThreadHandles,
kUnserializable, kUnserializable,
kWeak kWeak
}; };
......
...@@ -318,7 +318,9 @@ void IncrementalMarking::MarkRoots() { ...@@ -318,7 +318,9 @@ void IncrementalMarking::MarkRoots() {
IncrementalMarkingRootMarkingVisitor visitor(this); IncrementalMarkingRootMarkingVisitor visitor(this);
heap_->IterateRoots( heap_->IterateRoots(
&visitor, base::EnumSet<SkipRoot>{SkipRoot::kStack, SkipRoot::kWeak}); &visitor,
base::EnumSet<SkipRoot>{SkipRoot::kStack, SkipRoot::kMainThreadHandles,
SkipRoot::kWeak});
} }
bool IncrementalMarking::ShouldRetainMap(Map map, int age) { bool IncrementalMarking::ShouldRetainMap(Map map, int age) {
......
...@@ -269,6 +269,10 @@ TEST(ArrayBuffer_LivePromotion) { ...@@ -269,6 +269,10 @@ TEST(ArrayBuffer_LivePromotion) {
Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); Handle<JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab);
root->set(0, *buf); // Buffer that should be promoted as live. root->set(0, *buf); // Buffer that should be promoted as live.
} }
// Store array in Global such that it is part of the root set when
// starting incremental marking.
v8::Global<Value> global_root(CcTest::isolate(),
Utils::ToLocal(Handle<Object>::cast(root)));
heap::SimulateIncrementalMarking(heap, true); heap::SimulateIncrementalMarking(heap, true);
CHECK(IsTracked(heap, JSArrayBuffer::cast(root->get(0)))); CHECK(IsTracked(heap, JSArrayBuffer::cast(root->get(0))));
heap::GcAndSweep(heap, NEW_SPACE); heap::GcAndSweep(heap, NEW_SPACE);
......
...@@ -112,6 +112,12 @@ TEST(ConcurrentMarkingMarkedBytes) { ...@@ -112,6 +112,12 @@ TEST(ConcurrentMarkingMarkedBytes) {
Handle<FixedArray> root = isolate->factory()->NewFixedArray(1000000); Handle<FixedArray> root = isolate->factory()->NewFixedArray(1000000);
CcTest::CollectAllGarbage(); CcTest::CollectAllGarbage();
if (!heap->incremental_marking()->IsStopped()) return; if (!heap->incremental_marking()->IsStopped()) return;
// Store array in Global such that it is part of the root set when
// starting incremental marking.
v8::Global<Value> global_root(CcTest::isolate(),
Utils::ToLocal(Handle<Object>::cast(root)));
heap::SimulateIncrementalMarking(heap, false); heap::SimulateIncrementalMarking(heap, false);
heap->concurrent_marking()->Join(); heap->concurrent_marking()->Join();
CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size()); CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size());
......
...@@ -2304,6 +2304,11 @@ TEST(InstanceOfStubWriteBarrier) { ...@@ -2304,6 +2304,11 @@ TEST(InstanceOfStubWriteBarrier) {
v8::HandleScope outer_scope(CcTest::isolate()); v8::HandleScope outer_scope(CcTest::isolate());
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext(); v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
// Store native context in global as well to make it part of the root set when
// starting incremental marking. This will ensure that function will be part
// of the transitive closure during incremental marking.
v8::Global<v8::Context> global_ctx(CcTest::isolate(), ctx);
{ {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
CompileRun( CompileRun(
...@@ -5218,6 +5223,10 @@ void CheckMapRetainingFor(int n) { ...@@ -5218,6 +5223,10 @@ void CheckMapRetainingFor(int n) {
Handle<Context> context = Utils::OpenHandle(*ctx); Handle<Context> context = Utils::OpenHandle(*ctx);
CHECK(context->IsNativeContext()); CHECK(context->IsNativeContext());
Handle<NativeContext> native_context = Handle<NativeContext>::cast(context); Handle<NativeContext> native_context = Handle<NativeContext>::cast(context);
// This global is used to visit the object's constructor alive when starting
// incremental marking. The native context keeps the constructor alive. The
// constructor needs to be alive to retain the map.
v8::Global<v8::Context> global_ctxt(CcTest::isolate(), ctx);
ctx->Enter(); ctx->Enter();
Handle<WeakFixedArray> array_with_map = Handle<WeakFixedArray> array_with_map =
...@@ -5702,11 +5711,17 @@ TEST(Regress598319) { ...@@ -5702,11 +5711,17 @@ TEST(Regress598319) {
get().set(i, *tmp); get().set(i, *tmp);
} }
} }
global_root.Reset(CcTest::isolate(),
Utils::ToLocal(Handle<Object>::cast(root)));
} }
FixedArray get() { return FixedArray::cast(root->get(0)); } FixedArray get() { return FixedArray::cast(root->get(0)); }
Handle<FixedArray> root; Handle<FixedArray> root;
// Store array in global as well to make it part of the root set when
// starting incremental marking.
v8::Global<Value> global_root;
} arr(isolate, kNumberOfObjects); } arr(isolate, kNumberOfObjects);
CHECK_EQ(arr.get().length(), kNumberOfObjects); CHECK_EQ(arr.get().length(), kNumberOfObjects);
......
...@@ -75,7 +75,11 @@ HEAP_TEST(WriteBarrier_MarkingExtension) { ...@@ -75,7 +75,11 @@ HEAP_TEST(WriteBarrier_MarkingExtension) {
CHECK(collector->marking_state()->IsWhite(host)); CHECK(collector->marking_state()->IsWhite(host));
CHECK(!extension->IsMarked()); CHECK(!extension->IsMarked());
WriteBarrier::Marking(host, extension); WriteBarrier::Marking(host, extension);
// Concurrent marking barrier should mark this object.
CHECK_EQ(V8_CONCURRENT_MARKING_BOOL, extension->IsMarked()); CHECK_EQ(V8_CONCURRENT_MARKING_BOOL, extension->IsMarked());
// Keep object alive using the global handle.
v8::Global<ArrayBuffer> global_host(CcTest::isolate(),
Utils::ToLocal(handle(host, isolate)));
heap::SimulateIncrementalMarking(CcTest::heap(), true); heap::SimulateIncrementalMarking(CcTest::heap(), true);
CHECK(collector->marking_state()->IsBlack(host)); CHECK(collector->marking_state()->IsBlack(host));
CHECK(extension->IsMarked()); CHECK(extension->IsMarked());
......
...@@ -892,6 +892,11 @@ TEST(JSWeakRefScavengedInWorklist) { ...@@ -892,6 +892,11 @@ TEST(JSWeakRefScavengedInWorklist) {
weak_ref = inner_scope.CloseAndEscape(inner_weak_ref); weak_ref = inner_scope.CloseAndEscape(inner_weak_ref);
} }
// Store weak_ref in Global such that it is part of the root set when
// starting incremental marking.
v8::Global<Value> global_weak_ref(
CcTest::isolate(), Utils::ToLocal(Handle<Object>::cast(weak_ref)));
// Do marking. This puts the WeakRef above into the js_weak_refs worklist // Do marking. This puts the WeakRef above into the js_weak_refs worklist
// since its target isn't marked. // since its target isn't marked.
CHECK( CHECK(
...@@ -934,6 +939,10 @@ TEST(JSWeakRefTenuredInWorklist) { ...@@ -934,6 +939,10 @@ TEST(JSWeakRefTenuredInWorklist) {
weak_ref = inner_scope.CloseAndEscape(inner_weak_ref); weak_ref = inner_scope.CloseAndEscape(inner_weak_ref);
} }
// Store weak_ref such that it is part of the root set when starting
// incremental marking.
v8::Global<Value> global_weak_ref(
CcTest::isolate(), Utils::ToLocal(Handle<Object>::cast(weak_ref)));
JSWeakRef old_weak_ref_location = *weak_ref; JSWeakRef old_weak_ref_location = *weak_ref;
// Do marking. This puts the WeakRef above into the js_weak_refs worklist // Do marking. This puts the WeakRef above into the js_weak_refs worklist
......
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