Cycle collector. (#175)

This commit is contained in:
Nikolay Igotti
2017-01-11 17:38:03 +03:00
committed by GitHub
parent 8b83cb2adf
commit b1101ba43e
7 changed files with 406 additions and 65 deletions
@@ -33,7 +33,7 @@ internal class MacOSPlatform(distrib: Distribution,
override val linkerOptimizationFlags =
properties.propertyList("linkerOptimizationFlags.osx")
override val linkerKonanFlags = listOf(distrib.libCppAbi)
override val linkerKonanFlags = properties.propertyList("linkerKonanFlags.osx")
override val linker = "${distrib.sysRoot}/usr/bin/ld"
override fun linkCommand(objectFiles: List<String>, executable: String, optimize: Boolean): List<String> {
+2 -1
View File
@@ -10,12 +10,13 @@ libGcc.linux = target-gcc-toolchain-3-linux-x86-64/lib/gcc/x86_64-unknown-linux-
llvmLtoFlags.osx = -O3 -function-sections -exported-symbol=_main
llvmLlcFlags.osx = -mtriple=x86_64-apple-macosx10.10.0
linkerKonanFlags.osx = -lc++
linkerOptimizationFlags.osx = -dead_strip
macosVersionMin.osx = 10.10.0
llvmLtoFlags.linux = -O3 -function-sections -exported-symbol=main
llvmLlcFlags.linux = -march=x86-64
linkerKonanFlags.linux = -Bstatic -lc++abi -Bdynamic -ldl -lm -lpthread
linkerKonanFlags.linux = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread
linkerOptimizationFlags.linux = --gc-sections
pluginOptimizationFlags.linux = -plugin-opt=mcpu=x86-64 -plugin-opt=O3
+13 -8
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"
@@ -823,4 +828,4 @@ task unit3(type: RunKonanTest) {
task unit4(type: RunKonanTest) {
goldValue = "Done\n"
source = "codegen/basics/unit4.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)
}