Skip to content

Commit 5fe4b85

Browse files
committed
Rename VMRuntimeLimits to VMStoreContext
Way back in time, this struct originally contained the stack and fuel limits. Then it also got the epoch deadline. Then it also got the exit FP/PC and entry FP. Now it is just the place where we put per-store mutable data that is accessed by JIT code and must be shared between all `VMContext`s. So it is time to rename it. This commit is purely mechanical and just renames the type and various methods and variables that use/access it.
1 parent 4a430a6 commit 5fe4b85

File tree

19 files changed

+203
-178
lines changed

19 files changed

+203
-178
lines changed

crates/cranelift/src/compiler.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl wasmtime_environ::Compiler for Compiler {
224224
// The way that stack overflow is handled here is by adding a prologue
225225
// check to all functions for how much native stack is remaining. The
226226
// `VMContext` pointer is the first argument to all functions, and the
227-
// first field of this structure is `*const VMRuntimeLimits` and the
227+
// first field of this structure is `*const VMStoreContext` and the
228228
// first field of that is the stack limit. Note that the stack limit in
229229
// this case means "if the stack pointer goes below this, trap". Each
230230
// function which consumes stack space or isn't a leaf function starts
@@ -255,7 +255,7 @@ impl wasmtime_environ::Compiler for Compiler {
255255
});
256256
let stack_limit = context.func.create_global_value(ir::GlobalValueData::Load {
257257
base: interrupts_ptr,
258-
offset: i32::from(func_env.offsets.ptr.vmruntime_limits_stack_limit()).into(),
258+
offset: i32::from(func_env.offsets.ptr.vmstore_context_stack_limit()).into(),
259259
global_type: isa.pointer_type(),
260260
flags: MemFlags::trusted(),
261261
});
@@ -393,13 +393,13 @@ impl wasmtime_environ::Compiler for Compiler {
393393
wasmtime_environ::VMCONTEXT_MAGIC,
394394
);
395395
let ptr = isa.pointer_bytes();
396-
let limits = builder.ins().load(
396+
let vm_store_context = builder.ins().load(
397397
pointer_type,
398398
MemFlags::trusted(),
399399
caller_vmctx,
400-
i32::from(ptr.vmcontext_runtime_limits()),
400+
i32::from(ptr.vmcontext_store_context()),
401401
);
402-
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr, limits);
402+
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr, vm_store_context);
403403

404404
// Spill all wasm arguments to the stack in `ValRaw` slots.
405405
let (args_base, args_len) =
@@ -592,13 +592,13 @@ impl wasmtime_environ::Compiler for Compiler {
592592
// additionally perform the "routine of the exit trampoline" of saving
593593
// fp/pc/etc.
594594
debug_assert_vmctx_kind(isa, &mut builder, vmctx, wasmtime_environ::VMCONTEXT_MAGIC);
595-
let limits = builder.ins().load(
595+
let vm_store_context = builder.ins().load(
596596
pointer_type,
597597
MemFlags::trusted(),
598598
vmctx,
599-
ptr_size.vmcontext_runtime_limits(),
599+
ptr_size.vmcontext_store_context(),
600600
);
601-
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr_size, limits);
601+
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr_size, vm_store_context);
602602

603603
// Now it's time to delegate to the actual builtin. Forward all our own
604604
// arguments to the libcall itself.
@@ -1157,24 +1157,24 @@ fn save_last_wasm_entry_fp(
11571157
builder: &mut FunctionBuilder,
11581158
pointer_type: ir::Type,
11591159
ptr_size: &impl PtrSize,
1160-
vm_runtime_limits_offset: u32,
1160+
vm_store_context_offset: u32,
11611161
vmctx: Value,
11621162
) {
1163-
// First we need to get the `VMRuntimeLimits`.
1164-
let limits = builder.ins().load(
1163+
// First we need to get the `VMStoreContext`.
1164+
let vm_store_context = builder.ins().load(
11651165
pointer_type,
11661166
MemFlags::trusted(),
11671167
vmctx,
1168-
i32::try_from(vm_runtime_limits_offset).unwrap(),
1168+
i32::try_from(vm_store_context_offset).unwrap(),
11691169
);
11701170

11711171
// Then store our current stack pointer into the appropriate slot.
11721172
let fp = builder.ins().get_frame_pointer(pointer_type);
11731173
builder.ins().store(
11741174
MemFlags::trusted(),
11751175
fp,
1176-
limits,
1177-
ptr_size.vmruntime_limits_last_wasm_entry_fp(),
1176+
vm_store_context,
1177+
ptr_size.vmstore_context_last_wasm_entry_fp(),
11781178
);
11791179
}
11801180

@@ -1201,14 +1201,14 @@ fn save_last_wasm_exit_fp_and_pc(
12011201
MemFlags::trusted(),
12021202
wasm_fp,
12031203
limits,
1204-
ptr.vmruntime_limits_last_wasm_exit_fp(),
1204+
ptr.vmstore_context_last_wasm_exit_fp(),
12051205
);
12061206
// Finally save the Wasm return address to the limits.
12071207
let wasm_pc = builder.ins().get_return_address(pointer_type);
12081208
builder.ins().store(
12091209
MemFlags::trusted(),
12101210
wasm_pc,
12111211
limits,
1212-
ptr.vmruntime_limits_last_wasm_exit_pc(),
1212+
ptr.vmstore_context_last_wasm_exit_pc(),
12131213
);
12141214
}

crates/cranelift/src/compiler/component.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,17 +856,17 @@ impl ComponentCompiler for Compiler {
856856
wasmtime_environ::component::VMCOMPONENT_MAGIC,
857857
);
858858
if let Abi::Wasm = abi {
859-
let limits = c.builder.ins().load(
859+
let vm_store_context = c.builder.ins().load(
860860
pointer_type,
861861
MemFlags::trusted(),
862862
vmctx,
863-
i32::try_from(c.offsets.limits()).unwrap(),
863+
i32::try_from(c.offsets.vm_store_context()).unwrap(),
864864
);
865865
super::save_last_wasm_exit_fp_and_pc(
866866
&mut c.builder,
867867
pointer_type,
868868
&c.offsets.ptr,
869-
limits,
869+
vm_store_context,
870870
);
871871
}
872872

crates/cranelift/src/func_environ.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ pub struct FuncEnvironment<'module_environment> {
130130
/// A function-local variable which stores the cached value of the amount of
131131
/// fuel remaining to execute. If used this is modified frequently so it's
132132
/// stored locally as a variable instead of always referenced from the field
133-
/// in `*const VMRuntimeLimits`
133+
/// in `*const VMStoreContext`
134134
fuel_var: cranelift_frontend::Variable,
135135

136136
/// A function-local variable which caches the value of `*const
137-
/// VMRuntimeLimits` for this function's vmctx argument. This pointer is stored
137+
/// VMStoreContext` for this function's vmctx argument. This pointer is stored
138138
/// in the vmctx itself, but never changes for the lifetime of the function,
139139
/// so if we load it up front we can continue to use it throughout.
140-
vmruntime_limits_ptr: ir::Value,
140+
vmstore_context_ptr: ir::Value,
141141

142142
/// A cached epoch deadline value, when performing epoch-based
143-
/// interruption. Loaded from `VMRuntimeLimits` and reloaded after
143+
/// interruption. Loaded from `VMStoreContext` and reloaded after
144144
/// any yield.
145145
epoch_deadline_var: cranelift_frontend::Variable,
146146

@@ -199,7 +199,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
199199
fuel_var: Variable::new(0),
200200
epoch_deadline_var: Variable::new(0),
201201
epoch_ptr_var: Variable::new(0),
202-
vmruntime_limits_ptr: ir::Value::reserved_value(),
202+
vmstore_context_ptr: ir::Value::reserved_value(),
203203

204204
// Start with at least one fuel being consumed because even empty
205205
// functions should consume at least some fuel.
@@ -304,17 +304,17 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
304304
}
305305
}
306306

307-
fn declare_vmruntime_limits_ptr(&mut self, builder: &mut FunctionBuilder<'_>) {
308-
// We load the `*const VMRuntimeLimits` value stored within vmctx at the
307+
fn declare_vmstore_context_ptr(&mut self, builder: &mut FunctionBuilder<'_>) {
308+
// We load the `*const VMStoreContext` value stored within vmctx at the
309309
// head of the function and reuse the same value across the entire
310310
// function. This is possible since we know that the pointer never
311311
// changes for the lifetime of the function.
312312
let pointer_type = self.pointer_type();
313313
let vmctx = self.vmctx(builder.func);
314314
let base = builder.ins().global_value(pointer_type, vmctx);
315315
let offset = i32::from(self.offsets.ptr.vmctx_runtime_limits());
316-
debug_assert!(self.vmruntime_limits_ptr.is_reserved_value());
317-
self.vmruntime_limits_ptr =
316+
debug_assert!(self.vmstore_context_ptr.is_reserved_value());
317+
self.vmstore_context_ptr =
318318
builder
319319
.ins()
320320
.load(pointer_type, ir::MemFlags::trusted(), base, offset);
@@ -324,7 +324,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
324324
// On function entry we load the amount of fuel into a function-local
325325
// `self.fuel_var` to make fuel modifications fast locally. This cache
326326
// is then periodically flushed to the Store-defined location in
327-
// `VMRuntimeLimits` later.
327+
// `VMStoreContext` later.
328328
builder.declare_var(self.fuel_var, ir::types::I64);
329329
self.fuel_load_into_var(builder);
330330
self.fuel_check(builder);
@@ -372,13 +372,13 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
372372
match op {
373373
// Exiting a function (via a return or unreachable) or otherwise
374374
// entering a different function (via a call) means that we need to
375-
// update the fuel consumption in `VMRuntimeLimits` because we're
375+
// update the fuel consumption in `VMStoreContext` because we're
376376
// about to move control out of this function itself and the fuel
377377
// may need to be read.
378378
//
379379
// Before this we need to update the fuel counter from our own cost
380380
// leading up to this function call, and then we can store
381-
// `self.fuel_var` into `VMRuntimeLimits`.
381+
// `self.fuel_var` into `VMStoreContext`.
382382
Operator::Unreachable
383383
| Operator::Return
384384
| Operator::CallIndirect { .. }
@@ -463,7 +463,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
463463
builder.def_var(self.fuel_var, fuel);
464464
}
465465

466-
/// Loads the fuel consumption value from `VMRuntimeLimits` into `self.fuel_var`
466+
/// Loads the fuel consumption value from `VMStoreContext` into `self.fuel_var`
467467
fn fuel_load_into_var(&mut self, builder: &mut FunctionBuilder<'_>) {
468468
let (addr, offset) = self.fuel_addr_offset();
469469
let fuel = builder
@@ -473,7 +473,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
473473
}
474474

475475
/// Stores the fuel consumption value from `self.fuel_var` into
476-
/// `VMRuntimeLimits`.
476+
/// `VMStoreContext`.
477477
fn fuel_save_from_var(&mut self, builder: &mut FunctionBuilder<'_>) {
478478
let (addr, offset) = self.fuel_addr_offset();
479479
let fuel_consumed = builder.use_var(self.fuel_var);
@@ -483,12 +483,12 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
483483
}
484484

485485
/// Returns the `(address, offset)` of the fuel consumption within
486-
/// `VMRuntimeLimits`, used to perform loads/stores later.
486+
/// `VMStoreContext`, used to perform loads/stores later.
487487
fn fuel_addr_offset(&mut self) -> (ir::Value, ir::immediates::Offset32) {
488-
debug_assert!(!self.vmruntime_limits_ptr.is_reserved_value());
488+
debug_assert!(!self.vmstore_context_ptr.is_reserved_value());
489489
(
490-
self.vmruntime_limits_ptr,
491-
i32::from(self.offsets.ptr.vmruntime_limits_fuel_consumed()).into(),
490+
self.vmstore_context_ptr,
491+
i32::from(self.offsets.ptr.vmstore_context_fuel_consumed()).into(),
492492
)
493493
}
494494

@@ -676,9 +676,9 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
676676
builder.ins().load(
677677
ir::types::I64,
678678
ir::MemFlags::trusted(),
679-
self.vmruntime_limits_ptr,
679+
self.vmstore_context_ptr,
680680
ir::immediates::Offset32::new(
681-
self.offsets.ptr.vmruntime_limits_epoch_deadline() as i32
681+
self.offsets.ptr.vmstore_context_epoch_deadline() as i32
682682
),
683683
);
684684
builder.def_var(self.epoch_deadline_var, deadline);
@@ -3088,10 +3088,10 @@ impl FuncEnvironment<'_> {
30883088
self.conditionally_trap(builder, overflow, ir::TrapCode::STACK_OVERFLOW);
30893089
}
30903090

3091-
// If the `vmruntime_limits_ptr` variable will get used then we initialize
3092-
// it here.
3091+
// If the `vmstore_context_ptr` variable will get used then we
3092+
// initialize it here.
30933093
if self.tunables.consume_fuel || self.tunables.epoch_interruption {
3094-
self.declare_vmruntime_limits_ptr(builder);
3094+
self.declare_vmstore_context_ptr(builder);
30953095
}
30963096
// Additionally we initialize `fuel_var` if it will get used.
30973097
if self.tunables.consume_fuel {

crates/environ/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ macro_rules! foreach_builtin_function {
116116
// Wasm code, so that it doesn't need to make a libcall to go from
117117
// id to `VMFuncRef`. That will be a little tricky: it will also
118118
// require updating the pointer to the slab in the `VMContext` (or
119-
// `VMRuntimeLimits` or wherever we put it) when the slab is
119+
// `VMStoreContext` or wherever we put it) when the slab is
120120
// resized.
121121
#[cfg(feature = "gc")]
122122
get_interned_func_ref(

crates/environ/src/component/vmcomponent_offsets.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// struct VMComponentContext {
44
// magic: u32,
55
// builtins: &'static VMComponentBuiltins,
6-
// limits: *const VMRuntimeLimits,
6+
// limits: *const VMStoreContext,
77
// flags: [VMGlobalDefinition; component.num_runtime_component_instances],
88
// trampoline_func_refs: [VMFuncRef; component.num_trampolines],
99
// lowerings: [VMLowering; component.num_lowerings],
@@ -61,7 +61,7 @@ pub struct VMComponentOffsets<P> {
6161
// precalculated offsets of various member fields
6262
magic: u32,
6363
builtins: u32,
64-
limits: u32,
64+
vm_store_context: u32,
6565
flags: u32,
6666
trampoline_func_refs: u32,
6767
lowerings: u32,
@@ -98,7 +98,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
9898
num_resources: component.num_resources,
9999
magic: 0,
100100
builtins: 0,
101-
limits: 0,
101+
vm_store_context: 0,
102102
flags: 0,
103103
trampoline_func_refs: 0,
104104
lowerings: 0,
@@ -138,7 +138,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
138138
size(magic) = 4u32,
139139
align(u32::from(ret.ptr.size())),
140140
size(builtins) = ret.ptr.size(),
141-
size(limits) = ret.ptr.size(),
141+
size(vm_store_context) = ret.ptr.size(),
142142
align(16),
143143
size(flags) = cmul(ret.num_runtime_component_instances, ret.ptr.size_of_vmglobal_definition()),
144144
align(u32::from(ret.ptr.size())),
@@ -186,10 +186,10 @@ impl<P: PtrSize> VMComponentOffsets<P> {
186186
self.flags + index.as_u32() * u32::from(self.ptr.size_of_vmglobal_definition())
187187
}
188188

189-
/// The offset of the `limits` field.
189+
/// The offset of the `vm_store_context` field.
190190
#[inline]
191-
pub fn limits(&self) -> u32 {
192-
self.limits
191+
pub fn vm_store_context(&self) -> u32 {
192+
self.vm_store_context
193193
}
194194

195195
/// The offset of the `trampoline_func_refs` field.

0 commit comments

Comments
 (0)