Retoor software development Projects Research SearchXNG
Register Sign In

7 lines
99 B
Plaintext
Raw Normal View History

feat: replace recursive mark with iterative gray/darken GC to prevent stack overflow The previous recursive `wrenMarkObj` approach could overflow the C stack when marking deeply nested object graphs. This commit introduces an iterative two-phase collector: objects are first "grayed" onto an explicit stack in the WrenVM struct, then `wrenDarkenObjs` iteratively processes the gray stack until all reachable objects are marked as "dark". The `marked` field is renamed to `isDark` to reflect the new semantics. A `gray` array with `grayDepth` and `maxGray` tracking is added to `WrenVM`, initialized in `initializeGC` and freed in `wrenFreeVM`. All internal mark calls (`markClass`, `markClosure`, `markFiber`, `wrenCollectGarbage`) are updated to use `wrenGrayObj` instead of `wrenMarkObj`. Two new test files (`deeply_nested_gc.wren` and `many_reallocations.wren`) verify that deeply nested object graphs and repeated GC cycles complete without stack overflow.
2015-10-19 23:45:15 +02:00
var head
for (i in 1..400000) {
head = { "next" : head }
}
System.print("done") // expect: done
Reference in New Issue Copy Permalink
140fb7738e
wren/test/language/deeply_nested_gc.wren
Response time: 33ms
Mail Licenses API