YJIT: Print Rc strong and weak count on assert failure

For <https://bugs.ruby-lang.org/issues/21716>, the panic is looking like
some sort of third party memory corruption, with YJIT taking the fall.
At the point of this assert, the assembler has dropped, so there's
nothing in YJIT's code other than JITState that could be holding on to
these transient `PendingBranchRef`.

The strong count being more than a handful or the weak count is non-zero
shows that someone in the process (likely some native extension)
corrupted the Rc's counts.
This commit is contained in:
Alan Wu 2025-12-16 13:33:47 -05:00
parent f3d1557d5c
commit eaa952b536
Notes: git 2025-12-16 19:57:22 +00:00

View File

@ -2419,7 +2419,9 @@ impl<'a> JITState<'a> {
// Pending branches => actual branches
outgoing: MutableBranchList(Cell::new(self.pending_outgoing.into_iter().map(|pending_out| {
let pending_out = Rc::try_unwrap(pending_out)
.ok().expect("all PendingBranchRefs should be unique when ready to construct a Block");
.unwrap_or_else(|rc| panic!(
"PendingBranchRef should be unique when ready to construct a Block. \
strong={} weak={}", Rc::strong_count(&rc), Rc::weak_count(&rc)));
pending_out.into_branch(NonNull::new(blockref as *mut Block).expect("no null from Box"))
}).collect()))
});