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