abla/memory

Generated from source.

Import with import "abla/memory".

Source: abla/memory/entry.ab

memoryCheckpoint (fun)

fun memoryCheckpoint(): int

Returns the current allocation checkpoint for a later memory reset.

memoryReset (fun)

fun memoryReset(checkpoint: int)

Frees allocations made after the checkpoint and traps if the checkpoint cannot be reached.

memoryLiveBytes (fun)

fun memoryLiveBytes(): int

Returns the number of bytes currently tracked as allocated by the runtime.

memoryLimit (fun)

fun memoryLimit(): int

All targets start with a one-GiB tracked-heap budget. Programs which intentionally need more must raise it explicitly.

memorySetLimit (fun)

fun memorySetLimit(limit: int)

Set the tracked-heap budget; it also turns on collection under pressure. Reaching it is the "memory limit exceeded" panic, and so is reachable data held within about 1/64 of it: pressure collection does not run on every allocating call there (see standard-library.md).

memorySetCollectionGrowth (fun)

fun memorySetCollectionGrowth(bytes: int)

Turn on collection under allocation pressure (as memorySetLimit does): a collection runs at the next allocating call once the tracked heap has grown bytes (or half again, if more) past what the last collection kept. The hosted default adapts to surviving footprint and native allocation pressure. This setter selects explicit payload pacing.

memorySetFreeBlockLimit (fun)

fun memorySetFreeBlockLimit(bytes: int)

At most bytes of freed small blocks (up to 480 bytes) kept on lists by size for the next allocation of that size, past which they go back to malloc (hosted targets; the default is 128 MiB). A collection hands back the list of each size nothing allocated since the one before.

memorySetManualCollection (fun)

fun memorySetManualCollection()

Manual collection. A hosted native program collects under allocation pressure by default, which makes every allocating function a rooted safe point. Calling this anywhere main can reach compiles the program without those safe points (smaller, faster code), and at run time it stops pressure collection: only memoryCollect() frees garbage, and only the functions that can reach it keep roots. A later memorySetLimit or memorySetCollectionGrowth turns pressure collection back on (a program that can reach either keeps its safe points). Wasm and freestanding programs are manual by default.

memorySetStress (fun)

fun memorySetStress(enabled: bool): void

Test hooks for what ABLA_GC_STRESS=1 and ABLA_GC_TRACE=1 do in a program: a shared library has no process environment, so it asks by call (an export of its own). Stress collects at every safe point and poisons what it frees; trace writes a line to standard error for each collection that stopped threads and each stop abandoned. Hosted native targets; elsewhere no-ops.

memorySetStressStride (fun)

fun memorySetStressStride(stride: int): void

Under stress, collect at every stride-th safe point only (1, the default: every one), so a long run can be stressed within a time budget. A stop another thread asked for is never skipped. Hosted native targets; elsewhere a no-op.

memorySetTrace (fun)

fun memorySetTrace(enabled: bool): void

Enables or disables diagnostic tracing for the hosted garbage collector.

memorySetBackgroundFree (fun)

fun memorySetBackgroundFree(enabled: bool)

Background freeing (hosted Linux executables; elsewhere a no-op unless the program turns it on): each collection hands what it found unreachable to a helper thread of the runtime's own, which frees it while the program goes on, so a collection's pause no longer includes returning that memory to the system allocator. A release (not --fast) hosted Linux executable has it by default (the helper starts at the first collection that has something to free); memorySetBackgroundFree(false) in the program, or ABLA_GC_BACKGROUND=0 in the environment (which also wins over true), gives the plain collection back. A program that calls memorySetManualCollection has no collection to free in the background. Results are the same either way.

memorySetGcWorkers (fun)

fun memorySetGcWorkers(count: int)

The threads a collection's mark and sweep run on (2 to 8; used with background freeing, and adaptively: collections of fewer than 262,144 registry slots, and ones where threads are measured worse, run serially) when the environment's ABLA_GC_WORKERS does not say; the request is clamped to the CPUs the process may use. A program that never calls this gets 4 by default in a release build (decision #107); memorySetGcWorkers(0) or ABLA_GC_WORKERS=0 keeps the serial collector.

memoryHeapStat (fun)

fun memoryHeapStat(which: int): int

Allocator numbers for diagnostics: 0 linear memory bytes, 1 bytes ever handed out by the bump cursor, 2 / 3 bytes parked on the small / large free lists, 4 tracked live bytes, 5 collections that found every candidate from the registry, 6 that built the page directory (host targets), 7 collections that stopped other threads, 8 stops abandoned because a thread did not park in time (ABLA_GC_TRACE=1 names it), 13 the live bytes the last collection kept (host targets; 0 before the first), 14 collections finished, serial or parallel (host targets). Targets without them report 0.

memoryDebugHold (fun)

fun memoryDebugHold(mode: int): int

Test hook for the stop-the-world collector (#811): memoryDebugHold(1) arms it, and the next thread to reach a collection point (memoryCollect, a safe point) holds there, counted as stopped with its roots published, until memoryDebugHold(0) lets it go; memoryDebugHold(2) answers how many threads are held (0 or 1). Targets without threads answer 0.

MemoryCensus (class)

class MemoryCensus(
    val counts: array<int>,
    val bytes: array<int>,
    val fieldTags: array<int>,
    val overhead: int
)

What the tracked heap holds, for diagnostics (memoryCensus). Each array has an entry per allocation layout (0 words, 1 bytes such as a string's, 2 boxed values, 3 32-byte slots such as an instance's extension fields, 4 arrays, 5 class instances, 6 ropes, 7 TVars, 8 boxed array storage, 10 unsafe memory, 11 thread controls, 12 checkpoints). fieldTags counts the instances' declared fields by the tag of the value each holds (1 null, 2 int, f64 or f32, 3 bool, 4 string, 5 function, 6 cell, 7 array, 8 instance, 9-14 the runtime's shared, task, channel and TVar values). overhead is what the allocations cost past their payloads: their headers, and on Wasm the allocator's block headers and size-class rounding (a hosted target's system allocator keeps its own). A region's allocations are not counted.

memoryCensus (fun)

fun memoryCensus(): MemoryCensus

Walks the tracked heap once. It collects nothing: call memoryCollect() first to count only what is reachable.

memoryCollect (fun)

fun memoryCollect(): int

Explicit safe point. Returns the number of unreachable tracked bytes freed.

memoryPromoteString (fun)

fun memoryPromoteString(value: string): string

Copy a region-owned string into its parent allocation domain. This is the explicit lifetime boundary used when a request result must survive reset.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.