Remove Recursive Mark from GC

The previous GC implementation used a recursive mark method. This can
result in stack overflows when attempting to mark deeply nested objects.

This commit replaces the recursive approach with an iteritive one,
moving the state stack from the C call stack to the `WrenVM` structure.

As objects are 'grayed' they are pushed onto the VM's gray stack. When
we have grayed all of the root objects we iterate until the stack is
empty graying any obejcts which haven't been marked as dark before. At
the end of the process we clean up all unmarked objects as before.

This commit also adds a few new tests which check garbage collection by
allocating some new deeply nested objects and triggering the GC a few
times in the process.
This commit is contained in:
Will Speak
2015-10-19 22:45:15 +01:00
parent b365c07d7a
commit cea71c2fe4
6 changed files with 99 additions and 35 deletions

View File

@ -0,0 +1,7 @@
var head
for (i in 1..400000) {
head = { "next" : head }
}
System.print("done") // expect: done

View File

@ -0,0 +1,14 @@
var found = []
for (i in 1..1000) {
var foo = 1337
for (i in 1..1000) {
foo = { "a" : foo, "b": foo }
}
var bar = foo
for (i in 1..1000) {
bar = bar["a"]
}
found.add(bar)
}
System.print(found.all {|i| i == 1337}) // expect: true
System.print("DONE!") // expect: DONE!