Skip to content

Commit e982010

Browse files
authored
Only index into heap once when adding to over-approximated stack roots list (#12970)
1 parent c8ebad7 commit e982010

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

  • crates/wasmtime/src/runtime/vm/gc/enabled

crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -853,21 +853,20 @@ unsafe impl GcHeap for DrcHeap {
853853
}
854854

855855
fn expose_gc_ref_to_wasm(&mut self, gc_ref: VMGcRef) {
856+
// Read the current list head before borrowing through index_mut.
857+
let next = (*self.over_approximated_stack_roots)
858+
.as_ref()
859+
.map(|r| r.unchecked_copy());
856860
let header = self.index_mut(drc_ref(&gc_ref));
857861
if header.is_in_over_approximated_stack_roots() {
858862
// Already in the over-approximated-stack-roots list, nothing more
859863
// to do here.
860864
return;
861865
}
862-
863866
// Push this object onto the head of the over-approximated-stack-roots
864-
// list.
867+
// list using a single index_mut call.
865868
header.set_in_over_approximated_stack_roots_bit(true);
866-
let next = (*self.over_approximated_stack_roots)
867-
.as_ref()
868-
.map(|r| r.unchecked_copy());
869-
self.index_mut(drc_ref(&gc_ref))
870-
.set_next_over_approximated_stack_root(next);
869+
header.set_next_over_approximated_stack_root(next);
871870
*self.over_approximated_stack_roots = Some(gc_ref);
872871
}
873872

0 commit comments

Comments
 (0)