[K/N] Make GC scheduler less aggressive

^KT-48537

Merge-request: KT-MR-5319
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
This commit is contained in:
Alexander Shabalin
2022-01-19 19:11:15 +00:00
committed by Space
parent 3e7b1c027f
commit 69bb2587eb
7 changed files with 1146 additions and 123 deletions
+59 -27
View File
@@ -299,7 +299,7 @@ extern "C" void Kotlin_native_internal_GC_collect(ObjHeader*) {
extern "C" void Kotlin_native_internal_GC_collectCyclic(ObjHeader*) {
// TODO: Remove when legacy MM is gone.
ThrowIllegalArgumentException();
// Nothing to do
}
// TODO: Maybe a pair of suspend/resume or start/stop may be useful in the future?
@@ -321,46 +321,33 @@ extern "C" void Kotlin_native_internal_GC_start(ObjHeader*) {
// Nothing to do
}
extern "C" void Kotlin_native_internal_GC_setThreshold(ObjHeader*, int32_t value) {
if (value < 0) {
ThrowIllegalArgumentException();
}
mm::GlobalData::Instance().gc().gcSchedulerConfig().threshold = static_cast<size_t>(value);
extern "C" void Kotlin_native_internal_GC_setThreshold(ObjHeader*, KInt value) {
RuntimeAssert(value > 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().threshold = value;
}
extern "C" int32_t Kotlin_native_internal_GC_getThreshold(ObjHeader*) {
auto threshold = mm::GlobalData::Instance().gc().gcSchedulerConfig().threshold.load();
auto maxValue = std::numeric_limits<int32_t>::max();
if (threshold > static_cast<size_t>(maxValue)) {
return maxValue;
}
return static_cast<int32_t>(maxValue);
extern "C" KInt Kotlin_native_internal_GC_getThreshold(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().threshold.load();
}
extern "C" void Kotlin_native_internal_GC_setCollectCyclesThreshold(ObjHeader*, int64_t value) {
// TODO: Remove when legacy MM is gone.
ThrowIllegalArgumentException();
// Nothing to do
}
extern "C" int64_t Kotlin_native_internal_GC_getCollectCyclesThreshold(ObjHeader*) {
// TODO: Remove when legacy MM is gone.
ThrowIllegalArgumentException();
// Nothing to do
return -1;
}
extern "C" void Kotlin_native_internal_GC_setThresholdAllocations(ObjHeader*, int64_t value) {
if (value < 0) {
ThrowIllegalArgumentException();
}
mm::GlobalData::Instance().gc().gcSchedulerConfig().allocationThresholdBytes = static_cast<size_t>(value);
RuntimeAssert(value > 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().allocationThresholdBytes = value;
}
extern "C" int64_t Kotlin_native_internal_GC_getThresholdAllocations(ObjHeader*) {
auto threshold = mm::GlobalData::Instance().gc().gcSchedulerConfig().allocationThresholdBytes.load();
auto maxValue = std::numeric_limits<int64_t>::max();
if (threshold > static_cast<size_t>(maxValue)) {
return maxValue;
}
return static_cast<int64_t>(maxValue);
return mm::GlobalData::Instance().gc().gcSchedulerConfig().allocationThresholdBytes.load();
}
extern "C" void Kotlin_native_internal_GC_setTuneThreshold(ObjHeader*, KBoolean value) {
@@ -371,6 +358,51 @@ extern "C" KBoolean Kotlin_native_internal_GC_getTuneThreshold(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().autoTune.load();
}
extern "C" KLong Kotlin_native_internal_GC_getRegularGCIntervalMicroseconds(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().regularGcIntervalMicroseconds.load();
}
extern "C" void Kotlin_native_internal_GC_setRegularGCIntervalMicroseconds(ObjHeader*, KLong value) {
RuntimeAssert(value >= 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().regularGcIntervalMicroseconds = value;
}
extern "C" KLong Kotlin_native_internal_GC_getTargetHeapBytes(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().targetHeapBytes.load();
}
extern "C" void Kotlin_native_internal_GC_setTargetHeapBytes(ObjHeader*, KLong value) {
RuntimeAssert(value >= 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().targetHeapBytes = value;
}
extern "C" KDouble Kotlin_native_internal_GC_getTargetHeapUtilization(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().targetHeapUtilization.load();
}
extern "C" void Kotlin_native_internal_GC_setTargetHeapUtilization(ObjHeader*, KDouble value) {
RuntimeAssert(value > 0 && value <= 1, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().targetHeapUtilization = value;
}
extern "C" KLong Kotlin_native_internal_GC_getMaxHeapBytes(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().maxHeapBytes.load();
}
extern "C" void Kotlin_native_internal_GC_setMaxHeapBytes(ObjHeader*, KLong value) {
RuntimeAssert(value >= 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().maxHeapBytes = value;
}
extern "C" KLong Kotlin_native_internal_GC_getMinHeapBytes(ObjHeader*) {
return mm::GlobalData::Instance().gc().gcSchedulerConfig().minHeapBytes.load();
}
extern "C" void Kotlin_native_internal_GC_setMinHeapBytes(ObjHeader*, KLong value) {
RuntimeAssert(value >= 0, "Must be handled by the caller");
mm::GlobalData::Instance().gc().gcSchedulerConfig().minHeapBytes = value;
}
extern "C" OBJ_GETTER(Kotlin_native_internal_GC_detectCycles, ObjHeader*) {
// TODO: Remove when legacy MM is gone.
RETURN_OBJ(nullptr);
@@ -383,13 +415,13 @@ extern "C" OBJ_GETTER(Kotlin_native_internal_GC_findCycle, ObjHeader*, ObjHeader
extern "C" bool Kotlin_native_internal_GC_getCyclicCollector(ObjHeader* gc) {
// TODO: Remove when legacy MM is gone.
// Nothing to do.
return false;
}
extern "C" void Kotlin_native_internal_GC_setCyclicCollector(ObjHeader* gc, bool value) {
// TODO: Remove when legacy MM is gone.
if (value)
ThrowIllegalArgumentException();
// Nothing to do.
}
extern "C" bool Kotlin_Any_isShareable(ObjHeader* thiz) {