Skip to content

Commit

Permalink
Reinstate code that makes sure the CompiledTrace isn't dropped.
Browse files Browse the repository at this point in the history
Also add comments to make clear what's going on here.
  • Loading branch information
ptersilie committed Dec 4, 2020
1 parent 6c30bf8 commit e65c3a2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ykrt/src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
},
thread::{self, JoinHandle},
};
use ykcompile::TraceCompiler;
use ykcompile::{CompiledTrace, TraceCompiler};
use yktrace::{sir::SIR, start_tracing, tir::TirTrace, ThreadTracer, TracingKind};

pub type HotThreshold = usize;
Expand Down Expand Up @@ -305,7 +305,13 @@ impl MTThread {
}
PHASE_COMPILED => {
let p = (lp & !PHASE_TAG) as *const ();
let f = unsafe { mem::transmute::<_, fn(&mut I) -> bool>(p) };
// Retrieve the CompiledTrace to gain access to the memory containing the
// trace.
let bct = unsafe { Box::from_raw(p as *mut CompiledTrace<I>) };
let f = unsafe { mem::transmute::<_, fn(&mut I) -> bool>(bct.ptr()) };
// Forget the CompiledTrace again to make sure it isn't dropped before we had a
// chance to execute it.
mem::forget(bct);
return Some(f);
}
_ => unreachable!(),
Expand Down

0 comments on commit e65c3a2

Please sign in to comment.