Skip to main content

Module gas_const

Module gas_const 

Source
Expand description

Shared gas / resource cost constants and the category-#2 memory footprint multiplier.

Single source of truth linked by both execution engines (the interpreter and the x86 recompiler) so their charges cannot drift. See ~/docs/spec-staging/gas-cost.md.

NOTE: the category-#3 constants (PAGE_IN_COST, COW_COST, COMPILE_COST_PER_PAGE, CALL_FRAME_COST, HOST_CALL_FLOOR, MGMT_OP_COST) are placeholders. TODO(gas-calibration): calibrate against the kernel page-fault / call-setup handler; these values are subject to change. MAX_PAGES_PER_ACCESS is an invariant, not a tunable.

Constants§

CALL_FRAME_COST
#3 call-frame base: the fixed per-CALL frame-setup cost (callee address-space page table + dispatch table + frame push), independent of code size. The code-size (compile) and read-only-page-in components are added on top by call_frame_cost. Charged at an in-kernel CALL (ecall.jar OP_HOST_CALL). TODO(gas-calibration): placeholder, subject to change.
COMPILE_COST_PER_PAGE
#3 JIT-compile cost per 4 KiB of callee code, charged at the CALL that first materializes a callee Image (O(code), bounded by MAX_CODE_SIZE). Folded into call_frame_cost. Charged in full on every CALL — the compiled image is memoized for work, never for gas — so a re-CALL into a warm Image pays the same and gas stays independent of the node-local compile cache. TODO(gas-calibration): placeholder, subject to change.
COW_COST
#3 copy-on-write (first write of a page): allocate + copy + map RW. The only fault-driven #3 charge (read-only page-in moved to the CALL). TODO(gas-calibration): placeholder (~4 KiB copy), subject to change.
HOST_CALL_FLOOR
Dynamic floor charged for a bubbled host call (ecalli imm). TODO(gas-calibration): placeholder, subject to change.
MAX_PAGES_PER_ACCESS
Max consensus 4 KiB pages a single scalar access can span.
MEM_CYCLES_BASE
Base load/store latency at the smallest footprint tier (×1). Same value as crate::gas_cost::DEFAULT_MEM_CYCLES; the #2 tier scales it (see mem_cycles_for).
MGMT_OP_COST
Dynamic cost of an in-kernel MGMT op (MOVE / COPY / DROP / …): O(1) content-addressed handle work. TODO(gas-calibration): placeholder, subject to change.
PAGE_IN_COST
#3 read-only page-in, charged per declared 2 MiB unit at the CALL (no longer per touched unit at a fault): the cost of admitting one read-only unit — code or a pinned DataCap intersected with a 2 MiB cluster — into the working set. Folded into call_frame_cost; a read at a fault charges nothing. TODO(gas-calibration): placeholder, subject to change.

Functions§

accessible_pages
Accessible 4 KiB page count for an Instance whose data extent is [data_base, mem_size) — the #2 footprint. mem_size is the high-water-mark over the Image’s memory_mappings (javm_cap::image::ImageCap::data_overlays — the single source of truth both engines derive from), so the two engines compute an identical page count. data_base is javm_cap::layout::DATA_BASE (passed in — this crate has no javm-cap dependency).
call_frame_cost
Category-#3 cost of materializing a callee sub-invocation at an in-kernel CALL, charged to the caller’s meter in addition to the ecall_dynamic_cost floor, and computed statically from the callee Image so both engines agree:
compute_scale
Category-#2 memory-access-latency footprint multiplier (×1..4), chosen from the Instance’s total accessible 4 KiB page count. Tiers from ~/docs/memory-gas.md (mem_seq / mem_rand benchmarks). The multiplier is static (resolved once at compile time) and folded into each block’s #1 cost, so it has zero runtime metering cost.
ecall_dynamic_cost
Dynamic floor charged at every ecall block (the per-op base), keyed only on the instruction type — which both engines know at the ecall, so they charge identically: ecalli (host call) → HOST_CALL_FLOOR; ecall.jar (MGMT / CALL) → MGMT_OP_COST.
mem_cycles_for
Effective per-load/store base latency after #2 footprint scaling: MEM_CYCLES_BASE × compute_scale(accessible_pages) (saturating). This is the mem_cycles value threaded into predecode / the gas simulator in place of the flat MEM_CYCLES_BASE.