From 6c30bf8579f0ea54919eeccff1030f1b3605851a Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Fri, 4 Dec 2020 11:41:53 +0000 Subject: [PATCH] Pointer tagging should be OR not left-shift. --- ykrt/src/mt.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ykrt/src/mt.rs b/ykrt/src/mt.rs index cc1f8ed6d..7a25a5371 100644 --- a/ykrt/src/mt.rs +++ b/ykrt/src/mt.rs @@ -10,7 +10,7 @@ use std::{ }, thread::{self, JoinHandle}, }; -use ykcompile::{CompiledTrace, TraceCompiler}; +use ykcompile::TraceCompiler; use yktrace::{sir::SIR, start_tracing, tir::TirTrace, ThreadTracer, TracingKind}; pub type HotThreshold = usize; @@ -296,7 +296,7 @@ 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) }; @@ -304,12 +304,9 @@ impl MTThread { return None; } PHASE_COMPILED => { - let ptr = (lp >> PHASE_NUM_BITS) as *const u8; - let bct = unsafe { Box::from_raw(ptr as *mut CompiledTrace) }; - let tptr = bct.ptr(); - let func: fn(&mut I) -> bool = unsafe { mem::transmute(tptr) }; - mem::forget(bct); - return Some(func); + let p = (lp & !PHASE_TAG) as *const (); + let f = unsafe { mem::transmute::<_, fn(&mut I) -> bool>(p) }; + return Some(f); } _ => unreachable!(), }