pub struct Runtime { /* private fields */ }Expand description
The shared context of one run.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(
program: Arc<Program>,
sources: Arc<SourceMap>,
hosts: Arc<HostRegistry>,
) -> Self
pub fn new( program: Arc<Program>, sources: Arc<SourceMap>, hosts: Arc<HostRegistry>, ) -> Self
A run over program, reporting against sources and calling through
hosts, with tracing switched off.
Sourcepub fn with_trace(self, sink: Arc<dyn TraceSink>) -> Self
pub fn with_trace(self, sink: Arc<dyn TraceSink>) -> Self
Sends this run’s trace events to sink. Replaces any sink installed
earlier; the default is NullSink, which discards everything.
This is where every event but one goes: task lifecycle
(TaskSpawned, TaskCompleted, TaskCancelled), a heap’s
(HeapCollected, HeapSummary), and the entry’s own (EntryEnter,
EntryExit, RunEnded). The one exception is
TraceEvent::HostCall, which reports through
HostRegistry::set_trace instead —
a separate sink on a separate object, defaulting to its own
NullSink. An embedding that installs a sink here and expects host
calls on the same tape gets a trace with everything but those, and no
diagnostic saying the other sink was never installed.
pub fn program(&self) -> &Program
pub fn sources(&self) -> &SourceMap
Sourcepub fn hosts(&self) -> &HostRegistry
pub fn hosts(&self) -> &HostRegistry
The host boundary, so a caller can read a run’s counters after it finishes.
Sourcepub fn trace(&self, event: TraceEvent)
pub fn trace(&self, event: TraceEvent)
Records one trace event, from whichever thread produced it.
Sourcepub fn next_task_id(&self) -> u64
pub fn next_task_id(&self) -> u64
The next task id, unique across every thread of this run, and never
ENTRY_TASK.
Sourcepub fn retire_heap(&self, stats: &HeapStats)
pub fn retire_heap(&self, stats: &HeapStats)
Folds a finished heap’s totals into the run’s.
Only the counters are folded. What a retired heap last measured as live
went with the thread that owned it, so summing those would report
memory that no longer exists; see Interpreter::heap_stats for where
the live figure comes from instead.
Sourcepub fn heap_stats(&self) -> HeapStats
pub fn heap_stats(&self) -> HeapStats
What every heap retired so far has done.
Only Interpreter, the tree-walking backend, ever calls
Runtime::retire_heap. A run on Vm never does, so this stays at
HeapStats::default() for the whole of a VM run — not because the VM
is not counting, but because it counts memory in words rather than
the bytes and objects this struct holds, and there is no honest way to
fold one into the other. Reporting a zero here for a VM run would read
as a session that allocated nothing, which is worse than not
answering at all.
A Vm embedder reads
heap_words,
allocated_words,
collections and
live_words instead — see
Vm::live_words for which of those answers
“does this run still hold what it allocated”.