Commit fd871bde authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Prepare concurrent marking for new jobs api

The concurrent marking tasks used to get an ids as an
argument. With the new jobs api we can no longer pass
the id that way.
This CL updates to tasks to get an id from a collection
of available ids. This way all tasks only need to get a
pointer to the ThreadState (so tasks don't get unique
arguments anymore).

Bug: 986235
Change-Id: Ibd7146840c74297dc4531a1b4c6c1475c647464d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884850
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarAnton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712553}
parent 1adc373e
...@@ -729,6 +729,7 @@ void ThreadState::AtomicPauseMarkPrologue(BlinkGC::StackState stack_state, ...@@ -729,6 +729,7 @@ void ThreadState::AtomicPauseMarkPrologue(BlinkGC::StackState stack_state,
// Stop concurrent markers // Stop concurrent markers
marker_scheduler_->CancelAndWait(); marker_scheduler_->CancelAndWait();
active_markers_ = 0; active_markers_ = 0;
available_concurrent_marking_ids_.clear();
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
MarkingWorklist* worklist = Heap().GetMarkingWorklist(); MarkingWorklist* worklist = Heap().GetMarkingWorklist();
...@@ -1208,7 +1209,7 @@ bool ThreadState::ConcurrentMarkingStep() { ...@@ -1208,7 +1209,7 @@ bool ThreadState::ConcurrentMarkingStep() {
ScheduleConcurrentMarking(); ScheduleConcurrentMarking();
return false; return false;
} }
base::AutoLock lock(active_concurrent_markers_lock_); base::AutoLock lock(concurrent_marker_bootstrapping_lock_);
return active_markers_ == 0; return active_markers_ == 0;
} }
...@@ -1691,7 +1692,7 @@ void ThreadState::EnableCompactionForNextGCForTesting() { ...@@ -1691,7 +1692,7 @@ void ThreadState::EnableCompactionForNextGCForTesting() {
} }
void ThreadState::ScheduleConcurrentMarking() { void ThreadState::ScheduleConcurrentMarking() {
base::AutoLock lock(active_concurrent_markers_lock_); base::AutoLock lock(concurrent_marker_bootstrapping_lock_);
if (active_markers_ > 0) { if (active_markers_ > 0) {
// Concurrent markers are already running, should not run them again // Concurrent markers are already running, should not run them again
...@@ -1713,20 +1714,27 @@ void ThreadState::ScheduleConcurrentMarking() { ...@@ -1713,20 +1714,27 @@ void ThreadState::ScheduleConcurrentMarking() {
active_markers_ = kNumberOfConcurrentMarkingTasks; active_markers_ = kNumberOfConcurrentMarkingTasks;
for (int i = 0; i < kNumberOfConcurrentMarkingTasks; ++i) { for (int i = 0; i < kNumberOfConcurrentMarkingTasks; ++i) {
marker_scheduler_->ScheduleTask( available_concurrent_marking_ids_.push_back(
WTF::CrossThreadBindOnce(&ThreadState::PerformConcurrentMark, WorklistTaskId::ConcurrentThreadBase + i);
WTF::CrossThreadUnretained(this), i)); marker_scheduler_->ScheduleTask(WTF::CrossThreadBindOnce(
&ThreadState::PerformConcurrentMark, WTF::CrossThreadUnretained(this)));
} }
} }
void ThreadState::PerformConcurrentMark(int concurrent_marker_id) { void ThreadState::PerformConcurrentMark() {
VLOG(2) << "[state:" << this << "] [threadid:" << CurrentThread() << "] " VLOG(2) << "[state:" << this << "] [threadid:" << CurrentThread() << "] "
<< "ConcurrentMark"; << "ConcurrentMark";
ThreadHeapStatsCollector::EnabledConcurrentScope stats_scope( ThreadHeapStatsCollector::EnabledConcurrentScope stats_scope(
Heap().stats_collector(), ThreadHeapStatsCollector::kConcurrentMark); Heap().stats_collector(), ThreadHeapStatsCollector::kConcurrentMark);
const int task_id = int task_id;
WorklistTaskId::ConcurrentThreadBase + concurrent_marker_id; {
base::AutoLock lock(concurrent_marker_bootstrapping_lock_);
DCHECK(!available_concurrent_marking_ids_.IsEmpty());
task_id = available_concurrent_marking_ids_.back();
available_concurrent_marking_ids_.pop_back();
}
std::unique_ptr<ConcurrentMarkingVisitor> concurrent_visitor = std::unique_ptr<ConcurrentMarkingVisitor> concurrent_visitor =
IsUnifiedGCMarkingInProgress() IsUnifiedGCMarkingInProgress()
? std::make_unique<ConcurrentUnifiedHeapMarkingVisitor>( ? std::make_unique<ConcurrentUnifiedHeapMarkingVisitor>(
...@@ -1742,10 +1750,11 @@ void ThreadState::PerformConcurrentMark(int concurrent_marker_id) { ...@@ -1742,10 +1750,11 @@ void ThreadState::PerformConcurrentMark(int concurrent_marker_id) {
concurrent_visitor->FlushWorklists(); concurrent_visitor->FlushWorklists();
{ {
base::AutoLock lock(active_concurrent_markers_lock_); base::AutoLock lock(concurrent_marker_bootstrapping_lock_);
// When marking is done, flush visitor worklists and decrement number of // When marking is done, flush visitor worklists and decrement number of
// active markers so we know how many markers are left // active markers so we know how many markers are left
concurrently_marked_bytes_ += concurrent_visitor->marked_bytes(); concurrently_marked_bytes_ += concurrent_visitor->marked_bytes();
available_concurrent_marking_ids_.push_back(task_id);
if (finished) { if (finished) {
--active_markers_; --active_markers_;
return; return;
...@@ -1754,8 +1763,7 @@ void ThreadState::PerformConcurrentMark(int concurrent_marker_id) { ...@@ -1754,8 +1763,7 @@ void ThreadState::PerformConcurrentMark(int concurrent_marker_id) {
// Reschedule this marker // Reschedule this marker
marker_scheduler_->ScheduleTask(WTF::CrossThreadBindOnce( marker_scheduler_->ScheduleTask(WTF::CrossThreadBindOnce(
&ThreadState::PerformConcurrentMark, WTF::CrossThreadUnretained(this), &ThreadState::PerformConcurrentMark, WTF::CrossThreadUnretained(this)));
concurrent_marker_id));
} }
} // namespace blink } // namespace blink
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "third_party/blink/renderer/platform/wtf/thread_specific.h" #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/threading.h" #include "third_party/blink/renderer/platform/wtf/threading.h"
#include "third_party/blink/renderer/platform/wtf/threading_primitives.h" #include "third_party/blink/renderer/platform/wtf/threading_primitives.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace v8 { namespace v8 {
class EmbedderGraph; class EmbedderGraph;
...@@ -301,7 +302,7 @@ class PLATFORM_EXPORT ThreadState final { ...@@ -301,7 +302,7 @@ class PLATFORM_EXPORT ThreadState final {
// terminated and the worklist is empty) // terminated and the worklist is empty)
bool ConcurrentMarkingStep(); bool ConcurrentMarkingStep();
void ScheduleConcurrentMarking(); void ScheduleConcurrentMarking();
void PerformConcurrentMark(int); void PerformConcurrentMark();
void CompleteSweep(); void CompleteSweep();
void NotifySweepDone(); void NotifySweepDone();
...@@ -594,8 +595,9 @@ class PLATFORM_EXPORT ThreadState final { ...@@ -594,8 +595,9 @@ class PLATFORM_EXPORT ThreadState final {
std::unique_ptr<IncrementalMarkingScheduler> incremental_marking_scheduler_; std::unique_ptr<IncrementalMarkingScheduler> incremental_marking_scheduler_;
std::unique_ptr<CancelableTaskScheduler> marker_scheduler_; std::unique_ptr<CancelableTaskScheduler> marker_scheduler_;
Vector<int> available_concurrent_marking_ids_;
uint8_t active_markers_ = 0; uint8_t active_markers_ = 0;
base::Lock active_concurrent_markers_lock_; base::Lock concurrent_marker_bootstrapping_lock_;
size_t concurrently_marked_bytes_ = 0; size_t concurrently_marked_bytes_ = 0;
std::unique_ptr<CancelableTaskScheduler> sweeper_scheduler_; std::unique_ptr<CancelableTaskScheduler> sweeper_scheduler_;
......
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