Skip to content

Commit afa1ddd

Browse files
committed
Store protectors outside Item, pack Tag and Perm
Previously, Item was a struct of a NonZeroU64, an Option which was usually unset or irrelevant, and a 4-variant enum. So collectively, the size of an Item was 24 bytes, but only 8 bytes were used for the most part. So this takes advantage of the fact that it is probably impossible to exhaust the total space of SbTags, and steals 3 bits from it to pack the whole struct into a single u64. This bit-packing means that we reduce peak memory usage when Miri goes memory-bound by ~3x. We also get CPU performance improvements of varying size, because not only are we simply accessing less memory, we can now compare a Vec<Item> using a memcmp because it does not have any padding.
1 parent 6e10661 commit afa1ddd

14 files changed

+233
-114
lines changed

src/machine.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ pub struct FrameData<'tcx> {
5454
/// for the start of this frame. When we finish executing this frame,
5555
/// we use this to register a completed event with `measureme`.
5656
pub timing: Option<measureme::DetachedTiming>,
57+
58+
pub protected_tags: Vec<SbTag>,
5759
}
5860

5961
impl<'tcx> std::fmt::Debug for FrameData<'tcx> {
6062
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6163
// Omitting `timing`, it does not support `Debug`.
62-
let FrameData { call_id, catch_unwind, timing: _ } = self;
64+
let FrameData { call_id, catch_unwind, timing: _, protected_tags } = self;
6365
f.debug_struct("FrameData")
6466
.field("call_id", call_id)
6567
.field("catch_unwind", catch_unwind)
68+
.field("protected_tags", protected_tags)
6669
.finish()
6770
}
6871
}
@@ -788,6 +791,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
788791
range,
789792
machine.stacked_borrows.as_ref().unwrap(),
790793
machine.current_span(),
794+
&machine.threads,
791795
)?;
792796
}
793797
if let Some(weak_memory) = &alloc_extra.weak_memory {
@@ -819,6 +823,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
819823
range,
820824
machine.stacked_borrows.as_ref().unwrap(),
821825
machine.current_span(),
826+
&machine.threads,
822827
)?;
823828
}
824829
if let Some(weak_memory) = &alloc_extra.weak_memory {
@@ -852,6 +857,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
852857
tag,
853858
range,
854859
machine.stacked_borrows.as_ref().unwrap(),
860+
&machine.threads,
855861
)
856862
} else {
857863
Ok(())
@@ -892,7 +898,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
892898
stacked_borrows.borrow_mut().new_call()
893899
});
894900

895-
let extra = FrameData { call_id, catch_unwind: None, timing };
901+
let extra = FrameData { call_id, catch_unwind: None, timing, protected_tags: Vec::new() };
896902
Ok(frame.with_extra(extra))
897903
}
898904

@@ -936,7 +942,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
936942
) -> InterpResult<'tcx, StackPopJump> {
937943
let timing = frame.extra.timing.take();
938944
if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
939-
stacked_borrows.borrow_mut().end_call(frame.extra.call_id);
945+
stacked_borrows.borrow_mut().end_call(&frame.extra);
940946
}
941947
let res = ecx.handle_stack_pop_unwind(frame.extra, unwinding);
942948
if let Some(profiler) = ecx.machine.profiler.as_ref() {

0 commit comments

Comments
 (0)