jonas-schievink / rcgc Goto Github PK
View Code? Open in Web Editor NEWA reference-counting, tracing garbage collector in completely safe Rust
License: Creative Commons Zero v1.0 Universal
A reference-counting, tracing garbage collector in completely safe Rust
License: Creative Commons Zero v1.0 Universal
Naively replacing Rc
with Arc
and Weak
with sync::Weak
isn't going to fly.
Freeing completely abandoned data (ie. stuff not involved in cycles) should still work without having to synchronize all threads, since that decision only depends on the strong and weak count of Handle
s, however:
Arc::strong_count
and then Arc::weak_count
is always a race and can not be relied upon to make a decision about destroying objects
Arc::is_unique
is what we actually want to check (as it synchronizes the read), but is privateArc::get_mut
returns Some
iff Arc::is_unique
returns true
right now, so it can be used insteadIf this doesn't free sufficient amounts of memory, we need to do a cycle collection. I think the simplest way to do that correctly is by pausing all threads and preventing all strong or weak counts in the entire object graph from changing. Any thread can then perform the cycle collection atomically (theoretically we could even parallelize this).
This will require either:
rcgc
to check a synchronization token on every refcount manipulationThe second option looks much better to me. That way, we will simply block all threads when they decide to access GC data, not when they're doing unrelated things. I want to stress that this requires us to check the token (an Acquire
load) on every refcount manipulation, though (ie. in Clone
and Drop
of Rooted
and Handle
).
I'm sure this idea is still broken in some way, but somehow this has made me feel like this is at least possible.
With cfg(debug_assertions)
or, since this is extremely expensive, only when a Cargo feature is enabled, we should perform a full collection every time a reference to a GC object is dropped.
This means that objects get freed as soon as the GC would be allowed to, which should expose all possible use-after-free bugs caused either by a bug in rcgc, missing roots, or incorrectly broken/moved object references.
The current test suite is extremely limited. Long-term fuzzing should, if set up correctly, provide a much more confident result regarding GC correctness.
This is pretty difficult to set up, since you basically have to generate random workloads that trigger many edge cases, but also explore real-world loads during that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.