Commit 44e2357e authored by Leon Bettscheider's avatar Leon Bettscheider Committed by V8 LUCI CQ

[heap] Make ScheduleJob branch to JobTaskMinor and JobTaskMajor

This CL renames ConcurrentMarking::JobTask to JobTaskMajor, adds
JobTaskMinor, and makes ScheduleJob branch to schedule the respective
JobTask depending on its GarbageCollector parameter.

Bug: v8:13012
Change-Id: Ic7ab15ba70f7d4e86c94a6824623c258aa8b739c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3850482Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Leon Bettscheider <bettscheider@google.com>
Cr-Commit-Position: refs/heads/main@{#82913}
parent ada791dc
...@@ -575,32 +575,35 @@ StrongDescriptorArray ConcurrentMarkingVisitor::Cast(HeapObject object) { ...@@ -575,32 +575,35 @@ StrongDescriptorArray ConcurrentMarkingVisitor::Cast(HeapObject object) {
return StrongDescriptorArray::unchecked_cast(DescriptorArray::cast(object)); return StrongDescriptorArray::unchecked_cast(DescriptorArray::cast(object));
} }
class ConcurrentMarking::JobTask : public v8::JobTask { class ConcurrentMarking::JobTaskMajor : public v8::JobTask {
public: public:
JobTask(ConcurrentMarking* concurrent_marking, unsigned mark_compact_epoch, JobTaskMajor(ConcurrentMarking* concurrent_marking,
base::EnumSet<CodeFlushMode> code_flush_mode, unsigned mark_compact_epoch,
bool should_keep_ages_unchanged) base::EnumSet<CodeFlushMode> code_flush_mode,
bool should_keep_ages_unchanged)
: concurrent_marking_(concurrent_marking), : concurrent_marking_(concurrent_marking),
mark_compact_epoch_(mark_compact_epoch), mark_compact_epoch_(mark_compact_epoch),
code_flush_mode_(code_flush_mode), code_flush_mode_(code_flush_mode),
should_keep_ages_unchanged_(should_keep_ages_unchanged) {} should_keep_ages_unchanged_(should_keep_ages_unchanged) {}
~JobTask() override = default; ~JobTaskMajor() override = default;
JobTask(const JobTask&) = delete; JobTaskMajor(const JobTaskMajor&) = delete;
JobTask& operator=(const JobTask&) = delete; JobTaskMajor& operator=(const JobTaskMajor&) = delete;
// v8::JobTask overrides. // v8::JobTask overrides.
void Run(JobDelegate* delegate) override { void Run(JobDelegate* delegate) override {
if (delegate->IsJoiningThread()) { if (delegate->IsJoiningThread()) {
// TRACE_GC is not needed here because the caller opens the right scope. // TRACE_GC is not needed here because the caller opens the right scope.
concurrent_marking_->Run(delegate, code_flush_mode_, mark_compact_epoch_, concurrent_marking_->RunMajor(delegate, code_flush_mode_,
should_keep_ages_unchanged_); mark_compact_epoch_,
should_keep_ages_unchanged_);
} else { } else {
TRACE_GC_EPOCH(concurrent_marking_->heap_->tracer(), TRACE_GC_EPOCH(concurrent_marking_->heap_->tracer(),
GCTracer::Scope::MC_BACKGROUND_MARKING, GCTracer::Scope::MC_BACKGROUND_MARKING,
ThreadKind::kBackground); ThreadKind::kBackground);
concurrent_marking_->Run(delegate, code_flush_mode_, mark_compact_epoch_, concurrent_marking_->RunMajor(delegate, code_flush_mode_,
should_keep_ages_unchanged_); mark_compact_epoch_,
should_keep_ages_unchanged_);
} }
} }
...@@ -615,6 +618,34 @@ class ConcurrentMarking::JobTask : public v8::JobTask { ...@@ -615,6 +618,34 @@ class ConcurrentMarking::JobTask : public v8::JobTask {
const bool should_keep_ages_unchanged_; const bool should_keep_ages_unchanged_;
}; };
class ConcurrentMarking::JobTaskMinor : public v8::JobTask {
public:
explicit JobTaskMinor(ConcurrentMarking* concurrent_marking)
: concurrent_marking_(concurrent_marking) {}
~JobTaskMinor() override = default;
JobTaskMinor(const JobTaskMinor&) = delete;
JobTaskMinor& operator=(const JobTaskMinor&) = delete;
// v8::JobTask overrides.
void Run(JobDelegate* delegate) override {
if (delegate->IsJoiningThread()) {
// TRACE_GC is not needed here because the caller opens the right scope.
concurrent_marking_->RunMinor(delegate);
} else {
// TODO(v8:13012): TRACE_GC_EPOCH for MinorMC here.
concurrent_marking_->RunMinor(delegate);
}
}
size_t GetMaxConcurrency(size_t worker_count) const override {
return concurrent_marking_->GetMaxConcurrency(worker_count);
}
private:
ConcurrentMarking* concurrent_marking_;
};
ConcurrentMarking::ConcurrentMarking(Heap* heap, WeakObjects* weak_objects) ConcurrentMarking::ConcurrentMarking(Heap* heap, WeakObjects* weak_objects)
: heap_(heap), weak_objects_(weak_objects) { : heap_(heap), weak_objects_(weak_objects) {
#ifndef V8_ATOMIC_OBJECT_FIELD_WRITES #ifndef V8_ATOMIC_OBJECT_FIELD_WRITES
...@@ -634,10 +665,10 @@ ConcurrentMarking::ConcurrentMarking(Heap* heap, WeakObjects* weak_objects) ...@@ -634,10 +665,10 @@ ConcurrentMarking::ConcurrentMarking(Heap* heap, WeakObjects* weak_objects)
} }
} }
void ConcurrentMarking::Run(JobDelegate* delegate, void ConcurrentMarking::RunMajor(JobDelegate* delegate,
base::EnumSet<CodeFlushMode> code_flush_mode, base::EnumSet<CodeFlushMode> code_flush_mode,
unsigned mark_compact_epoch, unsigned mark_compact_epoch,
bool should_keep_ages_unchanged) { bool should_keep_ages_unchanged) {
size_t kBytesUntilInterruptCheck = 64 * KB; size_t kBytesUntilInterruptCheck = 64 * KB;
int kObjectsUntilInterruptCheck = 1000; int kObjectsUntilInterruptCheck = 1000;
uint8_t task_id = delegate->GetTaskId() + 1; uint8_t task_id = delegate->GetTaskId() + 1;
...@@ -660,7 +691,7 @@ void ConcurrentMarking::Run(JobDelegate* delegate, ...@@ -660,7 +691,7 @@ void ConcurrentMarking::Run(JobDelegate* delegate,
size_t marked_bytes = 0; size_t marked_bytes = 0;
Isolate* isolate = heap_->isolate(); Isolate* isolate = heap_->isolate();
if (FLAG_trace_concurrent_marking) { if (FLAG_trace_concurrent_marking) {
isolate->PrintWithTimestamp("Starting concurrent marking task %d\n", isolate->PrintWithTimestamp("Starting major concurrent marking task %d\n",
task_id); task_id);
} }
bool another_ephemeron_iteration = false; bool another_ephemeron_iteration = false;
...@@ -733,7 +764,7 @@ void ConcurrentMarking::Run(JobDelegate* delegate, ...@@ -733,7 +764,7 @@ void ConcurrentMarking::Run(JobDelegate* delegate,
marked_bytes); marked_bytes);
if (delegate->ShouldYield()) { if (delegate->ShouldYield()) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"),
"ConcurrentMarking::Run Preempted"); "ConcurrentMarking::RunMajor Preempted");
break; break;
} }
} }
...@@ -758,11 +789,15 @@ void ConcurrentMarking::Run(JobDelegate* delegate, ...@@ -758,11 +789,15 @@ void ConcurrentMarking::Run(JobDelegate* delegate,
} }
if (FLAG_trace_concurrent_marking) { if (FLAG_trace_concurrent_marking) {
heap_->isolate()->PrintWithTimestamp( heap_->isolate()->PrintWithTimestamp(
"Task %d concurrently marked %dKB in %.2fms\n", task_id, "Major task %d concurrently marked %dKB in %.2fms\n", task_id,
static_cast<int>(marked_bytes / KB), time_ms); static_cast<int>(marked_bytes / KB), time_ms);
} }
} }
void ConcurrentMarking::RunMinor(JobDelegate* delegate) {
// TODO(v8:13012): Implement
}
size_t ConcurrentMarking::GetMaxConcurrency(size_t worker_count) { size_t ConcurrentMarking::GetMaxConcurrency(size_t worker_count) {
size_t marking_items = marking_worklists_->shared()->Size(); size_t marking_items = marking_worklists_->shared()->Size();
marking_items += marking_worklists_->other()->Size(); marking_items += marking_worklists_->other()->Size();
...@@ -783,14 +818,20 @@ void ConcurrentMarking::ScheduleJob(GarbageCollector garbage_collector, ...@@ -783,14 +818,20 @@ void ConcurrentMarking::ScheduleJob(GarbageCollector garbage_collector,
DCHECK(IsStopped()); DCHECK(IsStopped());
garbage_collector_ = garbage_collector; garbage_collector_ = garbage_collector;
// TODO(v8:13012): Set marking_worklists_ based on GarbageCollector later. if (garbage_collector == GarbageCollector::MARK_COMPACTOR) {
marking_worklists_ = heap_->mark_compact_collector()->marking_worklists(); marking_worklists_ = heap_->mark_compact_collector()->marking_worklists();
job_handle_ = V8::GetCurrentPlatform()->PostJob(
job_handle_ = V8::GetCurrentPlatform()->PostJob( priority, std::make_unique<JobTaskMajor>(
priority, std::make_unique<JobTask>( this, heap_->mark_compact_collector()->epoch(),
this, heap_->mark_compact_collector()->epoch(), heap_->mark_compact_collector()->code_flush_mode(),
heap_->mark_compact_collector()->code_flush_mode(), heap_->ShouldCurrentGCKeepAgesUnchanged()));
heap_->ShouldCurrentGCKeepAgesUnchanged())); } else {
DCHECK(garbage_collector == GarbageCollector::MINOR_MARK_COMPACTOR);
marking_worklists_ =
heap_->minor_mark_compact_collector()->marking_worklists();
job_handle_ = V8::GetCurrentPlatform()->PostJob(
priority, std::make_unique<JobTaskMinor>(this));
}
DCHECK(job_handle_->IsValid()); DCHECK(job_handle_->IsValid());
} }
......
...@@ -102,9 +102,12 @@ class V8_EXPORT_PRIVATE ConcurrentMarking { ...@@ -102,9 +102,12 @@ class V8_EXPORT_PRIVATE ConcurrentMarking {
NativeContextStats native_context_stats; NativeContextStats native_context_stats;
char cache_line_padding[64]; char cache_line_padding[64];
}; };
class JobTask; class JobTaskMinor;
void Run(JobDelegate* delegate, base::EnumSet<CodeFlushMode> code_flush_mode, class JobTaskMajor;
unsigned mark_compact_epoch, bool should_keep_ages_unchanged); void RunMinor(JobDelegate* delegate);
void RunMajor(JobDelegate* delegate,
base::EnumSet<CodeFlushMode> code_flush_mode,
unsigned mark_compact_epoch, bool should_keep_ages_unchanged);
size_t GetMaxConcurrency(size_t worker_count); size_t GetMaxConcurrency(size_t worker_count);
bool IsWorkLeft(); bool IsWorkLeft();
void Resume(); void Resume();
......
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