[K/N] Optimize safepoint implementation
This commit is contained in:
@@ -99,16 +99,23 @@ void gc::SameThreadMarkAndSweep::ThreadData::OnOOM(size_t size) noexcept {
|
||||
PerformFullGC();
|
||||
}
|
||||
|
||||
void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noexcept {
|
||||
size_t counterOverhead = gc_.GetThreshold() == 0 ? safePointsCounter_ : safePointsCounter_ % gc_.GetThreshold();
|
||||
if (threadData_.suspensionData().suspendIfRequested()) {
|
||||
safePointsCounter_ = 0;
|
||||
} else if (counterOverhead + weight >= gc_.GetThreshold() && konan::getTimeMicros() - timeOfLastGcUs_ >= gc_.GetCooldownThresholdUs()) {
|
||||
void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegularSlowPath() noexcept {
|
||||
safePointsCounter_ = 0;
|
||||
if (konan::getTimeMicros() - timeOfLastGcUs_ >= gc_.GetCooldownThresholdUs()) {
|
||||
timeOfLastGcUs_ = konan::getTimeMicros();
|
||||
safePointsCounter_ = 0;
|
||||
PerformFullGC();
|
||||
}
|
||||
safePointsCounter_ += weight;
|
||||
}
|
||||
|
||||
void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noexcept {
|
||||
if (threadData_.suspensionData().suspendIfRequested()) {
|
||||
safePointsCounter_ = 0;
|
||||
} else {
|
||||
safePointsCounter_ += weight;
|
||||
if (safePointsCounter_ >= gc_.GetThreshold()) {
|
||||
SafePointRegularSlowPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gc::SameThreadMarkAndSweep::SameThreadMarkAndSweep() noexcept {
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
void SafePointRegular(size_t weight) noexcept;
|
||||
void SafePointRegularSlowPath() noexcept;
|
||||
|
||||
SameThreadMarkAndSweep& gc_;
|
||||
mm::ThreadData& threadData_;
|
||||
|
||||
@@ -46,12 +46,17 @@ std::condition_variable gSuspendsionCondVar;
|
||||
|
||||
NO_EXTERNAL_CALLS_CHECK bool kotlin::mm::ThreadSuspensionData::suspendIfRequested() noexcept {
|
||||
if (IsThreadSuspensionRequested()) {
|
||||
std::unique_lock lock(gSuspensionMutex);
|
||||
if (IsThreadSuspensionRequested()) {
|
||||
AutoReset scopedAssign(&suspended_, true);
|
||||
gSuspendsionCondVar.wait(lock, []() { return !IsThreadSuspensionRequested(); });
|
||||
return true;
|
||||
}
|
||||
return suspendIfRequestedSlowPath();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NO_EXTERNAL_CALLS_CHECK bool kotlin::mm::ThreadSuspensionData::suspendIfRequestedSlowPath() noexcept {
|
||||
std::unique_lock lock(gSuspensionMutex);
|
||||
if (IsThreadSuspensionRequested()) {
|
||||
AutoReset scopedAssign(&suspended_, true);
|
||||
gSuspendsionCondVar.wait(lock, []() { return !IsThreadSuspensionRequested(); });
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
private:
|
||||
std::atomic<ThreadState> state_;
|
||||
std::atomic<bool> suspended_;
|
||||
bool suspendIfRequestedSlowPath() noexcept;
|
||||
};
|
||||
|
||||
bool IsThreadSuspensionRequested() noexcept;
|
||||
|
||||
Reference in New Issue
Block a user