I'm interested in how garbage collection works. I've read up on how some work such as mark-and-sweep, stop-and-copy, generational GC, etc... I'd like to experiment with implementing some of these and comparing their behaviors. What's a good way to get started experimenting with my own? Ideally something in C, Java or Python (although the last two are themselves garbage-collected so it seems it'd be hard to use them...)
Implement your own JVM. Nothing fancy, just the basics. There are lots and lots of programs/compilers/languages which generate JVM code so you have plenty of material to test with.
the .NET runtime and Java runtime are now open source, so you can experiment with the runtime it self if you want to play around with a current support programming language. However if you wanted to do this yourself you would probably have to create your own runtime which has it's own language.
Never played with it myself, but the one that always gets mentioned for use with C/C++ is Hans Boehm's.
Fun to play with, but garbage collection is a dark art. Not to make it work, but to make it work with the efficiency that the newest VMs do.
We're talking multi-stage and magic that makes allocations speed more comparable to stack allocations than malloc.
The whole eden concept rocks.
You might want to read some whitepapers on the techniques used.
Here's an article that seems to have a good overview (just from a quick google/scan)
Slava Pestov who developes the Factor programming language wrote a number of posts about his implementation of a garbage collector. You can find posts on it with this link:
http://factor-language.blogspot.com/search?q=garbage+collection
in particular start from the post on Sunday, September 24, 2006.
MMTk contains a large set of high performance garbage collectors. It includes:
- Copying collectors
- Tracing collectors
- Reference counting collectors
It also has:
- Stop the world collectors
- Concurrent collectors
Since it is a research platform it has some advance collectors such as the generation reference counting collector.