pub struct JitCodeCache { /* private fields */ }Expand description
Cache of JIT-compiled function pointers, keyed by content hash.
Same blob hash = skip recompilation, reuse function pointer.
Tracks dependency edges so that when an inlined callee changes, all callers that embedded it can be invalidated.
§Safety
The raw *const u8 pointers stored here point into Cranelift
JITModule memory regions. Callers must ensure that the
JITModule that produced a pointer outlives any use of that
pointer through this cache.
Implementations§
Source§impl JitCodeCache
impl JitCodeCache
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a cache pre-sized for capacity entries.
Sourcepub fn get(&self, hash: &FunctionHash) -> Option<*const u8>
pub fn get(&self, hash: &FunctionHash) -> Option<*const u8>
Look up a cached native code pointer by content hash.
Sourcepub fn insert(&mut self, hash: FunctionHash, ptr: *const u8)
pub fn insert(&mut self, hash: FunctionHash, ptr: *const u8)
Insert a compiled function pointer for the given content hash.
Creates a minimal CacheEntry with no dependencies and zero
version/epoch. If an entry with the same hash already exists
it is overwritten.
Sourcepub fn insert_entry(&mut self, entry: CacheEntry)
pub fn insert_entry(&mut self, entry: CacheEntry)
Insert a cache entry with full dependency information.
Builds reverse-index edges so that invalidate_by_dependency()
can find this entry when any of its dependencies change.
Sourcepub fn invalidate_by_dependency(
&mut self,
changed_hash: &FunctionHash,
) -> Vec<FunctionHash>
pub fn invalidate_by_dependency( &mut self, changed_hash: &FunctionHash, ) -> Vec<FunctionHash>
Invalidate all entries that depend on the given function hash.
Performs a transitive walk: if A depends on B and B depends on C, invalidating C will remove both B and A.
Returns the list of invalidated function hashes.
Sourcepub fn get_entry(&self, hash: &FunctionHash) -> Option<&CacheEntry>
pub fn get_entry(&self, hash: &FunctionHash) -> Option<&CacheEntry>
Get a cache entry with full metadata.
Sourcepub fn contains(&self, hash: &FunctionHash) -> bool
pub fn contains(&self, hash: &FunctionHash) -> bool
Check whether a function with the given hash has been compiled.
Trait Implementations§
Source§impl Default for JitCodeCache
impl Default for JitCodeCache
impl Send for JitCodeCache
impl Sync for JitCodeCache
Auto Trait Implementations§
impl Freeze for JitCodeCache
impl RefUnwindSafe for JitCodeCache
impl Unpin for JitCodeCache
impl UnsafeUnpin for JitCodeCache
impl UnwindSafe for JitCodeCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more