[K/N] Remove fast paths phase checks in parallel mark ^KT-61741

This commit is contained in:
Alexander Shabalin
2023-09-06 13:44:24 +02:00
committed by Space Team
parent 190f7c4d30
commit 798e832943
2 changed files with 8 additions and 8 deletions
@@ -22,19 +22,19 @@ void spinWait(Cond&& until) {
} // namespace
bool gc::mark::MarkPacer::is(gc::mark::MarkPacer::Phase phase) const {
return phase_.load(std::memory_order_relaxed) == phase;
std::unique_lock lock(mutex_);
return phase_ == phase;
}
void gc::mark::MarkPacer::begin(gc::mark::MarkPacer::Phase phase) {
{
std::unique_lock lock(mutex_);
phase_.store(phase, std::memory_order_relaxed);
phase_ = phase;
}
cond_.notify_all();
}
void gc::mark::MarkPacer::wait(gc::mark::MarkPacer::Phase phase) {
if (phase_.load(std::memory_order_relaxed) >= phase) return;
std::unique_lock lock(mutex_);
cond_.wait(lock, [=]() { return phase_ >= phase; });
}
@@ -47,17 +47,18 @@ void gc::mark::MarkPacer::beginEpoch(uint64_t epoch) {
void gc::mark::MarkPacer::waitNewEpochReadyOrShutdown() const {
std::unique_lock lock(mutex_);
cond_.wait(lock, [this]() { return (phase_.load(std::memory_order_relaxed) >= Phase::kReady); });
cond_.wait(lock, [this]() { return phase_ >= Phase::kReady; });
}
void gc::mark::MarkPacer::waitEpochFinished(uint64_t currentEpoch) const {
std::unique_lock lock(mutex_);
cond_.wait(lock, [this, currentEpoch]() {
return is(Phase::kIdle) || is(Phase::kShutdown) || epoch_.load(std::memory_order_relaxed) > currentEpoch;
return phase_ == Phase::kIdle || phase_ == Phase::kShutdown || epoch_.load(std::memory_order_relaxed) > currentEpoch;
});
}
bool gc::mark::MarkPacer::acceptingNewWorkers() const {
std::unique_lock lock(mutex_);
return Phase::kReady <= phase_ && phase_ <= Phase::kParallelMark;
}
@@ -127,10 +128,9 @@ void gc::mark::ParallelMark::runMainInSTW() {
void gc::mark::ParallelMark::runOnMutator(mm::ThreadData& mutatorThread) {
if (compiler::gcMarkSingleThreaded() || !mutatorsCooperate_) return;
auto epoch = gcHandle().getEpoch();
auto parallelWorker = createWorker();
if (parallelWorker) {
GCLogDebug(epoch, "Mutator thread cooperates in marking");
GCLogDebug(gcHandle().getEpoch(), "Mutator thread cooperates in marking");
tryCollectRootSet(mutatorThread, *parallelWorker);
@@ -56,7 +56,7 @@ public:
private:
std::atomic<uint64_t> epoch_ = 0;
std::atomic<Phase> phase_ = Phase::kIdle;
Phase phase_ = Phase::kIdle;
mutable std::mutex mutex_;
mutable std::condition_variable cond_;
};