From db9361f8a2140ba25266d9bbfd3c721b776427fd Mon Sep 17 00:00:00 2001 From: SvyatoslavScherbina Date: Mon, 18 May 2020 19:34:47 +0300 Subject: [PATCH] Align docs with USE_CYCLIC_GC=0 (ed36f02c) Co-authored-by: ilya-g --- CONCURRENCY.md | 8 ++++---- .../src/main/kotlin/kotlin/native/concurrent/Atomics.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CONCURRENCY.md b/CONCURRENCY.md index dd87438904c..6018e9e5fc7 100644 --- a/CONCURRENCY.md +++ b/CONCURRENCY.md @@ -199,10 +199,10 @@ To achieve such functionality Kotlin/Native runtime provides two related classes `kotlin.native.concurrent.AtomicReference` and `kotlin.native.concurrent.FreezableAtomicReference`. Atomic reference holds reference to a frozen or immutable object, and its value could be updated by set or compare-and-swap operation. Thus, dedicated set of objects could be used to create mutable shared object graphs -(of immutable objects). Cycles in the shared memory could be created using atomic references, and to collect them -Kotlin/Native runtime has special concurrent cycle collector, concurrently analyzing cyclic data rooted in atomic references. -When cycle of no longer used objects is detected, collector zeroes out reference stored in atomic reference and thus -allows cycle to be collected. +(of immutable objects). Cycles in the shared memory could be created using atomic references. +Kotlin/Native runtime doesn't support garbage collecting cyclic data when reference cycle goes through +`AtomicReference` or frozen `FreezableAtomicReference`. So to avoid memory leaks atomic references +that are potentially parts of shared cyclic data should be zeroed out once no longer needed. If atomic reference value is attempted to be set to non-frozen value runtime exception is thrown. diff --git a/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt index e9d1232aa38..52ba8af64a8 100644 --- a/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt @@ -216,7 +216,7 @@ private fun debugString(value: Any?): String { /** * An atomic reference to a frozen Kotlin object. Can be used in concurrent scenarious * but frequently shall be of nullable type and be zeroed out once no longer needed. - * Asynchronous cycle collector takes care of cyclic references of that kind. + * Otherwise memory leak could happen if the atomic reference is a part of a reference cycle. */ @Frozen @LeakDetectorCandidate @@ -292,8 +292,8 @@ public class AtomicReference { /** * An atomic reference to a Kotlin object. Can be used in concurrent scenarious, but must be frozen first, - * otherwise behaves as regular box for the value. Asynchronous cycle collector helps to collect the - * cyclic garbage going through frozen instances of `FreezableAtomicReference`. + * otherwise behaves as regular box for the value. If frozen, shall be zeroed out once no longer needed. + * Otherwise memory leak could happen if atomic reference is a part of a reference cycle. */ @NoReorderFields @LeakDetectorCandidate @@ -377,4 +377,4 @@ public class FreezableAtomicReference(private var value_: T) { @SymbolName("Kotlin_AtomicReference_compareAndSet") private external fun compareAndSetImpl(expected: Any?, new: Any?): Boolean -} \ No newline at end of file +}