Commit fd7c9065 authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Introduce ShouldMarkObject() in marking visitors

This method will be used in the marking visitors to stop marking into
the shared heap from e.g. worker or client heaps.

Bug: v8:13267
Change-Id: I7a099a3f816fa5d867d6a99558838389914e3048
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3904606
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83308}
parent 014cadc9
...@@ -120,9 +120,7 @@ class ConcurrentMarkingVisitorUtility { ...@@ -120,9 +120,7 @@ class ConcurrentMarkingVisitorUtility {
if (!object.IsHeapObject()) continue; if (!object.IsHeapObject()) continue;
HeapObject heap_object = HeapObject::cast(object); HeapObject heap_object = HeapObject::cast(object);
visitor->SynchronizePageAccess(heap_object); visitor->SynchronizePageAccess(heap_object);
BasicMemoryChunk* target_page = if (!visitor->ShouldMarkObject(heap_object)) continue;
BasicMemoryChunk::FromHeapObject(heap_object);
if (!visitor->is_shared_heap() && target_page->InSharedHeap()) continue;
visitor->MarkObject(host, heap_object); visitor->MarkObject(host, heap_object);
visitor->RecordSlot(host, slot, heap_object); visitor->RecordSlot(host, slot, heap_object);
} }
...@@ -220,7 +218,9 @@ class YoungGenerationConcurrentMarkingVisitor final ...@@ -220,7 +218,9 @@ class YoungGenerationConcurrentMarkingVisitor final
heap->isolate(), worklists_local), heap->isolate(), worklists_local),
marking_state_(heap->isolate(), memory_chunk_data) {} marking_state_(heap->isolate(), memory_chunk_data) {}
bool is_shared_heap() { return false; } bool ShouldMarkObject(HeapObject object) const {
return !object.InSharedHeap();
}
void SynchronizePageAccess(HeapObject heap_object) { void SynchronizePageAccess(HeapObject heap_object) {
#ifdef THREAD_SANITIZER #ifdef THREAD_SANITIZER
......
...@@ -4407,7 +4407,11 @@ bool Heap::InSpace(HeapObject value, AllocationSpace space) const { ...@@ -4407,7 +4407,11 @@ bool Heap::InSpace(HeapObject value, AllocationSpace space) const {
UNREACHABLE(); UNREACHABLE();
} }
bool Heap::IsShared() { return isolate()->is_shared(); } bool Heap::IsShared() const { return isolate()->is_shared(); }
bool Heap::ShouldMarkSharedHeap() const {
return isolate()->is_shared() || isolate()->is_shared_space_isolate();
}
bool Heap::InSpaceSlow(Address addr, AllocationSpace space) const { bool Heap::InSpaceSlow(Address addr, AllocationSpace space) const {
if (memory_allocator()->IsOutsideAllocatedSpace(addr)) { if (memory_allocator()->IsOutsideAllocatedSpace(addr)) {
......
...@@ -1281,7 +1281,8 @@ class Heap { ...@@ -1281,7 +1281,8 @@ class Heap {
V8_EXPORT_PRIVATE bool InSpace(HeapObject value, AllocationSpace space) const; V8_EXPORT_PRIVATE bool InSpace(HeapObject value, AllocationSpace space) const;
// Returns true when this heap is shared. // Returns true when this heap is shared.
V8_EXPORT_PRIVATE bool IsShared(); V8_EXPORT_PRIVATE bool IsShared() const;
V8_EXPORT_PRIVATE bool ShouldMarkSharedHeap() const;
// Slow methods that can be used for verification as they can also be used // Slow methods that can be used for verification as they can also be used
// with off-heap Addresses. // with off-heap Addresses.
......
...@@ -44,7 +44,7 @@ template <typename THeapObjectSlot> ...@@ -44,7 +44,7 @@ template <typename THeapObjectSlot>
void MarkingVisitorBase<ConcreteVisitor, MarkingState>::ProcessStrongHeapObject( void MarkingVisitorBase<ConcreteVisitor, MarkingState>::ProcessStrongHeapObject(
HeapObject host, THeapObjectSlot slot, HeapObject heap_object) { HeapObject host, THeapObjectSlot slot, HeapObject heap_object) {
SynchronizePageAccess(heap_object); SynchronizePageAccess(heap_object);
if (!is_shared_heap_ && heap_object.InSharedHeap()) return; if (!ShouldMarkObject(heap_object)) return;
MarkObject(host, heap_object); MarkObject(host, heap_object);
concrete_visitor()->RecordSlot(host, slot, heap_object); concrete_visitor()->RecordSlot(host, slot, heap_object);
} }
...@@ -56,7 +56,7 @@ template <typename THeapObjectSlot> ...@@ -56,7 +56,7 @@ template <typename THeapObjectSlot>
void MarkingVisitorBase<ConcreteVisitor, MarkingState>::ProcessWeakHeapObject( void MarkingVisitorBase<ConcreteVisitor, MarkingState>::ProcessWeakHeapObject(
HeapObject host, THeapObjectSlot slot, HeapObject heap_object) { HeapObject host, THeapObjectSlot slot, HeapObject heap_object) {
SynchronizePageAccess(heap_object); SynchronizePageAccess(heap_object);
if (!is_shared_heap_ && heap_object.InSharedHeap()) return; if (!ShouldMarkObject(heap_object)) return;
if (concrete_visitor()->marking_state()->IsBlackOrGrey(heap_object)) { if (concrete_visitor()->marking_state()->IsBlackOrGrey(heap_object)) {
// Weak references with live values are directly processed here to // Weak references with live values are directly processed here to
// reduce the processing time of weak cells during the main GC // reduce the processing time of weak cells during the main GC
...@@ -116,7 +116,7 @@ void MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEmbeddedPointer( ...@@ -116,7 +116,7 @@ void MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEmbeddedPointer(
DCHECK(RelocInfo::IsEmbeddedObjectMode(rinfo->rmode())); DCHECK(RelocInfo::IsEmbeddedObjectMode(rinfo->rmode()));
HeapObject object = HeapObject object =
rinfo->target_object(ObjectVisitorWithCageBases::cage_base()); rinfo->target_object(ObjectVisitorWithCageBases::cage_base());
if (!is_shared_heap_ && object.InSharedHeap()) return; if (!ShouldMarkObject(object)) return;
if (!concrete_visitor()->marking_state()->IsBlackOrGrey(object)) { if (!concrete_visitor()->marking_state()->IsBlackOrGrey(object)) {
if (host.IsWeakObject(object)) { if (host.IsWeakObject(object)) {
...@@ -136,7 +136,7 @@ void MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitCodeTarget( ...@@ -136,7 +136,7 @@ void MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitCodeTarget(
DCHECK(RelocInfo::IsCodeTargetMode(rinfo->rmode())); DCHECK(RelocInfo::IsCodeTargetMode(rinfo->rmode()));
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address()); Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
if (!is_shared_heap_ && target.InSharedHeap()) return; if (!ShouldMarkObject(target)) return;
MarkObject(host, target); MarkObject(host, target);
concrete_visitor()->RecordRelocSlot(host, rinfo, target); concrete_visitor()->RecordRelocSlot(host, rinfo, target);
} }
...@@ -371,7 +371,7 @@ int MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEphemeronHashTable( ...@@ -371,7 +371,7 @@ int MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEphemeronHashTable(
ObjectSlot value_slot = ObjectSlot value_slot =
table.RawFieldOfElementAt(EphemeronHashTable::EntryToValueIndex(i)); table.RawFieldOfElementAt(EphemeronHashTable::EntryToValueIndex(i));
if ((!is_shared_heap_ && key.InSharedHeap()) || if (!ShouldMarkObject(key) ||
concrete_visitor()->marking_state()->IsBlackOrGrey(key)) { concrete_visitor()->marking_state()->IsBlackOrGrey(key)) {
VisitPointer(table, value_slot); VisitPointer(table, value_slot);
} else { } else {
...@@ -383,7 +383,7 @@ int MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEphemeronHashTable( ...@@ -383,7 +383,7 @@ int MarkingVisitorBase<ConcreteVisitor, MarkingState>::VisitEphemeronHashTable(
concrete_visitor()->RecordSlot(table, value_slot, value); concrete_visitor()->RecordSlot(table, value_slot, value);
AddWeakReferenceForReferenceSummarizer(table, value); AddWeakReferenceForReferenceSummarizer(table, value);
if (!is_shared_heap_ && value.InSharedHeap()) continue; if (!ShouldMarkObject(value)) continue;
// Revisit ephemerons with both key and value unreachable at end // Revisit ephemerons with both key and value unreachable at end
// of concurrent marking cycle. // of concurrent marking cycle.
......
...@@ -154,7 +154,7 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> { ...@@ -154,7 +154,7 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> {
code_flush_mode_(code_flush_mode), code_flush_mode_(code_flush_mode),
is_embedder_tracing_enabled_(is_embedder_tracing_enabled), is_embedder_tracing_enabled_(is_embedder_tracing_enabled),
should_keep_ages_unchanged_(should_keep_ages_unchanged), should_keep_ages_unchanged_(should_keep_ages_unchanged),
is_shared_heap_(heap->IsShared()) should_mark_shared_heap_(heap->ShouldMarkSharedHeap())
#ifdef V8_ENABLE_SANDBOX #ifdef V8_ENABLE_SANDBOX
, ,
external_pointer_table_(&heap->isolate()->external_pointer_table()), external_pointer_table_(&heap->isolate()->external_pointer_table()),
...@@ -221,7 +221,10 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> { ...@@ -221,7 +221,10 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> {
#endif #endif
} }
bool is_shared_heap() { return is_shared_heap_; } bool ShouldMarkObject(HeapObject object) const {
if (should_mark_shared_heap_) return true;
return !object.InSharedHeap();
}
// Marks the object grey and pushes it on the marking work list. // Marks the object grey and pushes it on the marking work list.
V8_INLINE void MarkObject(HeapObject host, HeapObject obj); V8_INLINE void MarkObject(HeapObject host, HeapObject obj);
...@@ -290,7 +293,7 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> { ...@@ -290,7 +293,7 @@ class MarkingVisitorBase : public HeapVisitor<int, ConcreteVisitor> {
const base::EnumSet<CodeFlushMode> code_flush_mode_; const base::EnumSet<CodeFlushMode> code_flush_mode_;
const bool is_embedder_tracing_enabled_; const bool is_embedder_tracing_enabled_;
const bool should_keep_ages_unchanged_; const bool should_keep_ages_unchanged_;
const bool is_shared_heap_; const bool should_mark_shared_heap_;
#ifdef V8_ENABLE_SANDBOX #ifdef V8_ENABLE_SANDBOX
ExternalPointerTable* const external_pointer_table_; ExternalPointerTable* const external_pointer_table_;
ExternalPointerTable* const shared_external_pointer_table_; ExternalPointerTable* const shared_external_pointer_table_;
......
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