Implement the semi-space copying garbage collector#13107
Implement the semi-space copying garbage collector#13107fitzgen wants to merge 8 commits intobytecodealliance:mainfrom
Conversation
This is a classic semi-space copying collector that uses bump allocation and Cheney-style worklists to avoid an explicit stack for grey (relocated but not yet scanned) objects outside the GC heap. Forwarding "pointers" (really `VMGcRef` indices) are stored inline in objects in the old semi-space, which again avoids explicit data structures outside of the GC heap. Furthermore, an intrusive linked-list of all `externref`s is maintained to allow for efficiently sweeping their associated host data after collection (and, once again, avoiding additional data structures outside the GC heap). Allocation in compiled Wasm code always happens by calling out to the `gc_alloc_raw` libcall currently. This is expected to become inline bump allocation, very similar to the null collector, in a follow-up commit shortly after this one. It is delayed to make review easier. Collection is not incremental (in the Wasmtime sense, not the GC literature sense) yet and the `CopyingCollection::collect_increment` implementation only has a single increment. This is delayed to make review easier and is also expected to come shortly in follow-up commits. I've also added new disas tests for the copying collector and also enabled running wast tests which need a GC heap with the copying collector. Finally, fuzz config generation can now generate configurations that enable the copying collector.
Subscribe to Label Actioncc @fitzgen DetailsThis issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:ref-types"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
alexcrichton
left a comment
There was a problem hiding this comment.
Overall I think this looks fantastic, thanks so much!
I've got some minor comments below, but I'm also happy to defer anything to issues as you see fit. My rough assumption as well is that long-term we'll want nurseries as well, right? If that's the case would it make sense to document that in an issue as an open future work item?
|
Oh, also, to kick the tire some more I might recommend locally making the copying collector the default (instead of drc) and running the full test suite. Iunno if that'll turn up much but might be good as a first pass |
Not totally clear to me right now. A nursery probably isn't worth it for our typical short-running programs, since we can mostly just avoid collecting in those cases, and would only slow down wasm execution via the write barriers it would require. (Also, our amortized GC heap growth algorithm effectively means we have N nursery collections on the way to the full heap size, if you squint hard.) But someone with long-running wasm instance use cases may indeed want a nursery. But then we also wouldn't want to force a nursery on the short-running use cases that don't need it. Seems like the kind of bridge we can cross when we get to it. I wouldn't go so far as to say that we should expect it to happen with enough certainty that a tracking issue is required at this time. |
|
Adding this to the merge queue now, but we can definitely continue with some of these other bits in follow ups. |
This is a classic semi-space copying collector that uses bump allocation and Cheney-style worklists to avoid an explicit stack for grey (relocated but not yet scanned) objects outside the GC heap. Forwarding "pointers" (really
VMGcRefindices) are stored inline in objects in the old semi-space, which again avoids explicit data structures outside of the GC heap. Furthermore, an intrusive linked-list of allexternrefs is maintained to allow for efficiently sweeping their associated host data after collection (and, once again, avoiding additional data structures outside the GC heap).Allocation in compiled Wasm code always happens by calling out to the
gc_alloc_rawlibcall currently. This is expected to become inline bump allocation, very similar to the null collector, in a follow-up commit shortly after this one. It is delayed to make review easier.Collection is not incremental (in the Wasmtime sense, not the GC literature sense) yet and the
CopyingCollection::collect_incrementimplementation only has a single increment. This is delayed to make review easier and is also expected to come shortly in follow-up commits.I've also added new disas tests for the copying collector and also enabled running wast tests which need a GC heap with the copying collector.
Finally, fuzz config generation can now generate configurations that enable the copying collector.