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.jarOP_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 byMAX_CODE_SIZE). Folded intocall_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 (seemem_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_sizeis the high-water-mark over the Image’smemory_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_baseisjavm_cap::layout::DATA_BASE(passed in — this crate has nojavm-capdependency). - 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_costfloor, 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
ecallblock (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 themem_cyclesvalue threaded into predecode / the gas simulator in place of the flatMEM_CYCLES_BASE.