[K/N] Move kotlin.native.internal.GC into kotlin.native.runtime

As a part of efforts to stabilize Native stdlib #KT-55765.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-03-30 23:16:33 +03:00
parent 7a2e2f5f9f
commit e1c91ee50f
46 changed files with 506 additions and 212 deletions
@@ -4,11 +4,13 @@
*/
// Note: This test reproduces a race, so it'll start flaking if problem is reintroduced.
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlin.native.runtime.GC
val thrashGC = AtomicInt(1)
val canStartCreating = AtomicInt(0)
@@ -2,7 +2,7 @@
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(FreezingIsDeprecated::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
package runtime.workers.freeze6
@@ -48,7 +48,7 @@ var global = 0
@Test
fun ensureFreezableHandlesCycles1() {
val ref = createRef1()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
val obj: Any = ref
global = obj.hashCode()
@@ -86,7 +86,7 @@ fun createRef2(): Pair<FreezableAtomicReference<Node?>, Any> {
@Test
fun ensureFreezableHandlesCycles2() {
val (ref, obj) = createRef2()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(obj.toString().length > 0)
global = ref.value!!.ref!!.hashCode()
@@ -108,7 +108,7 @@ fun createRef3(): FreezableAtomicReference<Any?> {
fun ensureFreezableHandlesCycles3() {
val ref = createRef3()
ref.value = null
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
val obj: Any = ref
assertTrue(obj.toString().length > 0)
@@ -133,7 +133,7 @@ fun ensureWeakRefNotLeaks1() {
ref.value = null
// We cannot check weakRef.get() here, as value read will be stored in the stack slot,
// and thus hold weak reference from release.
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(weakRef.get() == null)
}
@@ -155,6 +155,6 @@ fun createRef5() {
@Test
fun ensureWeakRefNotLeaks2() {
createRef5()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(weakNode2.get() == null)
}
@@ -24,8 +24,9 @@ fun printAll() {
// initializer field in frozen lazy object led to the crash, induced by breaking frozen objects'
// invariant (initializer end up in the same container as the lazy object itself, so it was destroyed
// earlier than it should when reference counter was decremented).
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
fun main(args: Array<String>) {
printAll()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
println("OK")
}
@@ -1,4 +1,4 @@
@file:OptIn(FreezingIsDeprecated::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.concurrent.*
import kotlin.native.ref.*
@@ -49,7 +49,7 @@ fun ensureGetsCollectedFrozenAndNotFrozen(create: () -> Any) {
fun ensureGetsCollected(create: () -> Any) {
val ref = makeWeakRef(create)
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertNull(ref.get())
}
@@ -1,4 +1,4 @@
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
package runtime.workers.worker10
import kotlin.test.*
@@ -99,7 +99,7 @@ val semaphore = AtomicInt(0)
}
while (semaphore.value != 1) {}
atomicRef.value = null
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
semaphore.increment()
future.result
worker.requestTermination().result
@@ -116,7 +116,7 @@ val semaphore = AtomicInt(0)
}
while (semaphore.value != 1) {}
stableRef.dispose()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
semaphore.increment()
future.result
worker.requestTermination().result
@@ -135,12 +135,12 @@ val stableHolder1 = StableRef.create(("hello" to "world").freeze())
ensureWeakIs(it, "hello" to "world")
semaphore.increment()
while (semaphore.value != 2) {}
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
ensureWeakIs(it, null)
}
while (semaphore.value != 1) {}
stableHolder1.dispose()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
semaphore.increment()
future.result
worker.requestTermination().result
@@ -155,12 +155,12 @@ val stableHolder2 = StableRef.create(("hello" to "world").freeze())
val value = it.get()
semaphore.increment()
while (semaphore.value != 2) {}
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertEquals("hello" to "world", value)
}
while (semaphore.value != 1) {}
stableHolder2.dispose()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
semaphore.increment()
future.result
worker.requestTermination().result
@@ -178,7 +178,7 @@ val atomicRef2 = AtomicReference<Any?>(Any().freeze())
}
while (semaphore.value != 1) {}
atomicRef2.value = null
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
semaphore.increment()
future.result
worker.requestTermination().result
@@ -80,12 +80,13 @@ fun makeCyclic(): Node {
return outer
}
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
@Test fun runTest4() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { }) {
makeCyclic().also {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
}
assert(future.result != null)
@@ -78,12 +78,13 @@ fun makeCyclic(): Node {
return outer
}
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
@Test fun runTest4() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, { }) {
makeCyclic().also {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
}
assert(future.result != null)