Skip to content

Commit 4d23e21

Browse files
committed
ZJIT: Avoid copying frame states in stack maps
build_stack_map only reads FrameState. It cloned the input state and cloned each caller state through Function::frame_state. Function::frame_state calls Function::find. Function::find clones the Snapshot and resolves its stack and local InsnId values. The input state clone does not resolve IDs. Borrow the stored states instead. Resolve each stack InsnId with Function::find_id before JITState::get_opnd. This avoids FrameState allocation and copies of its stack and locals vectors during stack-map construction. The generated stack map is unchanged.
1 parent 0bdfb4c commit 4d23e21

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎zjit/src/codegen.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,10 +3503,10 @@ fn gen_prepare_fallback_call(jit: &JITState, asm: &mut Assembler, function: &Fun
35033503
/// on the native stack are known.
35043504
fn build_stack_map(jit: &JITState, function: &Function, state: &FrameState) -> Vec<StackMapEntry> {
35053505
let mut stack = Vec::new();
3506-
let mut current_state = state.clone();
3506+
let mut current_state = state;
35073507
loop {
35083508
stack.extend(current_state.stack().rev().copied().map(|insn_id| {
3509-
let opnd = jit.get_opnd(insn_id);
3509+
let opnd = jit.get_opnd(function.find_id(insn_id));
35103510
assert!(
35113511
matches!(opnd, Opnd::Value(_) | Opnd::VReg { .. }),
35123512
"FrameState should only reference Opnd::Value or Opnd::VReg, but got: {opnd:?}",
@@ -3518,7 +3518,7 @@ fn build_stack_map(jit: &JITState, function: &Function, state: &FrameState) -> V
35183518
break;
35193519
};
35203520
stack.push(StackMapEntry::Skip(inline_frame_stack_gap(current_state.iseq)));
3521-
current_state = function.frame_state(caller);
3521+
current_state = function.frame_state_ref(caller);
35223522
}
35233523
stack
35243524
}

0 commit comments

Comments
 (0)