Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle fields in VMRuntimeLimits #9739

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 9 additions & 9 deletions crates/environ/src/vmoffsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,27 @@ pub trait PtrSize {

// Offsets within `VMRuntimeLimits`

/// Return the offset of the `stack_limit` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_stack_limit(&self) -> u8 {
0
}

/// Return the offset of the `fuel_consumed` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_fuel_consumed(&self) -> u8 {
self.size()
0
}

/// Return the offset of the `epoch_deadline` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_epoch_deadline(&self) -> u8 {
self.vmruntime_limits_fuel_consumed() + 8 // `stack_limit` is a pointer; `fuel_consumed` is an `i64`
self.vmruntime_limits_fuel_consumed() + 8
}

/// Return the offset of the `stack_limit` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_stack_limit(&self) -> u8 {
self.vmruntime_limits_epoch_deadline() + 8
}

/// Return the offset of the `last_wasm_exit_fp` field of `VMRuntimeLimits`.
fn vmruntime_limits_last_wasm_exit_fp(&self) -> u8 {
self.vmruntime_limits_epoch_deadline() + 8
self.vmruntime_limits_stack_limit() + self.size()
}

/// Return the offset of the `last_wasm_exit_pc` field of `VMRuntimeLimits`.
Expand Down
15 changes: 10 additions & 5 deletions crates/wasmtime/src/runtime/vm/vmcontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,11 @@ const _: () = {
#[derive(Debug)]
#[repr(C)]
pub struct VMRuntimeLimits {
/// Current stack limit of the wasm module.
///
/// For more information see `crates/cranelift/src/lib.rs`.
pub stack_limit: UnsafeCell<usize>,

// NB: 64-bit integer fields are located first with pointer-sized fields
// trailing afterwards. That makes the offsets in this structure easier to
// calculate on 32-bit platforms as we don't have to worry about the
// alignment of 64-bit integers.
//
/// Indicator of how much fuel has been consumed and is remaining to
/// WebAssembly.
///
Expand All @@ -846,6 +846,11 @@ pub struct VMRuntimeLimits {
/// yield if running asynchronously.
pub epoch_deadline: UnsafeCell<u64>,

/// Current stack limit of the wasm module.
///
/// For more information see `crates/cranelift/src/lib.rs`.
pub stack_limit: UnsafeCell<usize>,

/// The value of the frame pointer register when we last called from Wasm to
/// the host.
///
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/arith.wat
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
;; function u0:0(i64 vmctx, i64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/basic-wat-test.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;; function u0:0(i64 vmctx, i64, i32, i32) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
8 changes: 4 additions & 4 deletions tests/disas/br_table.wat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
;; function u0:0(i64 vmctx, i64) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand Down Expand Up @@ -70,7 +70,7 @@
;; function u0:1(i64 vmctx, i64) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand Down Expand Up @@ -106,7 +106,7 @@
;; function u0:2(i64 vmctx, i64) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand All @@ -130,7 +130,7 @@
;; function u0:3(i64 vmctx, i64) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand Down
4 changes: 2 additions & 2 deletions tests/disas/byteswap.wat
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
Expand All @@ -88,7 +88,7 @@
;; function u0:1(i64 vmctx, i64, i64) -> i64 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
Expand Down
4 changes: 2 additions & 2 deletions tests/disas/call-simd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
;; function u0:0(i64 vmctx, i64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; sig0 = (i64 vmctx, i64, i8x16, i8x16) -> i8x16 tail
;; fn0 = colocated u0:1 sig0
;; const0 = 0x00000004000000030000000200000001
Expand All @@ -37,7 +37,7 @@
;; function u0:1(i64 vmctx, i64, i8x16, i8x16) -> i8x16 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i8x16, v3: i8x16):
Expand Down
4 changes: 2 additions & 2 deletions tests/disas/call.wat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
;; function u0:0(i64 vmctx, i64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; sig0 = (i64 vmctx, i64) -> i32 tail
;; fn0 = colocated u0:1 sig0
;; stack_limit = gv2
Expand All @@ -32,7 +32,7 @@
;; function u0:1(i64 vmctx, i64) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand Down
8 changes: 4 additions & 4 deletions tests/disas/dead-code.wat
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; function u0:0(i64 vmctx, i64, i32) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
Expand All @@ -49,7 +49,7 @@
;; function u0:1(i64 vmctx, i64, i32) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
Expand All @@ -62,7 +62,7 @@
;; function u0:2(i64 vmctx, i64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64):
Expand All @@ -75,7 +75,7 @@
;; function u0:3(i64 vmctx, i64, i32) -> i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
Expand Down
4 changes: 2 additions & 2 deletions tests/disas/duplicate-loads-dynamic-memory.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand All @@ -49,7 +49,7 @@
;; function u0:1(i64 vmctx, i64, i32) -> i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand Down
4 changes: 2 additions & 2 deletions tests/disas/duplicate-loads-static-memory.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand All @@ -40,7 +40,7 @@
;; function u0:1(i64 vmctx, i64, i32) -> i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> i32, i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand Down Expand Up @@ -79,7 +79,7 @@
;; function u0:1(i64 vmctx, i64, i32, i32, i32, i32) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> i32, i32, i32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand Down Expand Up @@ -69,7 +69,7 @@
;; function u0:1(i64 vmctx, i64, i32, i32, i32, i32) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned checked gv3+96
Expand Down
34 changes: 17 additions & 17 deletions tests/disas/epoch-interruption-x86.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r10
;; movq (%r10), %r10
;; movq 0x10(%r10), %r10
;; addq $0x30, %r10
;; cmpq %rsp, %r10
;; ja 0x7f
;; 18: subq $0x20, %rsp
;; ja 0x80
;; 19: subq $0x20, %rsp
;; movq %rbx, (%rsp)
;; movq %r12, 8(%rsp)
;; movq %r13, 0x10(%rsp)
;; movq 8(%rdi), %r12
;; movq 0x20(%rdi), %rbx
;; movq %rdi, %r13
;; movq (%rbx), %r9
;; movq 0x10(%r12), %rax
;; movq 8(%r12), %rax
;; cmpq %rax, %r9
;; jae 0x57
;; 46: movq (%rbx), %rdi
;; jae 0x58
;; 47: movq (%rbx), %rdi
;; cmpq %rax, %rdi
;; jae 0x64
;; jmp 0x46
;; 57: movq %r13, %rdi
;; callq 0x117
;; jmp 0x46
;; 64: movq 0x10(%r12), %rax
;; jae 0x65
;; jmp 0x47
;; 58: movq %r13, %rdi
;; callq 0x118
;; jmp 0x47
;; 65: movq 8(%r12), %rax
;; cmpq %rax, %rdi
;; jb 0x46
;; 72: movq %r13, %rdi
;; callq 0x117
;; jmp 0x46
;; 7f: ud2
;; jb 0x47
;; 73: movq %r13, %rdi
;; callq 0x118
;; jmp 0x47
;; 80: ud2
6 changes: 3 additions & 3 deletions tests/disas/epoch-interruption.wat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; function u0:0(i64 vmctx, i64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; sig0 = (i64 vmctx) -> i64 tail
;; fn0 = colocated u1:16 sig0
Expand All @@ -17,7 +17,7 @@
;; @0016 v3 = load.i64 notrap aligned v0+8
;; @0016 v5 = load.i64 notrap aligned v0+32
;; @0016 v6 = load.i64 notrap aligned v5
;; @0016 v7 = load.i64 notrap aligned v3+16
;; @0016 v7 = load.i64 notrap aligned v3+8
;; @0016 v8 = icmp uge v6, v7
;; @0016 brif v8, block3, block2(v7)
;;
Expand All @@ -34,7 +34,7 @@
;; @0017 brif v14, block7, block6(v13)
;;
;; block7 cold:
;; @0017 v15 = load.i64 notrap aligned v3+16
;; @0017 v15 = load.i64 notrap aligned v3+8
;; @0017 v16 = icmp.i64 uge v12, v15
;; @0017 brif v16, block8, block6(v15)
;;
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/f32-load.wat
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> f32 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/f32-store.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;; function u0:0(i64 vmctx, i64, i32, f32) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/f64-load.wat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
;; function u0:0(i64 vmctx, i64, i32) -> f64 tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/f64-store.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;; function u0:0(i64 vmctx, i64, i32, f64) tail {
;; gv0 = vmctx
;; gv1 = load.i64 notrap aligned readonly gv0+8
;; gv2 = load.i64 notrap aligned gv1
;; gv2 = load.i64 notrap aligned gv1+16
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned gv3+104
;; gv5 = load.i64 notrap aligned readonly checked gv3+96
Expand Down
Loading
Loading