jam 0.0.1
A compacting generational garbage collector for C++26
Loading...
Searching...
No Matches
jam::heap::host Class Reference
module jam.heap

Borrow a heap whose roots, barriers and reference policy belong to a host runtime. More...

Classes

class  pin
 Stable alias registration; release through its owning host. More...
struct  gap
 Padding retained by pin placement, in destination cells. More...

Public Types

enum class  generation
 Select the arena for raw allocation or publication.

Public Member Functions

 host (heap &storage, std::size_t prefix) noexcept
 Reserve an identical guard in both fresh, fixed-size generations.
 ~host () noexcept
 Release the capability after finishing its last collection.
void publish (generation which, void *target, std::size_t skip, std::size_t count) const noexcept
 Publish one generation at a stable VM-owned address.
void unpublish (void *target, std::size_t count) const noexcept
 Remove a canonical alias without releasing the host's reservation.
offset allocate (generation which, std::size_t words) noexcept
 Allocate raw cells in either generation, preserving the tag bit. A host may subdivide the extent; scanner claims determine record boundaries.
pin * pin_object (offset at, std::size_t words) noexcept
 Alias a complete allocated object without collecting or changing its offset.
void unpin (pin *value) noexcept
 Release one registration; the last release invalidates its native address.
template<class F>
void visit_pins (F &&visit) const noexcept
 Enumerate open pins as strong roots before reference policy is resolved.
std::span< gap const > gaps () const noexcept
 Placement padding to format before a VM walks the collected object stream.
void track_starts ()
 Lazily allocate VM-defined object-start bits; enable before a major epoch. Existing objects are discovered by that epoch's tracer, not by this operation.
bool tracks_starts () const noexcept
 Whether the host opted into object-start transport.
void record_start (offset at) noexcept
 Declare an actual object start after claiming or formatting the object.
std::span< bitmap const > starts (generation which) const noexcept
 Borrow the bitmap in canonical cell coordinates, one word per mini-page.
void begin (bool minor) noexcept
 Start a VM-owned marking epoch; the VM supplies barriers and weak policy.
template<class Trace>
requires std::is_nothrow_invocable_v<Trace &, visitor &, offset>
void trace (std::span< offset const > roots, Trace &&trace, std::size_t marker_limit=1, bool old_owners=false) noexcept
 Drain roots using jam's ordinary frontier and persistent worker pool.
bool marked (offset at) const noexcept
 Exact collected-generation liveness; old objects are live during minors.
bool prepare (bool promote=false) noexcept
 Freeze both forwarding tables after resolving all reference policies.
offset forward (offset at) const noexcept
 Repair a root while original objects and both forwarding tables remain intact.
void finish () noexcept
 Move survivors, preserving side aliases, then pack the consumed metadata.

Detailed Description

Borrow a heap whose roots, barriers and reference policy belong to a host runtime.

See hosting a runtime. One capability per heap; it must not outlive the heap. Ordinary Jam roots and collection are excluded.

Definition at line 1224 of file heap.ccm.

Constructor & Destructor Documentation

◆ host()

jam::heap::host::host ( heap & storage,
std::size_t prefix )
explicitnoexcept

Reserve an identical guard in both fresh, fixed-size generations.

Parameters
storageFresh heap borrowed for the capability lifetime.
prefixGuard size in eight-byte cells, a positive native-page multiple.
Precondition
Sole host capability; no ordinary Jam allocations, roots or collection.

Definition at line 2320 of file heap.ccm.

◆ ~host()

jam::heap::host::~host ( )
noexcept

Release the capability after finishing its last collection.

Precondition
On Windows, all published windows have been explicitly unpublished.

Definition at line 2331 of file heap.ccm.

Member Function Documentation

◆ allocate()

offset jam::heap::host::allocate ( generation which,
std::size_t words )
inlinenodiscardnoexcept

Allocate raw cells in either generation, preserving the tag bit. A host may subdivide the extent; scanner claims determine record boundaries.

Precondition
Positive extent fits the selected generation; no active collection.

Definition at line 1303 of file heap.ccm.

◆ begin()

void jam::heap::host::begin ( bool minor)
noexcept

Start a VM-owned marking epoch; the VM supplies barriers and weak policy.

Precondition
No jam roots, weak registrations, remembered slots or active collection.

Definition at line 2623 of file heap.ccm.

◆ finish()

void jam::heap::host::finish ( )
noexcept

Move survivors, preserving side aliases, then pack the consumed metadata.

Precondition
VM roots and old remembered fields have been repaired. Republish both aliases before resuming mutators. Majors need no combined-live-size fit in either generation.

Definition at line 2678 of file heap.ccm.

◆ pin_object()

heap::host::pin * jam::heap::host::pin_object ( offset at,
std::size_t words )
nodiscardnoexcept

Alias a complete allocated object without collecting or changing its offset.

Precondition
Idle phase, host allocation ownership; all pins agree on object extent.

Definition at line 2392 of file heap.ccm.

◆ prepare()

bool jam::heap::host::prepare ( bool promote = false)
nodiscardnoexcept

Freeze both forwarding tables after resolving all reference policies.

Returns
False if whole-nursery promotion does not fit. No forwarding is then visible; Retry without promotion in the same epoch; no further tracing is allowed. Majors retain both generations separately.

Definition at line 2653 of file heap.ccm.

◆ publish()

void jam::heap::host::publish ( generation which,
void * target,
std::size_t skip,
std::size_t count ) const
noexcept

Publish one generation at a stable VM-owned address.

Precondition
Fixed capacity, no shrink, stopped mutators; skip/count are page multiples. target corresponds to cell skip, not cell zero. The host owns the reservation. On Windows, supply a containing placeholder or the exact window previously published from this generation. Do not alter its views outside this API.

Definition at line 2339 of file heap.ccm.

◆ record_start()

void jam::heap::host::record_start ( offset at)
inlinenoexcept

Declare an actual object start after claiming or formatting the object.

Precondition
Tracking enabled; idle or marking; callers never declare pin padding.

Definition at line 1332 of file heap.ccm.

◆ trace()

template<class Trace>
requires std::is_nothrow_invocable_v<Trace &, visitor &, offset>
void jam::heap::host::trace ( std::span< offset const > roots,
Trace && trace,
std::size_t marker_limit = 1,
bool old_owners = false )
inlinenoexcept

Drain roots using jam's ordinary frontier and persistent worker pool.

Precondition
Marking phase; callbacks claim full objects before enumerating fields. marker_limit=1 keeps callbacks on the caller (e.g. a registered VM thread). old_owners admits dirty old source jobs in a minor; their targets remain young-only.

Definition at line 1353 of file heap.ccm.

◆ unpublish()

void jam::heap::host::unpublish ( void * target,
std::size_t count ) const
noexcept

Remove a canonical alias without releasing the host's reservation.

Precondition
Idle phase, stopped mutators; target/count identify an exact published window and count is in eight-byte cells. The reservation survives this call.
Postcondition
The window is inaccessible; on Windows it is one placeholder.

Definition at line 2375 of file heap.ccm.


The documentation for this class was generated from the following file: