Skip to content

Commit bd91c37

Browse files
committed
gh-161676: Let the perf trampoline evaluator tail-call the trampoline
1 parent bf6623a commit bd91c37

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow the perf trampoline evaluator to tail-call the native trampoline.

‎Python/perf_trampoline.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,19 @@ compile_trampoline(void)
434434
return code_arena_new_code(perf_code_arena);
435435
}
436436

437+
// Keep the address-taken local out of the evaluator so it can tail-call the
438+
// trampoline without retaining another native frame.
439+
static Py_NO_INLINE py_trampoline
440+
get_trampoline(PyCodeObject *co)
441+
{
442+
py_trampoline trampoline = NULL;
443+
if (_PyCode_GetExtra((PyObject *)co, extra_code_index,
444+
(void **)&trampoline) != 0) {
445+
return NULL;
446+
}
447+
return trampoline;
448+
}
449+
437450
// gh-161288: the trampoline has no -fsanitize=function type signature
438451
static PyObject * _Py_NO_SANITIZE_FUNCTION
439452
py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame,
@@ -444,10 +457,9 @@ py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame,
444457
goto default_eval;
445458
}
446459
PyCodeObject *co = _PyFrame_GetCode(frame);
447-
py_trampoline f = NULL;
448460
assert(extra_code_index != -1);
449-
int ret = _PyCode_GetExtra((PyObject *)co, extra_code_index, (void **)&f);
450-
if (ret != 0 || f == NULL) {
461+
py_trampoline f = get_trampoline(co);
462+
if (f == NULL) {
451463
// This is the first time we see this code object so we need
452464
// to compile a trampoline for it.
453465
py_trampoline new_trampoline = compile_trampoline();

0 commit comments

Comments
 (0)