diff options
| Commit | 99a1e76f8ae228ab93341fbf943a30fc7fe98708 (patch) | |
|---|---|---|
| Author | 2019-01-03 18:25:45 +0200 | |
| Committer | 2019-01-03 18:25:45 +0200 | |
| Files | 27348983bb8927630803f4711f4278358baa137e /website | |
| IPL-99a1e76f8ae228ab93341fbf943a30fc7fe98708.tar IPL-99a1e76f8ae228ab93341fbf943a30fc7fe98708.tar.gz IPL-99a1e76f8ae228ab93341fbf943a30fc7fe98708.zip | ||
| Parent | 4ccb2c7b7e5e81d60b0ab29437d3ddd134178b73 (diff) | |
slides for GC in spasm
2 files changed, 152 insertions, 1 deletions
| -rw-r--r-- | website/content/post/contents.md | 3 | ||||
| -rw-r--r-- | website/content/slides/10_vm_gc/_index.md | 150 |
diff --git a/website/content/post/contents.md b/website/content/post/contents.md index 351a1ac..dab06c2 100644 --- a/website/content/post/contents.md +++ b/website/content/post/contents.md @@ -34,7 +34,6 @@ Table of contents for the course. 0. Garbage Collection Theory - 0. [Theory](https://www.slideshare.net/eelcovisser/garbage-collection-69688448) 0. [Lua GC](http://www.inf.puc-rio.br/~roberto/talks/gc-lua.pdf) 0. [V8 GC](http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection) @@ -42,3 +41,5 @@ Table of contents for the course. 0. [Java Z GC](http://cr.openjdk.java.net/~pliden/slides/ZGC-FOSDEM-2018.pdf) 0. [LuaJIT GC](http://wiki.luajit.org/New-Garbage-Collector) +0. Garbage Collection in Spasm - [slides]({{< ref "/slides/10_vm_gc" >}}), + [doc](https://github.com/SofiaCPP/IPL/blob/master/website/content/slides/10_vm_gc/_index.md) diff --git a/website/content/slides/10_vm_gc/_index.md b/website/content/slides/10_vm_gc/_index.md new file mode 100644 index 0000000..09453e9 --- /dev/null +++ b/website/content/slides/10_vm_gc/_index.md @@ -0,0 +1,150 @@ +--- +title: "Garbage collection in the VM" +date: 2018-12-05T17:45:53+03:00 +draft: false +outputs: ["Reveal"] +--- +# Garbage Collection in the VM + +--- +## Contents + +1. Allocation +2. Mark and sweep +3. Embedability +4. Incremental +5. Optimizations + +--- +## Disclaimer + +> This is how GC can be implemented. Everything is subject to change. + +--- +## Allocation + +Having a custom allocator is a *must* have for most VM + +- decent performance +- optimizations + +--- +### Allocators and C++ + +[Allocators in +C++](https://sofiacpp.github.io/advanced-cpp/slides/17_allocators.html) + +--- +### Simplicity matters + +For simplicity, we are going to not use a special allocator. + +--- +## Mark and sweep + + +- mark reacheable objects starting from variables (roots) +- sweep + - unmarked objects are returned to the free heap + - marked objects are unmarked (for the next cycle) + +--- +### Mark + +- every object starts as dead +- reacheable objects are marked as alive + +--- +#### Reachable objects + + +--- +#### Roots + +- registers +- stack +- global object / environment + +Where are these stored? + +--- +#### Roots + +- The `data_stack` + - everything upto `m_SP` +- The global object + +--- +#### Marking + + void Spasm::Mark() { + for (auto cell = &data_stack[0]; cell != m_SP; ++cell) { + Mark(cell); // ? + } + Mark(m_Global); + } + +--- +#### Visit every object in the heap? + +- Visitor pattern again + +--- + + struct MarkVisitor + { + typedef void ResultType; + + void Visit(double d) const {} + void VisitUndefined() const {} + void VisitNull() const {} + void Visit(StringValue& value) const; + void Visit(ArrayValue& value) const; + void Visit(ObjectValue& value) const; + void Visit(FunctionValue& value) const; + }; + +--- + + void Visit(StringValue& value) const { + if (Dead(value)) { + SetAlive(value); + } + } + +--- + + void Visit(ArrayValue& value) const { + if (Dead(value)) { + SetAlive(value); + for (auto i = 0u; i < value.length(); ++i) { + value.item(i).Visit(*this); + } + } + } + +--- + + void Visit(ObjectValue& value) const { + if (Dead(value)) { + SetAlive(value); + for (auto* p : value.m_Properties) { + p->first.Visit(*this); + p->second.Visit(*this); + } + value.m_Prototype->Visit(*this); + } + } + +--- +#### State + +Where to store whether an object is *dead* or *alive* + +- `bool` per object, string, array, function +- `bitmap` that holds one bit for a range of objects +- `bit` per pointer + + +--- +# ? |
