cpython/Tools/jit
Dino Viehland 07525c9a85
gh-116818: Make `sys.settrace`, `sys.setprofile`, and monitoring thread-safe (#116775)
Makes sys.settrace, sys.setprofile, and monitoring generally thread-safe.

Mostly uses a stop-the-world approach and synchronization around the code object's _co_instrumentation_version.  There may be a little bit of extra synchronization around the monitoring data that's required to be TSAN clean.
2024-04-19 14:47:42 -07:00
..
README.md
_llvm.py
_schema.py GH-116134: JIT aarch64-pc-windows-msvc (GH-116130) 2024-03-04 10:16:56 -08:00
_stencils.py GH-117512: Allow 64-bit JIT operands on 32-bit platforms (GH-117527) 2024-04-06 08:26:43 -07:00
_targets.py GH-116017: Put JIT code and data on the same page (GH-116845) 2024-03-19 08:47:28 -07:00
_writer.py GH-117512: Allow 64-bit JIT operands on 32-bit platforms (GH-117527) 2024-04-06 08:26:43 -07:00
build.py
mypy.ini
template.c gh-116818: Make `sys.settrace`, `sys.setprofile`, and monitoring thread-safe (#116775) 2024-04-19 14:47:42 -07:00

README.md

The JIT Compiler

This version of CPython can be built with an experimental just-in-time compiler. While most everything you already know about building and using CPython is unchanged, you will probably need to install a compatible version of LLVM first.

Installing LLVM

The JIT compiler does not require end users to install any third-party dependencies, but part of it must be built using LLVM1. You are not required to build the rest of CPython using LLVM, or even the same version of LLVM (in fact, this is uncommon).

LLVM version 16 is required. Both clang and llvm-readobj need to be installed and discoverable (version suffixes, like clang-16, are okay). It's highly recommended that you also have llvm-objdump available, since this allows the build script to dump human-readable assembly for the generated code.

It's easy to install all of the required tools:

Linux

Install LLVM 16 on Ubuntu/Debian:

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16

macOS

Install LLVM 16 with Homebrew:

brew install llvm@16

Homebrew won't add any of the tools to your $PATH. That's okay; the build script knows how to find them.

Windows

Install LLVM 16 by searching for it on LLVM's GitHub releases page, clicking on "Assets", downloading the appropriate Windows installer for your platform (likely the file ending with -win64.exe), and running it. When installing, be sure to select the option labeled "Add LLVM to the system PATH".

Building

For PCbuild-based builds, pass the new --experimental-jit option to build.bat.

For all other builds, pass the new --enable-experimental-jit option to configure.

Otherwise, just configure and build as you normally would. Cross-compiling "just works", since the JIT is built for the host platform.


  1. Clang is specifically needed because it's the only C compiler with support for guaranteed tail calls (musttail), which are required by CPython's continuation-passing-style approach to JIT compilation. Since LLVM also includes other functionalities we need (namely, object file parsing and disassembly), it's convenient to only support one toolchain at this time. ↩︎