[K/N] Updated deprecations for native atomics

* Removed deprecated methods from the new atomics in kotlin.concurrent
* Changed deprecation level from WARNING to ERROR for the old atomics in kotlin.native.concurrent
* Removed FreezingIsDeprecated annotation from kotlin.concurrent.AtomicReference

See KT-58123

Merge-request: KT-MR-10650
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
This commit is contained in:
mvicsokolova
2023-08-22 13:42:12 +00:00
committed by Space Team
parent ffbff15839
commit 5f431e4e87
21 changed files with 57 additions and 96 deletions
@@ -2,7 +2,7 @@
import kotlinx.cinterop.*
import kt44283.*
import kotlin.native.concurrent.AtomicInt
import kotlin.concurrent.AtomicInt
import kotlin.test.*
val callbackCounter = AtomicInt(0)
@@ -14,7 +14,7 @@ fun main() {
memScoped {
println("Hello, Kotlin/Native! ${it.ptr.pointed.d}")
}
callbackCounter.increment()
callbackCounter.incrementAndGet()
}
assertEquals(0, callbackCounter.value)
@@ -1,6 +1,7 @@
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import leakMemory.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.Platform
import kotlin.test.*
@@ -1,6 +1,7 @@
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import leakMemory.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.Platform
import kotlin.test.*
@@ -6,6 +6,7 @@
import objclib.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.internal.test.testLauncherEntryPoint
import kotlin.system.exitProcess
@@ -1,5 +1,6 @@
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class)
import kotlin.concurrent.AtomicReference
import kotlin.native.concurrent.*
import kotlinx.cinterop.*
import kotlin.test.*
@@ -9,6 +9,7 @@
package conversions
import kotlin.concurrent.AtomicReference
import kotlin.native.concurrent.freeze
import kotlin.native.concurrent.isFrozen
import kotlin.native.internal.ObjCErrorException
@@ -946,7 +947,7 @@ class TestStringConversion {
lateinit var str: Any
}
fun foo(a: kotlin.native.concurrent.AtomicReference<*>) {}
fun foo(a: kotlin.concurrent.AtomicReference<*>) {}
interface GH3825 {
@Throws(MyException::class) fun call0(callback: () -> Boolean)
@@ -137,7 +137,7 @@ fun test6() {
@Suppress("DEPRECATION_ERROR")
fun test7() {
val ref = FreezableAtomicReference(Array(1) { "hey" })
val ref = AtomicReference(Array(1) { "hey" })
ref.value[0] = "ho"
assertEquals(ref.value[0], "ho")
ref.value = Array(1) { "po" }
@@ -8,6 +8,7 @@
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlin.native.runtime.GC
@@ -37,7 +38,7 @@ fun main() {
val atomics = Array(atomicsCount) {
AtomicReference<Any?>(Any().freeze())
}
createdCount.increment()
createdCount.incrementAndGet()
while (canStartReading.value == 0) {}
GC.collect()
atomics.all { it.value != null }
@@ -10,6 +10,8 @@ package runtime.basic.cleaner_basic
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.AtomicNativePtr
import kotlin.native.concurrent.*
import kotlin.native.ref.WeakReference
import kotlin.native.ref.Cleaner
@@ -6,6 +6,7 @@
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlin.native.ref.Cleaner
@@ -9,6 +9,8 @@ package runtime.basic.cleaner_workers
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.AtomicReference
import kotlin.native.concurrent.*
import kotlin.native.ref.WeakReference
import kotlin.native.ref.Cleaner
@@ -7,10 +7,9 @@
package runtime.basic.initializers6
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.concurrent.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.*
import kotlin.native.concurrent.*
val aWorkerId = AtomicInt(0)
val bWorkersCount = 3
@@ -8,6 +8,8 @@ package runtime.concurrent.worker_bound_reference0
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.AtomicReference
import kotlin.native.concurrent.*
import kotlin.native.*
import kotlin.native.ref.WeakReference
@@ -108,7 +110,7 @@ fun testGlobalAccessOnWorkerFrozenBeforeAccess() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { semaphore }) { semaphore ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
@@ -118,7 +120,7 @@ fun testGlobalAccessOnWorkerFrozenBeforeAccess() {
while (semaphore.value < 1) {
}
global5.value.freeze()
semaphore.increment()
semaphore.incrementAndGet()
val value = future.result
assertEquals(3, value)
@@ -135,7 +137,7 @@ fun testGlobalModification() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { semaphore }) { semaphore ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
global6
@@ -144,7 +146,7 @@ fun testGlobalModification() {
while (semaphore.value < 1) {
}
global6.value.a = 4
semaphore.increment()
semaphore.incrementAndGet()
val value = future.result
assertEquals(4, value.value.a)
@@ -262,7 +264,7 @@ fun testLocalAccessOnWorkerFrozenBeforeAccessFrozen() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { Pair(local, semaphore) }) { (local, semaphore) ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
@@ -272,7 +274,7 @@ fun testLocalAccessOnWorkerFrozenBeforeAccessFrozen() {
while (semaphore.value < 1) {
}
local.value.freeze()
semaphore.increment()
semaphore.incrementAndGet()
val value = future.result
assertEquals(3, value)
@@ -321,7 +323,7 @@ fun testLocalModificationFrozen() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { Pair(local, semaphore) }) { (local, semaphore) ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
local
@@ -330,7 +332,7 @@ fun testLocalModificationFrozen() {
while (semaphore.value < 1) {
}
local.value.a = 4
semaphore.increment()
semaphore.incrementAndGet()
val value = future.result
assertEquals(4, value.value.a)
@@ -432,9 +434,9 @@ fun testLocalAccessWithWrapperFrozen() {
worker.requestTermination().result
}
fun getOwnerAndWeaks(initial: Int): Triple<FreezableAtomicReference<WorkerBoundReference<A>?>, WeakReference<WorkerBoundReference<A>>, WeakReference<A>> {
fun getOwnerAndWeaks(initial: Int): Triple<AtomicReference<WorkerBoundReference<A>?>, WeakReference<WorkerBoundReference<A>>, WeakReference<A>> {
val ref = WorkerBoundReference(A(initial))
val refOwner: FreezableAtomicReference<WorkerBoundReference<A>?> = FreezableAtomicReference(ref)
val refOwner: AtomicReference<WorkerBoundReference<A>?> = AtomicReference(ref)
val refWeak = WeakReference(ref)
val refValueWeak = WeakReference(ref.value)
@@ -485,7 +487,7 @@ fun collectInWorkerFrozen(worker: Worker, semaphore: AtomicInt): Pair<WeakRefere
val (refOwner, _, refValueWeak) = getOwnerAndWeaksFrozen(3)
val future = worker.execute(TransferMode.SAFE, { Pair(refOwner, semaphore) }) { (refOwner, semaphore) ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
@@ -510,7 +512,7 @@ fun testCollectInWorkerFrozen() {
val worker = Worker.start()
val (refValueWeak, future) = collectInWorkerFrozen(worker, semaphore)
semaphore.increment()
semaphore.incrementAndGet()
future.result
// At this point WorkerBoundReference no longer has a reference, so it's referent is destroyed.
@@ -524,7 +526,7 @@ fun doNotCollectInWorkerFrozen(worker: Worker, semaphore: AtomicInt): Future<Wor
val ref = WorkerBoundReference(A(3)).freeze()
return worker.execute(TransferMode.SAFE, { Pair(ref, semaphore) }) { (ref, semaphore) ->
semaphore.increment()
semaphore.incrementAndGet()
while (semaphore.value < 2) {
}
@@ -543,7 +545,7 @@ fun testDoNotCollectInWorkerFrozen() {
while (semaphore.value < 1) {
}
GC.collect()
semaphore.increment()
semaphore.incrementAndGet()
val value = future.result
assertEquals(3, value.value.a)
@@ -556,9 +558,9 @@ class B1 {
data class B2(val b1: WorkerBoundReference<B1>)
fun createCyclicGarbage(): Triple<FreezableAtomicReference<WorkerBoundReference<B1>?>, WeakReference<B1>, WeakReference<B2>> {
fun createCyclicGarbage(): Triple<AtomicReference<WorkerBoundReference<B1>?>, WeakReference<B1>, WeakReference<B2>> {
val ref1 = WorkerBoundReference(B1())
val ref1Owner: FreezableAtomicReference<WorkerBoundReference<B1>?> = FreezableAtomicReference(ref1)
val ref1Owner: AtomicReference<WorkerBoundReference<B1>?> = AtomicReference(ref1)
val ref1Weak = WeakReference(ref1.value)
val ref2 = WorkerBoundReference(B2(ref1))
@@ -783,7 +785,7 @@ fun concurrentAccessFrozen() {
}
}
}
workerUnlocker.increment()
workerUnlocker.incrementAndGet()
for (future in futures) {
val value = future.result
@@ -5,7 +5,7 @@
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
fun main() {
@@ -5,7 +5,7 @@
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
import kotlin.native.internal.MemoryUsageInfo
@@ -7,10 +7,9 @@
package runtime.workers.lazy4
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.concurrent.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.*
import kotlin.native.concurrent.*
const val WORKERS_COUNT = 20
@@ -3,11 +3,10 @@
package runtime.workers.worker10
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.concurrent.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.AtomicReference
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.*
import kotlin.native.concurrent.*
import kotlin.native.ref.WeakReference
import kotlinx.cinterop.StableRef
@@ -7,10 +7,9 @@
package runtime.workers.worker11
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.concurrent.*
import kotlin.concurrent.AtomicInt
import kotlin.concurrent.*
import kotlin.native.concurrent.*
import kotlinx.cinterop.convert
data class Job(val index: Int, var input: Int, var counter: Int)
@@ -7,8 +7,8 @@
package runtime.workers.worker4
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
@Test fun runTest1() {
withWorker {
@@ -69,24 +69,6 @@ public class AtomicInt(@Volatile public var value: Int) {
*/
public fun getAndDecrement(): Int = this::value.getAndAddField(-1)
/**
* Atomically increments the current value by one.
*/
@Deprecated(level = DeprecationLevel.ERROR, message = "Use incrementAndGet() or getAndIncrement() instead.",
replaceWith = ReplaceWith("this.incrementAndGet()"))
public fun increment(): Unit {
addAndGet(1)
}
/**
* Atomically decrements the current value by one.
*/
@Deprecated(level = DeprecationLevel.ERROR, message = "Use decrementAndGet() or getAndDecrement() instead.",
replaceWith = ReplaceWith("this.decrementAndGet()"))
public fun decrement(): Unit {
addAndGet(-1)
}
/**
* Returns the string representation of the current [value].
*/
@@ -151,30 +133,6 @@ public class AtomicLong(@Volatile public var value: Long) {
*/
public fun getAndDecrement(): Long = this::value.getAndAddField(-1L)
/**
* Atomically adds the [given value][delta] to the current value and returns the new value.
*/
@Deprecated(level = DeprecationLevel.ERROR, message = "Use addAndGet(delta: Long) instead.")
public fun addAndGet(delta: Int): Long = addAndGet(delta.toLong())
/**
* Atomically increments the current value by one.
*/
@Deprecated(level = DeprecationLevel.ERROR, message = "Use incrementAndGet() or getAndIncrement() instead.",
replaceWith = ReplaceWith("this.incrementAndGet()"))
public fun increment(): Unit {
addAndGet(1L)
}
/**
* Atomically decrements the current value by one.
*/
@Deprecated(level = DeprecationLevel.ERROR, message = "Use decrementAndGet() or getAndDecrement() instead.",
replaceWith = ReplaceWith("this.decrementAndGet()"))
public fun decrement(): Unit {
addAndGet(-1L)
}
/**
* Returns the string representation of the current [value].
*/
@@ -184,7 +142,6 @@ public class AtomicLong(@Volatile public var value: Long) {
/**
* An object reference that is always updated atomically.
*/
@OptIn(FreezingIsDeprecated::class)
@SinceKotlin("1.9")
public class AtomicReference<T>(public @Volatile var value: T) {
@@ -16,8 +16,7 @@ import kotlin.concurrent.*
* An [Int] value that is always updated atomically.
* For additional details about atomicity guarantees for reads and writes see [kotlin.concurrent.Volatile].
*/
@Deprecated("Use kotlin.concurrent.AtomicInt instead.", ReplaceWith("kotlin.concurrent.AtomicInt"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@Deprecated("Use kotlin.concurrent.AtomicInt instead.", ReplaceWith("kotlin.concurrent.AtomicInt"), DeprecationLevel.ERROR)
public class AtomicInt(public @Volatile var value: Int) {
/**
* Atomically sets the value to the given [new value][newValue] and returns the old value.
@@ -73,7 +72,7 @@ public class AtomicInt(public @Volatile var value: Int) {
/**
* Atomically increments the current value by one.
*/
@Deprecated("Use incrementAndGet() or getAndIncrement() instead.", ReplaceWith("this.incrementAndGet()"))
@Deprecated("Use incrementAndGet() or getAndIncrement() instead.", ReplaceWith("this.incrementAndGet()"), DeprecationLevel.ERROR)
public fun increment(): Unit {
addAndGet(1)
}
@@ -81,7 +80,7 @@ public class AtomicInt(public @Volatile var value: Int) {
/**
* Atomically decrements the current value by one.
*/
@Deprecated("Use decrementAndGet() or getAndDecrement() instead.", ReplaceWith("this.decrementAndGet()"))
@Deprecated("Use decrementAndGet() or getAndDecrement() instead.", ReplaceWith("this.decrementAndGet()"), DeprecationLevel.ERROR)
public fun decrement(): Unit {
addAndGet(-1)
}
@@ -96,8 +95,7 @@ public class AtomicInt(public @Volatile var value: Int) {
* A [Long] value that is always updated atomically.
* For additional details about atomicity guarantees for reads and writes see [kotlin.concurrent.Volatile].
*/
@Deprecated("Use kotlin.concurrent.AtomicLong instead.", ReplaceWith("kotlin.concurrent.AtomicLong"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@Deprecated("Use kotlin.concurrent.AtomicLong instead.", ReplaceWith("kotlin.concurrent.AtomicLong"), DeprecationLevel.ERROR)
public class AtomicLong(public @Volatile var value: Long = 0L) {
/**
* Atomically sets the value to the given [new value][newValue] and returns the old value.
@@ -153,13 +151,13 @@ public class AtomicLong(public @Volatile var value: Long = 0L) {
/**
* Atomically adds the [given value][delta] to the current value and returns the new value.
*/
@Deprecated("Use addAndGet(delta: Long) instead.")
@Deprecated(message = "Use addAndGet(delta: Long) instead.", level = DeprecationLevel.ERROR)
public fun addAndGet(delta: Int): Long = addAndGet(delta.toLong())
/**
* Atomically increments the current value by one.
*/
@Deprecated("Use incrementAndGet() or getAndIncrement() instead.", ReplaceWith("this.incrementAndGet()"))
@Deprecated("Use incrementAndGet() or getAndIncrement() instead.", ReplaceWith("this.incrementAndGet()"), DeprecationLevel.ERROR)
public fun increment(): Unit {
addAndGet(1L)
}
@@ -167,7 +165,7 @@ public class AtomicLong(public @Volatile var value: Long = 0L) {
/**
* Atomically decrements the current value by one.
*/
@Deprecated("Use decrementAndGet() or getAndDecrement() instead.", ReplaceWith("this.decrementAndGet()"))
@Deprecated("Use decrementAndGet() or getAndDecrement() instead.", ReplaceWith("this.decrementAndGet()"), DeprecationLevel.ERROR)
fun decrement(): Unit {
addAndGet(-1L)
}
@@ -181,8 +179,7 @@ public class AtomicLong(public @Volatile var value: Long = 0L) {
/**
* An object reference that is always updated atomically.
*/
@Deprecated("Use kotlin.concurrent.AtomicReference instead.", ReplaceWith("kotlin.concurrent.AtomicReference"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@Deprecated("Use kotlin.concurrent.AtomicReference instead.", ReplaceWith("kotlin.concurrent.AtomicReference"), DeprecationLevel.ERROR)
public class AtomicReference<T>(public @Volatile var value: T) {
/**
* Atomically sets the value to the given [new value][newValue] and returns the old value.
@@ -223,8 +220,7 @@ public class AtomicReference<T>(public @Volatile var value: T) {
* [kotlinx.cinterop.NativePtr] is a value type, hence it is stored in [AtomicNativePtr] without boxing
* and [compareAndSet], [compareAndSwap] operations perform comparison by value.
*/
@Deprecated("Use kotlin.concurrent.AtomicNativePtr instead.", ReplaceWith("kotlin.concurrent.AtomicNativePtr"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@Deprecated("Use kotlin.concurrent.AtomicNativePtr instead.", ReplaceWith("kotlin.concurrent.AtomicNativePtr"), DeprecationLevel.ERROR)
public class AtomicNativePtr(public @Volatile var value: NativePtr) {
/**
* Atomically sets the value to the given [new value][newValue] and returns the old value.
@@ -281,8 +277,7 @@ private fun debugString(value: Any?): String {
* This class was useful only with legacy memory manager. Please use [AtomicReference] instead.
*/
@FreezingIsDeprecated
@Deprecated("Use kotlin.concurrent.AtomicReference instead.", ReplaceWith("kotlin.concurrent.AtomicReference"))
@DeprecatedSinceKotlin(warningSince = "1.9")
@Deprecated("Use kotlin.concurrent.AtomicReference instead.", ReplaceWith("kotlin.concurrent.AtomicReference"), DeprecationLevel.ERROR)
public class FreezableAtomicReference<T>(public @Volatile var value: T) {
/**