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

[heap] Remove duplicate MarkingBarrier for main thread in Heap

Now that the main thread has its own LocalHeap, we don't need a
separate instance of MarkingBarrier in Heap for the main thread
anymore. We can just use the MarkingBarrier in
main_thread_local_heap(). This makes code between main and background
threads more uniform.

Bug: v8:13018
Change-Id: I3d2dab1b11815df9a92c2fa7eebf52bf2cb130f2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3769687Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81841}
parent 13f4aa05
......@@ -21,8 +21,9 @@ thread_local MarkingBarrier* current_marking_barrier = nullptr;
} // namespace
MarkingBarrier* WriteBarrier::CurrentMarkingBarrier(Heap* heap) {
return current_marking_barrier ? current_marking_barrier
: heap->marking_barrier();
return current_marking_barrier
? current_marking_barrier
: heap->main_thread_local_heap()->marking_barrier();
}
void WriteBarrier::SetForThread(MarkingBarrier* marking_barrier) {
......@@ -37,15 +38,13 @@ void WriteBarrier::ClearForThread(MarkingBarrier* marking_barrier) {
void WriteBarrier::MarkingSlow(Heap* heap, HeapObject host, HeapObjectSlot slot,
HeapObject value) {
MarkingBarrier* marking_barrier = current_marking_barrier
? current_marking_barrier
: heap->marking_barrier();
MarkingBarrier* marking_barrier = CurrentMarkingBarrier(heap);
marking_barrier->Write(host, slot, value);
}
// static
void WriteBarrier::MarkingSlowFromGlobalHandle(Heap* heap, HeapObject value) {
heap->marking_barrier()->WriteWithoutHost(value);
heap->main_thread_local_heap()->marking_barrier()->WriteWithoutHost(value);
}
// static
......@@ -58,25 +57,19 @@ void WriteBarrier::MarkingSlowFromInternalFields(Heap* heap, JSObject host) {
void WriteBarrier::MarkingSlow(Heap* heap, Code host, RelocInfo* reloc_info,
HeapObject value) {
MarkingBarrier* marking_barrier = current_marking_barrier
? current_marking_barrier
: heap->marking_barrier();
MarkingBarrier* marking_barrier = CurrentMarkingBarrier(heap);
marking_barrier->Write(host, reloc_info, value);
}
void WriteBarrier::MarkingSlow(Heap* heap, JSArrayBuffer host,
ArrayBufferExtension* extension) {
MarkingBarrier* marking_barrier = current_marking_barrier
? current_marking_barrier
: heap->marking_barrier();
MarkingBarrier* marking_barrier = CurrentMarkingBarrier(heap);
marking_barrier->Write(host, extension);
}
void WriteBarrier::MarkingSlow(Heap* heap, DescriptorArray descriptor_array,
int number_of_own_descriptors) {
MarkingBarrier* marking_barrier = current_marking_barrier
? current_marking_barrier
: heap->marking_barrier();
MarkingBarrier* marking_barrier = CurrentMarkingBarrier(heap);
marking_barrier->Write(descriptor_array, number_of_own_descriptors);
}
......
......@@ -5735,8 +5735,6 @@ void Heap::SetUp(LocalHeap* main_thread_local_heap) {
concurrent_marking_.reset(new ConcurrentMarking(this, nullptr, nullptr));
}
marking_barrier_.reset(new MarkingBarrier(this));
for (int i = FIRST_SPACE; i <= LAST_SPACE; i++) {
space_[i] = nullptr;
}
......
......@@ -100,7 +100,6 @@ class JSFinalizationRegistry;
class LinearAllocationArea;
class LocalEmbedderHeapTracer;
class LocalHeap;
class MarkingBarrier;
class MemoryAllocator;
class MemoryChunk;
class MemoryMeasurement;
......@@ -1128,8 +1127,6 @@ class Heap {
return incremental_marking_.get();
}
MarkingBarrier* marking_barrier() const { return marking_barrier_.get(); }
// ===========================================================================
// Concurrent marking API. ===================================================
// ===========================================================================
......@@ -2338,7 +2335,6 @@ class Heap {
std::unique_ptr<AllocationObserver> scavenge_task_observer_;
std::unique_ptr<AllocationObserver> stress_concurrent_allocation_observer_;
std::unique_ptr<LocalEmbedderHeapTracer> local_embedder_heap_tracer_;
std::unique_ptr<MarkingBarrier> marking_barrier_;
std::unique_ptr<AllocationTrackerForDebugging>
allocation_tracker_for_debugging_;
......
......@@ -22,6 +22,7 @@ namespace internal {
class Heap;
class LocalHandles;
class MarkingBarrier;
class MemoryChunk;
class Safepoint;
......
......@@ -512,7 +512,7 @@ void MarkCompactCollector::TearDown() {
AbortCompaction();
if (heap()->incremental_marking()->IsMarking()) {
local_marking_worklists()->Publish();
heap()->marking_barrier()->Publish();
heap()->main_thread_local_heap()->marking_barrier()->Publish();
// Marking barriers of LocalHeaps will be published in their destructors.
marking_worklists()->Clear();
local_weak_objects()->Publish();
......
......@@ -22,25 +22,16 @@
namespace v8 {
namespace internal {
MarkingBarrier::MarkingBarrier(Heap* heap)
: heap_(heap),
collector_(heap_->mark_compact_collector()),
incremental_marking_(heap_->incremental_marking()),
worklist_(collector_->marking_worklists()->shared()),
marking_state_(heap_->isolate()),
is_main_thread_barrier_(true),
is_shared_heap_(heap_->IsShared()) {}
MarkingBarrier::MarkingBarrier(LocalHeap* local_heap)
: heap_(local_heap->heap()),
collector_(heap_->mark_compact_collector()),
incremental_marking_(nullptr),
incremental_marking_(heap_->incremental_marking()),
worklist_(collector_->marking_worklists()->shared()),
marking_state_(heap_->isolate()),
is_main_thread_barrier_(false),
is_main_thread_barrier_(local_heap->is_main_thread()),
is_shared_heap_(heap_->IsShared()) {}
MarkingBarrier::~MarkingBarrier() { DCHECK(worklist_.IsLocalEmpty()); }
MarkingBarrier::~MarkingBarrier() { DCHECK(typed_slots_map_.empty()); }
void MarkingBarrier::Write(HeapObject host, HeapObjectSlot slot,
HeapObject value) {
......@@ -135,7 +126,6 @@ void MarkingBarrier::RecordRelocSlot(Code host, RelocInfo* rinfo,
// static
void MarkingBarrier::ActivateAll(Heap* heap, bool is_compacting) {
heap->marking_barrier()->Activate(is_compacting);
heap->safepoint()->IterateLocalHeaps([is_compacting](LocalHeap* local_heap) {
local_heap->marking_barrier()->Activate(is_compacting);
});
......@@ -143,7 +133,6 @@ void MarkingBarrier::ActivateAll(Heap* heap, bool is_compacting) {
// static
void MarkingBarrier::DeactivateAll(Heap* heap) {
heap->marking_barrier()->Deactivate();
heap->safepoint()->IterateLocalHeaps([](LocalHeap* local_heap) {
local_heap->marking_barrier()->Deactivate();
});
......@@ -151,7 +140,6 @@ void MarkingBarrier::DeactivateAll(Heap* heap) {
// static
void MarkingBarrier::PublishAll(Heap* heap) {
heap->marking_barrier()->Publish();
heap->safepoint()->IterateLocalHeaps(
[](LocalHeap* local_heap) { local_heap->marking_barrier()->Publish(); });
}
......
......@@ -20,7 +20,6 @@ class NewSpace;
class MarkingBarrier {
public:
explicit MarkingBarrier(Heap*);
explicit MarkingBarrier(LocalHeap*);
~MarkingBarrier();
......
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