3 ms·
Does it have a good story for doing precise GC? When I looked at it some time ago, it appeared that I'd have to understand and write a lot of C++ code ... whic
by hga 14y ago
Does it have a good story for doing precise GC?
When I looked at it some time ago, it appeared that I'd have to understand and write a lot of C++ code ... which I very much don't want to do.
- pcwalton 14y agoNo, LLVM's support for precise GC is not great. You can do it, but you have to spill all registers that might contain pointers across all calls, which is a significant performance hit. (Note that GCC is the same way though, as I understand it.) In my opinion, you're usually better off just doing conservative-on-the-stack GC if you're using LLVM. (This is what Rust does.) The basic problem is that LLVM loses the distinction between pointers and integers as soon as it drops into SelectionDAG and later passes. Fixing this would be a lot of work.
- billwashere 14y agoAnother cool LLVM based project that has Garbage Collection is the Epoch Programming Language[0] uses a similar approach [1]. Original reddit submission here [2]. [0] https://code.google.com/p/epoch-language/ https://code.google.com/p/epoch-language/ [1] https://code.google.com/p/epoch-language/wiki/GarbageCollectionScheme https://code.google.com/p/epoch-language/wiki/GarbageCollect... [2] http://www.reddit.com/r/programming/comments/1c5jz6/realistic_garbage_collection_on_top_of_llvm_epoch/ http://www.reddit.com/r/programming/comments/1c5jz6/realisti...
- jules 14y agoIf you're willing to jump through some hoops, you don't have to spill. You can recover the pointers on the stack by making all function calls return a flag indicating whether it's a normal return or a stack scan for GC. If a function returns the stack scan flag, you register the local variables in the current stack frame to the GC, and then you return the stack scan flag from that function. This way it unrolls the entire stack and you scan everything. Of course you've now destroyed the stack, so either you have to copy the stack before this process starts and later restore it, or you introduce stack restoring functions as a source to source transformation. The former is probably simpler and faster, but the latter is neat because it doesn't use any hacks like copying the stack, and because it allows you to restore only part of the stack and keep part of it in the heap and restore it lazily, which is important for GC pause times if you have very deep stacks. The disadvantage of this approach compared to the ideal is that now all function returns get slower, because they have to check the flag. However it's probably better than spilling everything, especially if you inline enough so that function calls are infrequent. Example: def f(...): var x; var y; ... z = g(...) ... becomes: def f(...): var x; var y; ... z = g(...) if STACKSCAN: register_gc_root(x) register_gc_root(y) return // scan parent stack frame ....
- pjmlp 14y agoSadly, not yet.
- carterschonwald 14y agoGHC haskell has precise ghc via the llvm and native code backends both. That said, it doesn't (i think) use any of the llvm hooks. Instead the gc machinery is baked into the relevant primops. The hand written primops can be found here https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L51 https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L51 (the low level primops that aren't compiler generated are written in cmm, a ghc specific dialect of c minus minus. )