Cycle collector. (#175)

This commit is contained in:
Nikolay Igotti
2017-01-11 17:38:03 +03:00
committed by Konstantin Anisimov
parent 14695bf20e
commit ecf66ab23b
7 changed files with 405 additions and 64 deletions
+12 -7
View File
@@ -41,11 +41,11 @@ abstract class KonanTest extends DefaultTask {
project.javaexec {
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
classpath = project.configurations.cli_bc
jvmArgs "-ea",
jvmArgs "-ea",
"-Dkonan.home=${dist.canonicalPath}",
"-Djava.library.path=${dist.canonicalPath}/konan/nativelib"
args("-output", output,
source,
source,
*moreArgs,
*project.globalArgs)
}
@@ -88,7 +88,7 @@ abstract class KonanTest extends DefaultTask {
class RunKonanTest extends KonanTest {
void compileTest(String source, String exe) {
runCompiler(source, exe, [])
runCompiler(source, exe, [])
}
}
@@ -98,7 +98,7 @@ class LinkKonanTest extends KonanTest {
void compileTest(String source, String exe) {
def libDir = project.file(lib).absolutePath
def libBc = "${libDir}.bc"
runCompiler(lib, libBc, ['-nolink', '-nostdlib'])
runCompiler(source, exe, ['-library', libBc])
}
@@ -246,8 +246,8 @@ task tostring3(type: RunKonanTest) {
"1.17549E-38\n3.40282E+38\n-INF\nINF\n" +
// Linux version prints -NAN.
// "NAN\n" +
"4.94066E-324\n1.79769E+308\n-INF\nINF\n"
// "NAN\n"
"4.94066E-324\n1.79769E+308\n-INF\nINF\n"
// "NAN\n"
source = "runtime/basic/tostring3.kt"
}
@@ -359,7 +359,7 @@ task intrinsic(type: RunKonanTest) {
}
/*
Disabled until we extract the classes that should be
Disabled until we extract the classes that should be
always present from stdlib.kt.bc into a separate binary.
task link(type: LinkKonanTest) {
@@ -805,6 +805,11 @@ task memory_throw_cleanup(type: RunKonanTest) {
source = "runtime/memory/throw_cleanup.kt"
}
task memory_collect_cycles(type: RunKonanTest) {
goldValue = "42\n"
source = "runtime/memory/cycles0.kt"
}
task unit1(type: RunKonanTest) {
goldValue = "First\nkotlin.Unit\n"
source = "codegen/basics/unit1.kt"
@@ -0,0 +1,45 @@
data class Node(val data: Int, var next: Node?, var prev: Node?, val outer: Node?)
fun makeCycle(len: Int, outer: Node?): Node {
val start = Node(0, null, null, outer)
var prev = start
for (i in 1 .. len - 1) {
prev = Node(i, prev, null, outer)
}
start.next = prev
return start
}
fun makeDoubleCycle(len: Int): Node {
val start = makeCycle(len, null)
var prev = start
var cur = prev.next
while (cur != start) {
cur!!.prev = prev
prev = cur
cur = cur.next
}
start.prev = prev
return start
}
fun createCycles(junk: Node) {
val cycle1 = makeCycle(1, junk)
val cycle2 = makeCycle(2, junk)
val cycle10 = makeCycle(10, junk)
val cycle100 = makeCycle(100, junk)
val dcycle1 = makeDoubleCycle(1)
val dcycle2 = makeDoubleCycle(2)
val dcycle10 = makeDoubleCycle(10)
val dcycle100 = makeDoubleCycle(100)
}
fun main(args : Array<String>) {
// Create outer link from cyclic garbage.
val outer = Node(42, null, null, null)
createCycles(outer)
konan.internal.GC.collect()
// Ensure outer is not collected.
println(outer.data)
}