◐ Shell
clean mode source ↗

GH-137959: Replace shim code in jitted code with a single trampoline function. by markshannon · Pull Request #137961 · python/cpython

Conversation

@markshannon

Fidget-Spinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things I observed. Correct me if I'm wrong:

  1. This actually splits out the tier 2 interpreter from the tier 1 interpreter. Which is likely a significant saving for our tier 2 debug build time and tier 2 interpreter. Nice!
  2. The shim/trampoline is only compiled once lazily and reused across the whole runtime. Then reused across all JIT functions. We currently do two jumps (one into the shim/trampoline, one into the exec->jit_code). You need to lock this with a mutex in case multiple threads try to compile the shim at the same time.

If my understanding above is correct, then this is alright to me.

@markshannon

Some things I observed. Correct me if I'm wrong:

  1. This actually splits out the tier 2 interpreter from the tier 1 interpreter. Which is likely a significant saving for our tier 2 debug build time and tier 2 interpreter. Nice!
  2. The shim/trampoline is only compiled once lazily and reused across the whole runtime. Then reused across all JIT functions. We currently do two jumps (one into the shim/trampoline, one into the exec->jit_code). You need to lock this with a mutex in case multiple threads try to compile the shim at the same time.

If my understanding above is correct, then this is alright to me.

That is all correct. I'll add a comment explaining it.

@brandtbucher

Nice, sorry I wasn't able to review in time, but it looks mostly good (love the unification of the two JIT execution engines).

Two notes:

  • I prefer the old name "shim" throughout to the new name "trampoline". Trampoline already has another meaning in the JIT compiler, and we renamed this to "shim" a while back to make the distinction clearer.
  • I don't love that we leak the shim code when the runtime is finalized. We should free it in Py_Finalize or whatever.

This was referenced

Oct 18, 2025

This was referenced

Nov 13, 2025

This was referenced

Dec 19, 2025

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes

@brandtbucher brandtbucher Awaiting requested review from brandtbucher brandtbucher is a code owner

@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner

@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner

@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski savannahostrowski is a code owner

@diegorusso diegorusso Awaiting requested review from diegorusso diegorusso is a code owner