diff --git a/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp b/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp index a5513d22542..b7ac98b46d9 100644 --- a/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp +++ b/kotlin-native/runtime/src/gc/noop/cpp/NoOpGC.hpp @@ -47,9 +47,13 @@ public: void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; } size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; } + void SetAutoTune(bool value) noexcept { autoTune_ = value; } + bool GetAutoTune() noexcept { return autoTune_; } + private: size_t threshold_ = 0; size_t allocationThresholdBytes_ = 0; + bool autoTune_ = false; }; } // namespace gc diff --git a/kotlin-native/runtime/src/gc/stms/cpp/SingleThreadMarkAndSweep.hpp b/kotlin-native/runtime/src/gc/stms/cpp/SingleThreadMarkAndSweep.hpp index 117829f0e8c..d8eadc6b9d0 100644 --- a/kotlin-native/runtime/src/gc/stms/cpp/SingleThreadMarkAndSweep.hpp +++ b/kotlin-native/runtime/src/gc/stms/cpp/SingleThreadMarkAndSweep.hpp @@ -63,6 +63,9 @@ public: void SetAllocationThresholdBytes(size_t value) noexcept { allocationThresholdBytes_ = value; } size_t GetAllocationThresholdBytes() noexcept { return allocationThresholdBytes_; } + void SetAutoTune(bool value) noexcept { autoTune_ = value; } + bool GetAutoTune() noexcept { return autoTune_; } + private: void PerformFullGC() noexcept; @@ -70,6 +73,7 @@ private: size_t threshold_ = 1000; size_t allocationThresholdBytes_ = 10000; + bool autoTune_ = false; }; } // namespace gc diff --git a/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp b/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp index 7c7300859d0..f5d85c8e3ae 100644 --- a/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp +++ b/kotlin-native/runtime/src/legacymm/cpp/Memory.cpp @@ -3537,7 +3537,7 @@ KLong Kotlin_native_internal_GC_getThresholdAllocations(KRef) { #endif } -void Kotlin_native_internal_GC_setTuneThreshold(KRef, KInt value) { +void Kotlin_native_internal_GC_setTuneThreshold(KRef, KBoolean value) { #if USE_GC setTuneGCThreshold(value); #endif @@ -3736,4 +3736,4 @@ MemoryState* kotlin::mm::GetMemoryState() { kotlin::ThreadState kotlin::GetThreadState(MemoryState* thread) noexcept { // Assume that we are always in the Runnable thread state. return ThreadState::kRunnable; -} \ No newline at end of file +} diff --git a/kotlin-native/runtime/src/main/cpp/Memory.h b/kotlin-native/runtime/src/main/cpp/Memory.h index 3773379de46..61b1b0937ae 100644 --- a/kotlin-native/runtime/src/main/cpp/Memory.h +++ b/kotlin-native/runtime/src/main/cpp/Memory.h @@ -287,7 +287,7 @@ void Kotlin_native_internal_GC_setCollectCyclesThreshold(ObjHeader*, int64_t val int64_t Kotlin_native_internal_GC_getCollectCyclesThreshold(ObjHeader*); void Kotlin_native_internal_GC_setThresholdAllocations(ObjHeader*, int64_t value); int64_t Kotlin_native_internal_GC_getThresholdAllocations(ObjHeader*); -void Kotlin_native_internal_GC_setTuneThreshold(ObjHeader*, int32_t value); +void Kotlin_native_internal_GC_setTuneThreshold(ObjHeader*, bool value); bool Kotlin_native_internal_GC_getTuneThreshold(ObjHeader*); OBJ_GETTER(Kotlin_native_internal_GC_detectCycles, ObjHeader*); OBJ_GETTER(Kotlin_native_internal_GC_findCycle, ObjHeader*, ObjHeader* root); diff --git a/kotlin-native/runtime/src/mm/cpp/Memory.cpp b/kotlin-native/runtime/src/mm/cpp/Memory.cpp index 42cd2469dd3..e918b2171af 100644 --- a/kotlin-native/runtime/src/mm/cpp/Memory.cpp +++ b/kotlin-native/runtime/src/mm/cpp/Memory.cpp @@ -264,6 +264,25 @@ extern "C" void Kotlin_native_internal_GC_collectCyclic(ObjHeader*) { ThrowIllegalArgumentException(); } +// TODO: Maybe a pair of suspend/resume or start/stop may be useful in the future? +// The other pair is likely to be removed. + +extern "C" void Kotlin_native_internal_GC_suspend(ObjHeader*) { + // Nothing to do +} + +extern "C" void Kotlin_native_internal_GC_resume(ObjHeader*) { + // Nothing to do +} + +extern "C" void Kotlin_native_internal_GC_stop(ObjHeader*) { + // Nothing to do +} + +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(); @@ -306,6 +325,14 @@ extern "C" int64_t Kotlin_native_internal_GC_getThresholdAllocations(ObjHeader*) return static_cast(maxValue); } +extern "C" void Kotlin_native_internal_GC_setTuneThreshold(ObjHeader*, KBoolean value) { + mm::GlobalData::Instance().gc().SetAutoTune(value); +} + +extern "C" KBoolean Kotlin_native_internal_GC_getTuneThreshold(ObjHeader*) { + return mm::GlobalData::Instance().gc().GetAutoTune(); +} + extern "C" OBJ_GETTER(Kotlin_native_internal_GC_detectCycles, ObjHeader*) { // TODO: Remove when legacy MM is gone. RETURN_OBJ(nullptr); diff --git a/kotlin-native/runtime/src/mm/cpp/Stubs.cpp b/kotlin-native/runtime/src/mm/cpp/Stubs.cpp index c0fa2773c45..dbd57d73909 100644 --- a/kotlin-native/runtime/src/mm/cpp/Stubs.cpp +++ b/kotlin-native/runtime/src/mm/cpp/Stubs.cpp @@ -9,30 +9,6 @@ extern "C" { -void Kotlin_native_internal_GC_suspend(ObjHeader*) { - TODO(); -} - -void Kotlin_native_internal_GC_resume(ObjHeader*) { - TODO(); -} - -void Kotlin_native_internal_GC_stop(ObjHeader*) { - TODO(); -} - -void Kotlin_native_internal_GC_start(ObjHeader*) { - TODO(); -} - -void Kotlin_native_internal_GC_setTuneThreshold(ObjHeader*, int32_t value) { - TODO(); -} - -bool Kotlin_native_internal_GC_getTuneThreshold(ObjHeader*) { - TODO(); -} - bool TryAddHeapRef(const ObjHeader* object) { TODO(); }