Skip to content

Commit

Permalink
Pointer tagging should be OR not left-shift.
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Diekmann <[email protected]>.
  • Loading branch information
ltratt committed Dec 4, 2020
1 parent 56d0156 commit 1c18d23
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ykrt/src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,23 @@ impl MTThread {
// FIXME: free up the memory when the trace is no longer used.
let ptr = Box::into_raw(Box::new(ct)) as usize;

let new_pack = PHASE_COMPILED | (ptr << PHASE_NUM_BITS);
let new_pack = ptr | PHASE_COMPILED;
loc.pack.store(new_pack, Ordering::Release);
// Free the small block of memory we used as a Location ID.
unsafe { Box::from_raw(loc_id) };
Rc::get_mut(&mut self.inner).unwrap().tracer = None;
return None;
}
PHASE_COMPILED => {
let ptr = (lp >> PHASE_NUM_BITS) as *const u8;
let bct = unsafe { Box::from_raw(ptr as *mut CompiledTrace<I>) };
let tptr = bct.ptr();
let func: fn(&mut I) -> bool = unsafe { mem::transmute(tptr) };
let p = (lp & !PHASE_TAG) as *const ();
// 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(func);
return Some(f);
}
_ => unreachable!(),
}
Expand Down

0 comments on commit 1c18d23

Please sign in to comment.