Improve cyclic collector turning off machinery
Ensure collector doesn't actually run when turned off.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
589cf8edda
commit
dc8c9d70c1
@@ -140,11 +140,11 @@ class CyclicCollector {
|
||||
toRelease_.clear();
|
||||
}
|
||||
|
||||
void terminate() {
|
||||
void terminate(bool enabled) {
|
||||
{
|
||||
Locker locker(&lock_);
|
||||
terminateCollector_ = true;
|
||||
shallRunCollector_ = true;
|
||||
if (enabled) shallRunCollector_ = true;
|
||||
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
|
||||
}
|
||||
// TODO: improve waiting for collector termination.
|
||||
@@ -322,12 +322,14 @@ class CyclicCollector {
|
||||
if (mainWorker_ == nullptr) mainWorker_ = worker;
|
||||
}
|
||||
|
||||
void removeWorker(void* worker) {
|
||||
void removeWorker(void* worker, bool enabled) {
|
||||
suggestLockRelease();
|
||||
Locker lock(&lock_);
|
||||
// When exiting the worker - we shall collect the cyclic garbage here.
|
||||
shallRunCollector_ = true;
|
||||
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
|
||||
if (enabled) {
|
||||
shallRunCollector_ = true;
|
||||
CHECK_CALL(pthread_cond_signal(&cond_), "Cannot signal collector")
|
||||
}
|
||||
currentAliveWorkers_--;
|
||||
}
|
||||
|
||||
@@ -436,11 +438,11 @@ void cyclicInit() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void cyclicDeinit() {
|
||||
void cyclicDeinit(bool enabled) {
|
||||
#if WITH_WORKERS
|
||||
RuntimeAssert(cyclicCollector != nullptr, "Must be inited");
|
||||
auto* local = cyclicCollector;
|
||||
local->terminate();
|
||||
local->terminate(enabled);
|
||||
cyclicCollector = nullptr;
|
||||
// Workaround data race with threads non-atomically reading and then using [cyclicCollector].
|
||||
// konanDestructInstance(local);
|
||||
@@ -458,11 +460,11 @@ void cyclicAddWorker(void* worker) {
|
||||
#endif // WITH_WORKERS
|
||||
}
|
||||
|
||||
void cyclicRemoveWorker(void* worker) {
|
||||
void cyclicRemoveWorker(void* worker, bool enabled) {
|
||||
#if WITH_WORKERS
|
||||
auto* local = cyclicCollector;
|
||||
if (local)
|
||||
local->removeWorker(worker);
|
||||
local->removeWorker(worker, enabled);
|
||||
#endif // WITH_WORKERS
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
struct ObjHeader;
|
||||
|
||||
void cyclicInit();
|
||||
void cyclicDeinit();
|
||||
void cyclicDeinit(bool enabled);
|
||||
void cyclicAddWorker(void* worker);
|
||||
void cyclicRemoveWorker(void* worker);
|
||||
void cyclicRemoveWorker(void* worker, bool enabled);
|
||||
void cyclicAddAtomicRoot(ObjHeader* obj);
|
||||
void cyclicRemoveAtomicRoot(ObjHeader* obj);
|
||||
void cyclicMutateAtomicRoot(ObjHeader* newValue);
|
||||
|
||||
@@ -1760,7 +1760,7 @@ void deinitMemory(MemoryState* memoryState) {
|
||||
if (atomicGet(&pendingDeinit) > 1) {
|
||||
checkLeaks = false;
|
||||
}
|
||||
cyclicDeinit();
|
||||
cyclicDeinit(g_hasCyclicCollector);
|
||||
#endif // USE_CYCLIC_GC
|
||||
}
|
||||
// Actual GC only implemented in strict memory model at the moment.
|
||||
@@ -2897,7 +2897,8 @@ void Kotlin_native_internal_GC_collect(KRef) {
|
||||
|
||||
void Kotlin_native_internal_GC_collectCyclic(KRef) {
|
||||
#if USE_CYCLIC_GC
|
||||
cyclicScheduleGarbageCollect();
|
||||
if (g_hasCyclicCollector)
|
||||
cyclicScheduleGarbageCollect();
|
||||
#else
|
||||
ThrowIllegalArgumentException();
|
||||
#endif
|
||||
@@ -3067,7 +3068,7 @@ void GC_RegisterWorker(void* worker) {
|
||||
|
||||
void GC_UnregisterWorker(void* worker) {
|
||||
#if USE_CYCLIC_GC
|
||||
cyclicRemoveWorker(worker);
|
||||
cyclicRemoveWorker(worker, g_hasCyclicCollector);
|
||||
#endif // USE_CYCLIC_GC
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user