|
jam 0.0.1
A compacting generational garbage collector for C++26
|
A circular, double-mapped arena with bounded parallel compaction.Compressed four-byte offsets address two generations of up to 16 GiB each. The high bit selects young; the remaining bits count eight-byte cells. Record alignment up to 64 bytes is retained by dilation and padding between independent rank blocks. Allocation and liveness always use eight-byte cells. Clients trace complete byte-relocatable records; the heap does not infer boundaries or run destructors. This storage contract extends beyond ISO C++ trivial-copy guarantees: moving representation bytes must preserve meaning after ptr fields are forwarded. Raw address-dependent state and required destruction are unsupported. Multiple markers may trace a frozen heap. Join them before compaction, mutation, allocation, or inspecting metadata. Borrows expire on movement. More...
Classes | |
| class | root_handle |
| A four-byte handle to a collector-updated external root slot.Copies share a registration; moves leave the source detached and null. Operations on registered handles require the owning heap current and a quiescent collector. The heap must outlive all its registered handles. More... | |
| class | visitor |
| One marker's claim and edge-discovery interface.Only a successful claimant visits the record's fields. The visitor is borrowed for one callback and must not escape it. More... | |
| struct | generation |
| One generation's ordered double-mapped arena and collection metadata. More... | |
| class | host |
| Borrow a heap whose roots, barriers and reference policy belong to a host runtime. More... | |
Public Types | |
| using | word = std::uint64_t |
| Eight-byte allocation cell. | |
| using | offset = std::uint32_t |
| Stored reference, in eight-byte units from data(). | |
| using | bitmap = offset |
| Allocation/live bitmap. | |
| using | block = detail::heap_block |
| Live bitmap, forwarding base and pointer-field bitmap. | |
| template<class T> | |
| using | ptr = jam::ptr<T> |
| The compact pointer type for this heap. | |
| template<class T> | |
| using | weak_ptr = jam::weak_ptr<T> |
| The weak field type for this heap. | |
Public Member Functions | |
| char const * | compactor_name () const noexcept |
| Runtime-selected compaction implementation, including SIMD ISA admission. | |
| std::size_t | remembered_size () const noexcept |
| Number of distinct old source slots retained in the current GC epoch. | |
| template<class T> | |
| void | remember (ptr< T > const &value) noexcept |
| Explicitly register a pointer after a caller-managed unsafe write. | |
| template<class T> | |
| void | remember (std::span< ptr< T > > values) noexcept |
| Register a contiguous group after bulk unsafe assignment. | |
| template<class T> | |
| void | remember (weak_ptr< T > const &value) noexcept |
| Register a weak old-to-young slot for rewriting, never for marking. | |
| template<class T> | |
| void | remember (std::span< weak_ptr< T > > values) noexcept |
| Register weak slots after bulk unsafe assignment, dropping stale entries. | |
| heap (heap_options config={}) | |
| Construct a heap and one persistent pool sized for both collection phases. | |
| generation const & | old () const noexcept |
| Inspect generation zero's arena. | |
| generation const & | young () const noexcept |
| Inspect generation one's arena. | |
| heap_options | configuration () const noexcept |
| Read the immutable construction policy with typed page counts. | |
| ~heap () noexcept | |
| Release the arena; every attached root must already be destroyed. | |
| root_handle | root (offset at) noexcept |
| Register a record or null in the current heap. | |
| template<class T> requires traceable<T> | |
| jam::root< T > | root (ptr< T > const &at) noexcept |
| Register a typed external root with its type-specific tracing callback. | |
| template<class T> requires traceable<T> | |
| jam::weak_root< T > | weak_root (ptr< T > const &at) noexcept |
| Register an external weak slot, forwarded but never used to seed marking. | |
| template<traceable K, traceable V, traceable F> | |
| jam::weak< V > | mk_weak (ptr< K > const &key, ptr< V > const &value, ptr< F > const &finalizer, std::type_identity_t< void(*)(F *) noexcept > runner) noexcept |
| Associate a weak key and value with a managed finalizer and stateless runner. | |
| void | collect () noexcept |
| Collect typed roots, running minor_collections minors between majors. The first minor_collections calls are minor; the next call is major. Explicit major collection resets the countdown; explicit minors leave it unchanged.Nonnull untyped roots or untyped visitor.field edges require collect(trace). External ptr copies expire, including stack variables and loaded snapshots. Only registered roots retain their meaning; reacquire pointers from them. | |
| void | collect_major () noexcept |
| Trace both generations and compact survivors into old; reset the countdown. | |
| void | collect_minor (bool promote=false) noexcept |
| Collect young without walking old; optionally promote survivors; preserve the countdown. | |
| template<class Trace> requires std::is_nothrow_invocable_v<Trace &, visitor &, offset> | |
| void | collect (Trace &&trace) noexcept |
| Scheduled collection with a fallback tracer for untyped records. | |
|
template<class Trace> requires std::is_nothrow_invocable_v<Trace &, visitor &, offset> | |
| void | collect_major (Trace &&trace) noexcept |
| Major collection with a fallback tracer; reset the countdown.Uses the same tracing and synchronization contract as collect(trace). | |
|
template<class Trace> requires std::is_nothrow_invocable_v<Trace &, visitor &, offset> | |
| void | collect_minor (Trace &&trace, bool promote=false) noexcept |
| Minor collection with a fallback tracer and optional promotion; preserve the countdown.Uses the same tracing and synchronization contract as collect(trace). | |
|
template<class T, class... Args> requires traceable<T> | |
| ptr< T > | mk (Args &&... args) noexcept |
| Allocate and copy a typed record, returning an unrooted reference.Construct T from the arguments. Register a root before collecting; copies of the returned ptr do not keep the target alive. Allocation preserves pointers. | |
| template<class T> requires traceable<T> | |
| T * | address (ptr< T > const &at) noexcept |
| Borrow a typed target; the address expires on growth or collection. | |
| template<class T> requires traceable<T> | |
| T | load (ptr< T > const &at) const noexcept |
| Read a typed value snapshot; any pointers in it expire on collection. | |
| template<class T> requires traceable<T> | |
| void | store (ptr< T > const &at, T const &value) noexcept |
| Replace a typed record's bytes without changing its extent or type. | |
Static Public Member Functions | |
| static heap * | current () noexcept |
| Read the current thread's dynamically bound heap. Implicit operations require an active heap_scope. Binding stores invalidate this pure accessor; it is not const and may change between scopes. | |
Static Public Attributes | |
| static constexpr offset | null = 0 |
| Unreachable reference preserved by forwarding. | |
| static constexpr std::size_t | block_words = 32 |
| Eight-byte cells in one rank block: 32. | |
| static constexpr unsigned | fields_per_word = 2 |
| Four-byte pointer fields per allocation cell. | |
A circular, double-mapped arena with bounded parallel compaction.
Compressed four-byte offsets address two generations of up to 16 GiB each. The high bit selects young; the remaining bits count eight-byte cells. Record alignment up to 64 bytes is retained by dilation and padding between independent rank blocks. Allocation and liveness always use eight-byte cells. Clients trace complete byte-relocatable records; the heap does not infer boundaries or run destructors. This storage contract extends beyond ISO C++ trivial-copy guarantees: moving representation bytes must preserve meaning after ptr fields are forwarded. Raw address-dependent state and required destruction are unsupported. Multiple markers may trace a frozen heap. Join them before compaction, mutation, allocation, or inspecting metadata. Borrows expire on movement.
|
nodiscardnoexcept |
Associate a weak key and value with a managed finalizer and stateless runner.
|
inlinenodiscardnoexcept |