From 39c0d3991c6123cdf39ca8f1b4ea40161a078770 Mon Sep 17 00:00:00 2001 From: Ulan Degenbaev Date: Wed, 6 Dec 2017 16:35:18 +0100 Subject: [PATCH] [heap] Add tracing scope to parallel evacuation. Bug: chromium:758183 Change-Id: I626be7a8f42662a657595c1147a6aa8cb53391fa Reviewed-on: https://chromium-review.googlesource.com/808941 Commit-Queue: Ulan Degenbaev Reviewed-by: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#49902} --- src/heap-symbols.h | 12 +++++------ src/heap/gc-tracer.h | 19 ++++++++---------- src/heap/mark-compact.cc | 43 ++++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/heap-symbols.h b/src/heap-symbols.h index 4a036d9b67..0f1d771923 100644 --- a/src/heap-symbols.h +++ b/src/heap-symbols.h @@ -357,13 +357,13 @@ F(SCAVENGER_SCAVENGE_WEAK) #define TRACER_BACKGROUND_SCOPES(F) \ - F(SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL) \ - F(MINOR_MC_BACKGROUND_MARKING) \ - F(MINOR_MC_BACKGROUND_EVACUATE_COPY) \ - F(MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS) \ + F(MC_BACKGROUND_EVACUATE_COPY) \ + F(MC_BACKGROUND_EVACUATE_UPDATE_POINTERS) \ F(MC_BACKGROUND_MARKING) \ F(MC_BACKGROUND_SWEEPING) \ - F(MC_BACKGROUND_EVACUATE_COPY) \ - F(MC_BACKGROUND_EVACUATE_UPDATE_POINTERS) + F(MINOR_MC_BACKGROUND_EVACUATE_COPY) \ + F(MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS) \ + F(MINOR_MC_BACKGROUND_MARKING) \ + F(SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL) #endif // V8_HEAP_SYMBOLS_H_ diff --git a/src/heap/gc-tracer.h b/src/heap/gc-tracer.h index 22a58cd11c..ceb1476e4f 100644 --- a/src/heap/gc-tracer.h +++ b/src/heap/gc-tracer.h @@ -70,11 +70,10 @@ class V8_EXPORT_PRIVATE GCTracer { FIRST_SCOPE = MC_INCREMENTAL, NUMBER_OF_INCREMENTAL_SCOPES = LAST_INCREMENTAL_SCOPE - FIRST_INCREMENTAL_SCOPE + 1, - FIRST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_MARKING, - LAST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, - FIRST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, - LAST_MINOR_GC_BACKGROUND_SCOPE = - MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS + FIRST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_EVACUATE_COPY, + LAST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_SWEEPING, + FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY, + LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL }; Scope(GCTracer* tracer, ScopeId scope); @@ -98,12 +97,10 @@ class V8_EXPORT_PRIVATE GCTracer { TRACER_BACKGROUND_SCOPES(DEFINE_SCOPE) #undef DEFINE_SCOPE NUMBER_OF_SCOPES, - - FIRST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_MARKING, - LAST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, - FIRST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, - LAST_MINOR_GC_BACKGROUND_SCOPE = - MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS + FIRST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_EVACUATE_COPY, + LAST_MC_BACKGROUND_SCOPE = MC_BACKGROUND_SWEEPING, + FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY, + LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL }; BackgroundScope(GCTracer* tracer, ScopeId scope); ~BackgroundScope(); diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index b93a451088..73df6eb587 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -3031,6 +3031,8 @@ class Evacuator : public Malloced { // to be called from the main thread. inline void Finalize(); + virtual GCTracer::BackgroundScope::ScopeId GetBackgroundTracingScope() = 0; + protected: static const int kInitialLocalPretenuringFeedbackCapacity = 256; @@ -3110,6 +3112,10 @@ class FullEvacuator : public Evacuator { RecordMigratedSlotVisitor* record_visitor) : Evacuator(collector->heap(), record_visitor), collector_(collector) {} + GCTracer::BackgroundScope::ScopeId GetBackgroundTracingScope() override { + return GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY; + } + protected: void RawEvacuatePage(Page* page, intptr_t* live_bytes) override; @@ -3166,6 +3172,10 @@ class YoungGenerationEvacuator : public Evacuator { RecordMigratedSlotVisitor* record_visitor) : Evacuator(collector->heap(), record_visitor), collector_(collector) {} + GCTracer::BackgroundScope::ScopeId GetBackgroundTracingScope() override { + return GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY; + } + protected: void RawEvacuatePage(Page* page, intptr_t* live_bytes) override; @@ -3243,10 +3253,13 @@ class PageEvacuationItem : public ItemParallelJob::Item { class PageEvacuationTask : public ItemParallelJob::Task { public: PageEvacuationTask(Isolate* isolate, Evacuator* evacuator) - : ItemParallelJob::Task(isolate), evacuator_(evacuator) {} + : ItemParallelJob::Task(isolate), + evacuator_(evacuator), + tracer_(isolate->heap()->tracer()) {} void RunInParallel() override { - // TODO(ulan): add GCTracer background scope. + GCTracer::BackgroundScope scope(tracer_, + evacuator_->GetBackgroundTracingScope()); PageEvacuationItem* item = nullptr; while ((item = GetItem()) != nullptr) { evacuator_->EvacuatePage(item->page()); @@ -3256,6 +3269,7 @@ class PageEvacuationTask : public ItemParallelJob::Task { private: Evacuator* evacuator_; + GCTracer* tracer_; }; template @@ -3554,17 +3568,24 @@ class UpdatingItem : public ItemParallelJob::Item { class PointersUpdatingTask : public ItemParallelJob::Task { public: - explicit PointersUpdatingTask(Isolate* isolate) - : ItemParallelJob::Task(isolate) {} + explicit PointersUpdatingTask(Isolate* isolate, + GCTracer::BackgroundScope::ScopeId scope) + : ItemParallelJob::Task(isolate), + tracer_(isolate->heap()->tracer()), + scope_(scope) {} void RunInParallel() override { - // TODO(ulan): add GCTracer background scope. + GCTracer::BackgroundScope scope(tracer_, scope_); UpdatingItem* item = nullptr; while ((item = GetItem()) != nullptr) { item->Process(); item->MarkFinished(); } }; + + private: + GCTracer* tracer_; + GCTracer::BackgroundScope::ScopeId scope_; }; template @@ -3955,7 +3976,9 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() { const int to_space_tasks = CollectToSpaceUpdatingItems(&updating_job); const int num_tasks = Max(to_space_tasks, remembered_set_tasks); for (int i = 0; i < num_tasks; i++) { - updating_job.AddTask(new PointersUpdatingTask(isolate())); + updating_job.AddTask(new PointersUpdatingTask( + isolate(), + GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS)); } updating_job.Run(); } @@ -3985,7 +4008,9 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() { const int num_tasks = Max(array_buffer_pages, remembered_set_tasks); if (num_tasks > 0) { for (int i = 0; i < num_tasks; i++) { - updating_job.AddTask(new PointersUpdatingTask(isolate())); + updating_job.AddTask(new PointersUpdatingTask( + isolate(), + GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS)); } updating_job.Run(); heap()->array_buffer_collector()->FreeAllocationsOnBackgroundThread(); @@ -4036,7 +4061,9 @@ void MinorMarkCompactCollector::UpdatePointersAfterEvacuation() { remembered_set_pages, old_to_new_slots_); const int num_tasks = Max(to_space_tasks, remembered_set_tasks); for (int i = 0; i < num_tasks; i++) { - updating_job.AddTask(new PointersUpdatingTask(isolate())); + updating_job.AddTask(new PointersUpdatingTask( + isolate(), GCTracer::BackgroundScope:: + MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS)); } {