Implement a bit more of GC object interface

This commit is contained in:
Alexander Shabalin
2021-05-19 07:29:27 +00:00
committed by Space
parent a3105da32e
commit 94076300ec
6 changed files with 38 additions and 27 deletions
@@ -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
@@ -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
@@ -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;
}
}
+1 -1
View File
@@ -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);
@@ -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<int64_t>(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);
@@ -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();
}