[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,6 +4,7 @@
*/
@file:Suppress("UNUSED")
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
package stdlib
@@ -63,7 +64,7 @@ data class TripleVars<T>(var first: T, var second: T, var third: T) {
}
}
fun gc() = kotlin.native.internal.GC.collect()
fun gc() = kotlin.native.runtime.GC.collect()
// Note: this method checks only some of the operations (namely the ones modified recently,
// and thus required additional tests).
@@ -2,9 +2,10 @@
* Copyright 2010-2020 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(ExperimentalStdlibApi::class)
@file:OptIn(ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.internal.*
import kotlin.native.runtime.GC
fun ensureInitialized() {}
@@ -1,3 +1,5 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import kt44283.*
import kotlin.native.concurrent.AtomicInt
@@ -7,7 +9,7 @@ val callbackCounter = AtomicInt(0)
fun main() {
val func = staticCFunction<CValue<TestStruct>, Unit> {
kotlin.native.internal.GC.collect() // Helps to ensure that "runtime" is already initialized.
kotlin.native.runtime.GC.collect() // Helps to ensure that "runtime" is already initialized.
memScoped {
println("Hello, Kotlin/Native! ${it.ptr.pointed.d}")
@@ -2,6 +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(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import objcSmoke.*
@@ -204,7 +205,7 @@ fun testCustomRetain() {
autoreleasepool {
test()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
assertFalse(unexpectedDeallocation)
@@ -2,6 +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(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import objcSmoke.*
@@ -204,7 +205,7 @@ fun testCustomRetain() {
autoreleasepool {
test()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
assertFalse(unexpectedDeallocation)
@@ -1,3 +1,5 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
import objcTests.*
@@ -13,7 +15,7 @@ import objcTests.*
}
test()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(customStringDeallocated)
}
@@ -1,3 +1,5 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.ref.WeakReference
import kotlinx.cinterop.*
import kotlin.test.*
@@ -9,7 +11,7 @@ import objcTests.*
@Test
fun testKT41811() {
// Attempt to make the state predictable:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
deallocRetainReleaseDeallocated = false
assertFalse(deallocRetainReleaseDeallocated)
@@ -17,12 +19,12 @@ fun testKT41811() {
createGarbageDeallocRetainRelease()
// Runs [DeallocRetainRelease dealloc]:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(deallocRetainReleaseDeallocated)
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
private fun createGarbageDeallocRetainRelease() {
@@ -55,7 +57,7 @@ fun testKT41811LoadKotlinWeak() {
private fun testKT41811LoadWeak(weakRef: WeakReferenceProtocol) {
// Attempt to make the state predictable:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
deallocLoadWeakDeallocated = false
assertFalse(deallocLoadWeakDeallocated)
@@ -63,12 +65,12 @@ private fun testKT41811LoadWeak(weakRef: WeakReferenceProtocol) {
createGarbageDeallocLoadWeak(weakRef)
// Runs [DeallocLoadWeak dealloc]:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(deallocLoadWeakDeallocated)
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
weakDeallocLoadWeak = null
}
@@ -85,7 +87,7 @@ private fun createGarbageDeallocLoadWeak(weakRef: WeakReferenceProtocol) {
@Test
fun testKT41811WithGlobal() {
// Attempt to make the state predictable:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
deallocRetainReleaseDeallocated = false
assertFalse(deallocRetainReleaseDeallocated)
@@ -99,7 +101,7 @@ fun testKT41811WithGlobal() {
assertFalse(deallocRetainReleaseDeallocated)
// Clean up local DeallocRetainRelease on Kotlin side
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertFalse(deallocRetainReleaseDeallocated)
@@ -112,7 +114,7 @@ fun testKT41811WithGlobal() {
// on ObjC side, which triggers `retain` and `release` of `self`. If these messages
// were to reach Kotlin side, the `release` would have immediately scheduled the
// second disposal of Kotlin object.
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(deallocRetainReleaseDeallocated)
}
@@ -1,3 +1,5 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.ref.WeakReference
import kotlinx.cinterop.*
import kotlin.test.*
@@ -6,7 +8,7 @@ import objcTests.*
@Test
fun testKT42482() {
// Attempt to make the state predictable:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
kt42482Deallocated = false
assertFalse(kt42482Deallocated);
@@ -25,7 +27,7 @@ fun testKT42482() {
kt42482Global = null
}()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(kt42482Deallocated)
}
@@ -1,4 +1,4 @@
@file:OptIn(FreezingIsDeprecated::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import kotlin.native.concurrent.*
@@ -16,7 +16,7 @@ import objcTests.*
testObjCWeakRef0(deallocListener)
}
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertTrue(deallocListener.deallocated)
assertTrue(deallocListener.deallocExecutorIsNil())
}
@@ -47,6 +47,6 @@ private fun testObjCWeakRef0(deallocListener: DeallocListener) = withWorker {
assertFalse(deallocListener.deallocExecutorIsNil())
}
// Process release of Kotlin reference to [obj] in any case:
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
}
@@ -1,10 +1,12 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlinx.cinterop.*
import kotlin.test.*
import objcTests.*
@Test
fun testTryRetainGC() {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
val weakRefHolder = WeakRefHolder()
createGarbageNSObjects(weakRefHolder)
weakRefHolder.obj = object : NSObject() {}
@@ -1,3 +1,5 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.ref.*
import kotlinx.cinterop.*
import kotlin.test.*
@@ -16,7 +18,7 @@ private fun testWeakReference(block: () -> NSObject) {
createAndTestWeakReference(block)
}
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertNull(ref.get())
}
@@ -2,6 +2,7 @@
* Copyright 2010-2020 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(kotlin.native.runtime.NativeRuntimeApi::class)
package coroutines
@@ -243,4 +244,4 @@ fun createCoroutineUninterceptedAndResume(fn: suspend () -> Any?, resultHolder:
fun createCoroutineUninterceptedAndResume(fn: suspend Any?.() -> Any?, receiver: Any?, resultHolder: ResultHolder<Any?>) =
fn.createCoroutine(receiver, ResultHolderCompletion(resultHolder)).resume(Unit)
fun gc() = kotlin.native.internal.GC.collect()
fun gc() = kotlin.native.runtime.GC.collect()
@@ -7,7 +7,8 @@ package deallocretain
open class DeallocRetainBase
fun garbageCollect() = kotlin.native.internal.GC.collect()
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
fun garbageCollect() = kotlin.native.runtime.GC.collect()
fun createWeakReference(value: Any) = kotlin.native.ref.WeakReference(value)
@@ -19,7 +19,8 @@ class KotlinLivenessTracker {
fun objectsAreDead() = weakRefs.all { it.value === null }
}
fun gc() = kotlin.native.internal.GC.collect()
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
fun gc() = kotlin.native.runtime.GC.collect()
class KotlinObject
@@ -5,7 +5,7 @@
// All classes and methods should be used in tests
@file:Suppress("UNUSED")
@file:OptIn(FreezingIsDeprecated::class)
@file:OptIn(FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
package conversions
@@ -807,7 +807,7 @@ open class TestDeprecation() {
@Deprecated("warning", level = DeprecationLevel.WARNING) var warningVar: Any? = null
fun gc() {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
class TestWeakRefs(private val frozen: Boolean) {
@@ -862,7 +862,7 @@ class SharedRefs {
fun createFrozenCollection() = createCollection().freeze()
fun hasAliveObjects(): Boolean {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
return mustBeRemoved.any { it.get() != null }
}
@@ -2,7 +2,7 @@
* Copyright 2010-2020 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(ExperimentalStdlibApi::class, FreezingIsDeprecated::class)
@file:OptIn(ExperimentalStdlibApi::class, FreezingIsDeprecated::class, kotlin.native.runtime.NativeRuntimeApi::class)
package runtime.basic.cleaner_basic
@@ -13,6 +13,7 @@ import kotlin.native.concurrent.*
import kotlin.native.ref.WeakReference
import kotlin.native.ref.Cleaner
import kotlin.native.ref.createCleaner
import kotlin.native.runtime.GC
class AtomicBoolean(initialValue: Boolean) {
private val impl = AtomicInt(if (initialValue) 1 else 0)
@@ -2,7 +2,7 @@
* Copyright 2010-2020 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(ExperimentalStdlibApi::class)
@file:OptIn(ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.test.*
@@ -10,6 +10,7 @@ import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlin.native.ref.Cleaner
import kotlin.native.ref.createCleaner
import kotlin.native.runtime.GC
@ThreadLocal
var tlsCleaner: Cleaner? = null
@@ -2,7 +2,7 @@
* Copyright 2010-2020 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(ExperimentalStdlibApi::class, FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
@file:OptIn(ExperimentalStdlibApi::class, FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
package runtime.basic.cleaner_workers
@@ -13,6 +13,7 @@ import kotlin.native.concurrent.*
import kotlin.native.ref.WeakReference
import kotlin.native.ref.Cleaner
import kotlin.native.ref.createCleaner
import kotlin.native.runtime.GC
class AtomicBoolean(initialValue: Boolean) {
private val impl = AtomicInt(if (initialValue) 1 else 0)
@@ -7,7 +7,6 @@ package runtime.collections.hash_map1
import kotlin.native.MemoryModel
import kotlin.native.Platform
import kotlin.native.internal.GC
import kotlin.test.*
fun assertTrue(cond: Boolean) {
@@ -2,16 +2,16 @@
* Copyright 2010-2020 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.concurrent.worker_bound_reference0
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.native.internal.GC
import kotlin.native.*
import kotlin.native.ref.WeakReference
import kotlin.native.runtime.GC
import kotlin.text.Regex
class A(var a: Int)
@@ -1,5 +1,7 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.concurrent.*
import kotlin.native.internal.GC
import kotlin.native.runtime.GC
import kotlin.native.Platform
import kotlin.test.*
@@ -44,15 +46,15 @@ fun makeIt(): Holder {
fun test4() {
val holder = makeIt()
// To clean rc count coming from rememberNewContainer().
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
// Request cyclic collection.
kotlin.native.internal.GC.collectCyclic()
kotlin.native.runtime.GC.collectCyclic()
// Ensure we processed delayed release.
repeat(10) {
// Wait a bit and process queue.
Worker.current.park(10)
Worker.current.processQueue()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
val value = @Suppress("UNCHECKED_CAST") (holder.other as? AtomicReference<Holder?>?)
assertTrue(value != null)
@@ -77,15 +79,15 @@ fun createHolder2() = Holder2(createRef())
fun test5() {
val holder = createHolder2()
kotlin.native.internal.GC.collect()
kotlin.native.internal.GC.collectCyclic()
kotlin.native.runtime.GC.collect()
kotlin.native.runtime.GC.collectCyclic()
Worker.current.park(100 * 1000)
holder.switch()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
Worker.current.park(100 * 1000)
withWorker {
executeAfter(0L, {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}.freeze())
}
Worker.current.park(1000)
@@ -109,9 +111,9 @@ fun createRoot(): AtomicReference<Any?> {
fun test7() {
val ref1 = createRoot()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
kotlin.native.internal.GC.collectCyclic()
kotlin.native.runtime.GC.collectCyclic()
Worker.current.park(500 * 1000L)
withWorker {
@@ -177,7 +179,7 @@ fun test9() {
fun main() {
Platform.isMemoryLeakCheckerActive = true
kotlin.native.internal.GC.cyclicCollectorEnabled = true
kotlin.native.runtime.GC.cyclicCollectorEnabled = true
test1()
test2()
test3()
@@ -1,9 +1,9 @@
import kotlin.native.concurrent.*
import kotlin.native.internal.GC
import kotlin.test.*
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
fun main() {
kotlin.native.internal.GC.cyclicCollectorEnabled = true
kotlin.native.runtime.GC.cyclicCollectorEnabled = true
repeat(10000) {
// Create atomic cyclic garbage:
@@ -1,5 +1,7 @@
@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.concurrent.*
import kotlin.native.internal.GC
import kotlin.native.runtime.GC
import kotlin.native.Platform
import kotlin.test.*
@@ -44,11 +44,12 @@ fun createCycles(junk: Node) {
}
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
@Test fun runTest() {
// Create outer link from cyclic garbage.
val outer = Node(42, null, null, null)
createCycles(outer)
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
// Ensure outer is not collected.
println(outer.data)
}
@@ -10,11 +10,12 @@ package runtime.memory.cycles1
import kotlin.test.*
import kotlin.native.ref.*
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
@Test fun runTest() {
// TODO: make it work in relaxed model as well.
if (Platform.memoryModel == MemoryModel.RELAXED) return
val weakRefToTrashCycle = createLoop()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
assertNull(weakRefToTrashCycle.get())
}
@@ -3,9 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:OptIn(kotlin.ExperimentalStdlibApi::class)
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.native.internal.GC
import kotlin.native.runtime.GC
import kotlin.test.*
@@ -2,8 +2,8 @@
* 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.
*/
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
fun main(args: Array<String>) {
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
}
@@ -2,6 +2,8 @@
* Copyright 2010-2021 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(kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
@@ -58,8 +60,8 @@ fun test() {
val progressReportsCount = 100
if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) {
kotlin.native.internal.GC.autotune = false
kotlin.native.internal.GC.targetHeapBytes = retainLimit
kotlin.native.runtime.GC.autotune = false
kotlin.native.runtime.GC.targetHeapBytes = retainLimit
}
// On Linux, the child process might immediately commit the same amount of memory as the parent.
@@ -28,15 +28,16 @@ fun multiWeak(): Array<WeakReference<Data>> {
return weaks
}
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
@Test fun runTest() {
val weak = localWeak()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
val value = weak.get()
println(value?.toString())
val weaks = multiWeak()
kotlin.native.internal.GC.collect()
kotlin.native.runtime.GC.collect()
weaks.forEach {
it -> if (it.get()?.s != null) throw Error("not null")
@@ -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)