[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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user