[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 {