[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
@@ -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())
}