mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
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:
7
test/language/deeply_nested_gc.wren
Normal file
7
test/language/deeply_nested_gc.wren
Normal file
@ -0,0 +1,7 @@
|
||||
var head
|
||||
|
||||
for (i in 1..400000) {
|
||||
head = { "next" : head }
|
||||
}
|
||||
|
||||
System.print("done") // expect: done
|
||||
14
test/language/many_reallocations.wren
Normal file
14
test/language/many_reallocations.wren
Normal 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!
|
||||
Reference in New Issue
Block a user