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)
black_allocation_(false),
have_code_to_deoptimize_(false),
sweeper_(new Sweeper(heap, non_atomic_marking_state())) {
old_to_new_slots_ = -1;
}
MarkCompactCollector::~MarkCompactCollector() { delete sweeper_; }
......@@ -3474,8 +3473,9 @@ class PointersUpdatingJob : public v8::JobTask {
public:
explicit PointersUpdatingJob(
Isolate* isolate,
std::vector<std::unique_ptr<UpdatingItem>> updating_items, int slots,
GCTracer::Scope::ScopeId scope, GCTracer::Scope::ScopeId background_scope)
std::vector<std::unique_ptr<UpdatingItem>> updating_items,
base::Optional<size_t> slots, GCTracer::Scope::ScopeId scope,
GCTracer::Scope::ScopeId background_scope)
: updating_items_(std::move(updating_items)),
remaining_updating_items_(updating_items_.size()),
generator_(updating_items_.size()),
......@@ -3518,19 +3518,22 @@ class PointersUpdatingJob : public v8::JobTask {
size_t wanted_tasks = items;
// Limit the number of update tasks as task creation often dominates the
// actual work that is being done.
if (slots_ >= 0) {
if (slots_ && *slots_ > 0) {
// Round up to ensure enough workers for all items.
wanted_tasks =
std::min<size_t>(items, (slots_ + kSlotsPerTask - 1) / kSlotsPerTask);
wanted_tasks = std::min<size_t>(
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:
std::vector<std::unique_ptr<UpdatingItem>> updating_items_;
std::atomic<size_t> remaining_updating_items_{0};
IndexGenerator generator_;
const int slots_;
const base::Optional<size_t> slots_;
GCTracer* tracer_;
GCTracer::Scope::ScopeId scope_;
......
......@@ -200,8 +200,7 @@ class MarkCompactCollectorBase {
inline Isolate* isolate();
protected:
explicit MarkCompactCollectorBase(Heap* heap)
: heap_(heap), old_to_new_slots_(0) {}
explicit MarkCompactCollectorBase(Heap* heap) : heap_(heap) {}
// Marking operations for objects reachable from roots.
virtual void MarkLiveObjects() = 0;
......@@ -240,8 +239,7 @@ class MarkCompactCollectorBase {
Heap* heap_;
// Number of old to new slots. Should be computed during MarkLiveObjects.
// -1 indicates that the value couldn't be computed.
int old_to_new_slots_;
base::Optional<size_t> old_to_new_slots_;
};
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