Skip to content

perf_jit activated from a subinterpreter publishes JIT executors with the trampoline's unwind info #157247

Description

@stratakis

Bug report

Bug description:

sys.activate_stack_trampoline() refuses to run while the JIT is active, but it only checks the current interpreter, and the perf state is process-wide. A subinterpreter can activate perf_jit while the main interpreter keeps its JIT.

import sys
from concurrent import interpreters

interpreters.create().exec("import sys; sys.activate_stack_trampoline('perf_jit')")

def hot(n):
    t = 0
    for i in range(n):
        t += i & 3
    return t

for _ in range(50):
    hot(100000)

With PYTHON_JIT=1 ./python buggy_stuff.py on a --enable-experimental-jit build, the resulting /tmp/jit-.dump holds the JIT's executors (records named py::jit:executor), and every one of them is tagged with the unwind information of the 8-byte perf trampoline. Executor frames look different, so perf produces wrong stacks for samples inside JIT code.

Found while working on #157246

CPython versions tested on:

CPython main branch, 3.16

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions