Commit f6ae3c47 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Ensure GetMaxConcurrency() > 0 when there is still work left

GetMaxConcurrency() needs to return a value greater than 0 when there
is work left. When the return value is 0, no more items are processed.

With Minor MC it could happen that GetMaxConcurrency() returned 0 when
there were no old-to-new-slots even though there were still items left
to process. This CL fixes this and adds a DCHECK to ensure this doesn't
happen again.

Change-Id: Ia971c232564bcb0b0d305e76371a3a8e82f46229
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2593247
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71768}
parent 6544a1e4
...@@ -414,7 +414,6 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap) ...@@ -414,7 +414,6 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap)
black_allocation_(false), black_allocation_(false),
have_code_to_deoptimize_(false), have_code_to_deoptimize_(false),
sweeper_(new Sweeper(heap, non_atomic_marking_state())) { sweeper_(new Sweeper(heap, non_atomic_marking_state())) {
old_to_new_slots_ = -1;
} }
MarkCompactCollector::~MarkCompactCollector() { delete sweeper_; } MarkCompactCollector::~MarkCompactCollector() { delete sweeper_; }
...@@ -3474,8 +3473,9 @@ class PointersUpdatingJob : public v8::JobTask { ...@@ -3474,8 +3473,9 @@ class PointersUpdatingJob : public v8::JobTask {
public: public:
explicit PointersUpdatingJob( explicit PointersUpdatingJob(
Isolate* isolate, Isolate* isolate,
std::vector<std::unique_ptr<UpdatingItem>> updating_items, int slots, std::vector<std::unique_ptr<UpdatingItem>> updating_items,
GCTracer::Scope::ScopeId scope, GCTracer::Scope::ScopeId background_scope) base::Optional<size_t> slots, GCTracer::Scope::ScopeId scope,
GCTracer::Scope::ScopeId background_scope)
: updating_items_(std::move(updating_items)), : updating_items_(std::move(updating_items)),
remaining_updating_items_(updating_items_.size()), remaining_updating_items_(updating_items_.size()),
generator_(updating_items_.size()), generator_(updating_items_.size()),
...@@ -3518,19 +3518,22 @@ class PointersUpdatingJob : public v8::JobTask { ...@@ -3518,19 +3518,22 @@ class PointersUpdatingJob : public v8::JobTask {
size_t wanted_tasks = items; size_t wanted_tasks = items;
// Limit the number of update tasks as task creation often dominates the // Limit the number of update tasks as task creation often dominates the
// actual work that is being done. // actual work that is being done.
if (slots_ >= 0) { if (slots_ && *slots_ > 0) {
// Round up to ensure enough workers for all items. // Round up to ensure enough workers for all items.
wanted_tasks = wanted_tasks = std::min<size_t>(
std::min<size_t>(items, (slots_ + kSlotsPerTask - 1) / kSlotsPerTask); items, (*slots_ + kSlotsPerTask - 1) / kSlotsPerTask);
} }
return std::min<size_t>(kMaxPointerUpdateTasks, wanted_tasks); size_t max_concurrency =
std::min<size_t>(kMaxPointerUpdateTasks, wanted_tasks);
DCHECK_IMPLIES(items > 0, max_concurrency > 0);
return max_concurrency;
} }
private: private:
std::vector<std::unique_ptr<UpdatingItem>> updating_items_; std::vector<std::unique_ptr<UpdatingItem>> updating_items_;
std::atomic<size_t> remaining_updating_items_{0}; std::atomic<size_t> remaining_updating_items_{0};
IndexGenerator generator_; IndexGenerator generator_;
const int slots_; const base::Optional<size_t> slots_;
GCTracer* tracer_; GCTracer* tracer_;
GCTracer::Scope::ScopeId scope_; GCTracer::Scope::ScopeId scope_;
......
...@@ -200,8 +200,7 @@ class MarkCompactCollectorBase { ...@@ -200,8 +200,7 @@ class MarkCompactCollectorBase {
inline Isolate* isolate(); inline Isolate* isolate();
protected: protected:
explicit MarkCompactCollectorBase(Heap* heap) explicit MarkCompactCollectorBase(Heap* heap) : heap_(heap) {}
: heap_(heap), old_to_new_slots_(0) {}
// Marking operations for objects reachable from roots. // Marking operations for objects reachable from roots.
virtual void MarkLiveObjects() = 0; virtual void MarkLiveObjects() = 0;
...@@ -240,8 +239,7 @@ class MarkCompactCollectorBase { ...@@ -240,8 +239,7 @@ class MarkCompactCollectorBase {
Heap* heap_; Heap* heap_;
// Number of old to new slots. Should be computed during MarkLiveObjects. // Number of old to new slots. Should be computed during MarkLiveObjects.
// -1 indicates that the value couldn't be computed. base::Optional<size_t> old_to_new_slots_;
int old_to_new_slots_;
}; };
class MinorMarkingState final class MinorMarkingState final
......
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