garbage-collector-implementer
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Implements tracing garbage collectors. Use when: (1) Building language
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- acsl-annotation-assistantSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- dsl-embeddingSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- higher-order-abstract-syntaxSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- lexer-generatorSkill
- linear-type-implementerSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 9 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 60
Consider write barriers for incremental collection
- Distinctive: line 62
Use thread-local allocation for speed
- Distinctive: line 93
For real-time systems: Use real-time GC or custom allocators
- Distinctive: line 94
For memory-constrained: Use manual memory management or arenas
- Distinctive: line 95
For deterministic timing: Avoid GC pauses; use pooling
- Distinctive: line 96
For bare metal: Use static allocation or custom allocators
- Distinctive: line 107
Pause times: Stop-the-world collectors cause latency spikes
- Distinctive: line 157
Techniques: Write barriers, dirty bits, concurrent marking
- Distinctive: line 209
Must scan all threads' stacks:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Garbage Collector Implementer
Implements tracing garbage collectors (mark-compact, generational, etc.).
When to Use
- Building language runtimes
- Implementing interpreters/compilers
- Learning memory management
- Optimizing memory allocation
What This Skill Does
- Implements heap allocation - Object layout and allocation
- Builds tracing collectors - Mark-sweep, mark-compact, copying
- Handles roots - Stack and global roots
- Optimizes - Generational, incremental collection
Key Concepts
| Concept | Description |
| Root set | Initial reachable references (stack, globals) |
| Tracing | Follow pointers from roots to find live objects |
| Allocation | Finding space for new objects |
| Compaction | Defragment heap after collection |
| Generations | Age-based collection (young/old) |
GC Algorithms Comparison
| Algorithm | Pros | Cons |
| Mark-Sweep | Simple, no copying | Fragmentation, pause |
| Mark-Compact | No fragmentation | Multiple passes, slow |
| Copying | Fast, no fragmentation | Half memory, mutator copies |
| Generational | Short pause, efficiency | Complexity |
Tips
- Track all root pointers carefully
- Handle weak references specially
- Consider write barriers for incremental collection
- Profile pause times in production
- Use thread-local allocation for speed
Related Skills
jit-compiler-builder- Build VM runtimelambda-calculus-interpreter- Bytecode interpreter
Canonical References
| Reference | Why It Matters |
| Jones & Lins, "Garbage Collection: Algorithms for Automatic Dynamic Memory Management" (Wiley, 1996) | Definitive textbook on GC |
| Jones, Hosking & Moss, "The Garbage Collection Handbook: The Art of Automatic Memory Management" (Chapman & Hall, 2012) | Updated comprehensive reference |
| Lieberman & Hewitt, "A Real-Time Garbage Collector Based on the Lifetimes of Objects" (CACM 1983) | Generational GC origin |
| Ungar, "Generation Scavenging: A Non-disruptive High Performance Storage Reclamation Algorithm" (1984) | Nursery/tenured generations |
| Blackburn & McKinley, "Immix: A Mark-Region Garbage Collector with Space Efficiency, Fast Collection, and Mutator Performance" (PLDI 2008) | Modern high-throughput collector |
Tradeoffs and Limitations
Algorithm Tradeoffs
| Algorithm | Pause Time | Throughput | Memory | Best For |
| Mark-Sweep | Medium | Medium | High | Embedded systems |
| Mark-Compact | High | Low | High | Long-running servers |
| Copying | Low | High | 50% | Real-time, short-lived objects |
| Generational | Low | High | Moderate | General purpose |
| Incremental | Predictable | Lower | Moderate | Interactive apps |
When NOT to Use GC
- For real-time systems: Use real-time GC or custom allocators
- For memory-constrained: Use manual memory management or arenas
- For deterministic timing: Avoid GC pauses; use pooling
- For bare metal: Use static allocation or custom allocators
Complexity Analysis
- Mark-Sweep: O(n + m) where n = heap objects, m = marks
- Copying: O(n) where n = live objects
- Generational: O(n) for minor collections (young gen), full O(n) for major
- Space overhead: Forwarding pointers, remembered sets
Limitations
- Pause times: Stop-the-world collectors cause latency spikes
- Fragmentation: Mark-sweep causes internal/external fragmentation
- Overhead: GC costs 5-20% CPU time typically
- Weak references: Need special handling for finalizers
- Debugging: Memory leaks harder to find ( GC bugs are subtle)
- Portability: GC depends on memory layout, pointer formats
Assessment Criteria
A high-quality GC implementation should have:
| Criterion | What to Look For |
| Correctness | Never collects live objects |
| Completeness | Collects all unreachable objects |
| Pause time | Low latency (for real-time: <1ms) |
| Throughput | Minimal overhead on mutator |
| Memory | Efficient use of heap |
| Scaling | Works on multi-core |
Quality Indicators
✅ Good: Correct, low pause, efficient ⚠️ Warning: Memory bloat, occasional pauses ❌ Bad: Collects live objects (memory corruption), doesn't terminate
Research Tools & Artifacts
Real-world garbage collectors to study:
| System | Collector | Key Innovation |
| HotSpot JVM | G1, ZGC, Shenandoah | Generational, low-latency |
| Go runtime | Mark-assisted | Concurrent marking |
| OCaml | Minor GC | Short pauses |
| GraalVM | Truffle GC | Metacircular |
| Racket | Ring GC | Incremental |
| Haskell GHC | Generational | Parallel collection |
Academic/Research GCs
- Immix (Blackburn et al.) - High throughput
- ZGC (Oracle) - Sub-millisecond pauses
- Shenandoah (Red Hat) - Concurrent compaction
- MMTk (Oxford) - Memory management tool kit
Research Frontiers
1. Concurrent GC
- Goal: Reduce pause times by running concurrently
- Techniques: Write barriers, dirty bits, concurrent marking
- Papers: "Garbage Collection in Java 11" (Google I/O)
- Tools: ZGC, Shenandoah, Go GC
2. Region-Based Allocation
- Goal: Region-based memory management
- Techniques: Regions with different lifetimes
- Papers: "Memory Management with Regions" (Gay & Aiken)
- Application: Rust's arena allocator
3. GC for Functional Languages
- Goal: Efficient for immutable data
- Techniques: Generational, incremental, persistent data structures
- Papers: "The Design of Cryptographic Applications"
- Application: Haskell, Clojure, OCaml
4. Real-Time GC
- Goal: Predictable pause times
- Techniques: Incremental, concurrent, hybrid
- Papers: "Real-Time Garbage Collection" (Lieberman & Hewitt)
- Application: Embedded systems, games
Implementation Pitfalls
| Pitfall | Real Consequence | Solution |
| Missing roots | Memory corruption | Trace all stack slots, globals |
| Write barrier bugs | Incorrect collection | Test with pinned objects |
| Fragmentation | Out of memory | Compaction or copying |
| Pin handling | Objects can't move | Handle specially |
| Finalizers | Memory leaks | Track finalizer queue |
The "Write Barrier" Problem
Concurrent GC needs write barriers:
// Write barrier for generational GC
void write_barrier(void* obj, void* field, void* new_value) {
// If storing old->new ref and new is in older gen
if (is_heap_object(new_value) &&
generation(new_value) < generation(obj)) {
// Remember this store for minor GC
remember_set_add(obj);
}
// Perform actual write
*field = new_value;
}The "Stack Scanning" Challenge
Must scan all threads' stacks:
void scan_roots() {
for (Thread* t = all_threads; t != NULL; t = t->next) {
// Get stack boundaries
void* stack_top = t->stack_top;
void* stack_bottom = t->stack_bottom;
// Scan stack for pointers
for (void* p = stack_bottom; p < stack_top; p += sizeof(void*)) {
void* obj = *p;
if (is_heap_object(obj)) {
mark(obj);
}
}
}
}This is why GC pause times vary with stack depth!
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

