Skip to main content

JitVmGuard

Struct JitVmGuard 

Source
pub struct JitVmGuard { /* private fields */ }
Expand description

P11-S5c — RAII guard pinning the active Vm (and optional closure) pointer for JIT-emitted Rust helper calls.

§v2.0 Track J sub-step J-D — real RAII rebind

Prior to J-D, this guard’s drop was a deliberate no-op: the dispatcher always re-installed JIT_VM / JIT_CL on every enter_jit call, so the previous-dispatch values would simply be overwritten on the next entry. That trick saved 2 TLS writes per dispatch (~5-10 cycles each on arm64) — measurable on fib_28’s 434k dispatches (~1.5 ms aggregate).

Track J Option B targets cross-thread Vm move under feature = "send" (J-E flip). Once a Vm parks on thread A, moves to thread B, and dispatches there, the per-thread JIT_VM slot on thread B is null/stale at entry — enter_jit installs it fine on the way in, but on the way out the no-op drop left stale Vm pointers behind for any nested JIT entry (Lua-from-Rust-from- JIT call chains, e.g. metamethod dispatch under a JIT’d op). With nested entries restoring an outer Vm pointer becomes load-bearing.

J-D therefore turns the guard into a real RAII: enter_jit captures the prior (JIT_VM, JIT_CL) values into the guard, and Drop restores them. The cost is the 2 TLS writes we previously elided per dispatch. The single-thread-no-nesting case is semantically equivalent: prior values restored on exit are the same null/stale ones the next enter_jit would overwrite anyway; no observable behavior change for existing call sites.

NullJitBackend::enter keeps the no-op shape via noop_jit_guard — its guard has restore = None.

Debug-mode assertions still catch misuse via current_jit_vm’s is_null check IF a helper runs outside enter_jit (would happen only if some bug calls a helper symbol from interp code, which never happens by design).

Trait Implementations§

Source§

impl Drop for JitVmGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.