Commit Graph

92 Commits

Author SHA1 Message Date
Neil Schemenauer
c98c5b3449 gh-131253: free-threaded build support for pystats (gh-137189)
Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
2025-11-03 11:36:37 -08:00
Krishna Chaitanya
2f60b8f02f gh-140513: Fail to compile if _Py_TAIL_CALL_INTERP is set but preserve_none and musttail do not exist. (GH-140548)
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-11-01 16:41:23 +00:00
Ken Jin
a716091227 gh-140104: Set next_instr properly in the JIT during exceptions (GH-140233)
Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-10-27 18:26:47 +00:00
Ken Jin
a269e691de gh-139109: Dynamic opcode targets (GH-139111)
Make opcode targets table dynamic
2025-09-18 14:12:07 +01:00
Victor Stinner
6504f20cce gh-135755: Make Py_TAIL_CALL_INTERP macro private (#138981)
Rename Py_TAIL_CALL_INTERP to _Py_TAIL_CALL_INTERP.
2025-09-18 14:33:07 +02:00
Mark Shannon
a8d9d94784 GH-137959: Replace shim code in jitted code with a single trampoline function. (GH-137961) 2025-08-21 10:40:53 +01:00
Mark Shannon
af15e1d13e GH-132532: Add new DSL macros to better declare semantics of exits at ends of instructions/uops. (GH-137098) 2025-08-09 15:41:28 +01:00
Mark Shannon
e7b55f564d GH-136410: Faster side exits by using a cold exit stub (GH-136411) 2025-08-01 16:26:07 +01:00
Mark Shannon
ac7d5ba96e GH-133231: Changes to executor management to support proposed sys._jit module (GH-133287)
* Track the current executor, not the previous one, on the thread-state. 

* Batch executors for deallocation to avoid having to constantly incref executors; this is an ad-hoc form of deferred reference counting.
2025-05-04 10:05:35 +01:00
Ken Jin
6430c634da gh-132758: Fix tail call and pystats builds (GH-132759) 2025-04-23 18:17:35 +08:00
Mark Shannon
7099c75550 GH-131498: Cases generator: manage stacks automatically (GH-132074) 2025-04-04 17:59:36 +01:00
Mark Shannon
2bef8ea8ea GH-127705: Use _PyStackRefs in the default build. (GH-127875) 2025-03-10 14:06:56 +00:00
Ken Jin
359c7dde3b gh-129989: Properly disable tailcall interp in configure (GH-129991)
Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-02-16 03:01:24 +08:00
Ken Jin
1b27f36eb0 gh-129819: Allow tier2/JIT and tailcall (GH-129820) 2025-02-13 02:18:36 +08:00
Mark Shannon
72f56654d0 GH-128682: Account for escapes in DECREF_INPUTS (GH-129953)
* Handle escapes in DECREF_INPUTS

* Mark a few more functions as escaping

* Replace DECREF_INPUTS with PyStackRef_CLOSE where possible
2025-02-12 17:44:59 +00:00
Brandt Bucher
70e387c990 GH-129709: Clean up tier two (GH-129710) 2025-02-07 09:52:49 -08:00
Brandt Bucher
fbaa6c8ff0 GH-129763: Remove the LLTRACE macro (GH-129764) 2025-02-07 08:49:51 -08:00
Ken Jin
cb640b659e gh-128563: A new tail-calling interpreter (GH-128718)
Co-authored-by: Garrett Gu <garrettgu777@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-06 23:21:57 +08:00
Mark Shannon
96ff4c2486 GH-128682: Mark two more macros as escaping. (GH-129645)
Expand out SETLOCAL so that code generator can see the decref. Mark Py_CLEAR as escaping
2025-02-04 14:00:51 +00:00
Mark Shannon
54f74b80ae GH-128563: Move some labels, to simplify implementing tailcalling interpreter. (GH-129525) 2025-01-31 17:13:20 +00:00
Ken Jin
86c1a60d5a gh-128563: Move GO_TO_INSTRUCTION and PREDICT to cases generator (GH-129115) 2025-01-22 09:22:25 +08:00
Ken Jin
5809b25909 gh-128563: Move lltrace into the frame struct (GH-129113) 2025-01-21 22:17:15 +08:00
Mark Shannon
f5b6356a11 GH-128563: Add new frame owner type for interpreter entry frames (GH-129078)
Add new frame owner type for interpreter entry frames
2025-01-21 10:15:02 +00:00
Mark Shannon
f826beca0c GH-128375: Better instrument for FOR_ITER (GH-128445) 2025-01-06 17:54:47 +00:00
Mark Shannon
128cc47fbd GH-127705: Add debug mode for _PyStackRefs inspired by HPy debug mode (GH-128121) 2024-12-20 16:52:20 +00:00
Kumar Aditya
91c55085a9 gh-128033: change PyMutex_LockFast to take PyMutex as argument (#128054)
Change `PyMutex_LockFast` to take `PyMutex` as argument.
2024-12-18 20:49:00 +05:30
Sam Gross
71ede1142d gh-115999: Add free-threaded specialization for STORE_SUBSCR (#127169)
The specialization only depends on the type, so no special thread-safety
considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
2024-11-26 16:46:06 -05:00
Ken Jin
6293d00e72 gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2024-11-09 11:35:33 +08:00
mpage
2e95c5ba3b gh-115999: Implement thread-local bytecode and enable specialization for BINARY_OP (#123926)
Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads.

Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization.

Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
2024-11-04 11:13:32 -08:00
Mark Shannon
06ca33020e GH-125323: Convert DECREF_INPUTS_AND_REUSE_FLOAT into a function that takes PyStackRefs. (GH-125439) 2024-10-14 14:18:57 +01:00
Mark Shannon
da071fa3e8 GH-119866: Spill the stack around escaping calls. (GH-124392)
* Spill the evaluation around escaping calls in the generated interpreter and JIT. 

* The code generator tracks live, cached values so they can be saved to memory when needed.

* Spills the stack pointer around escaping calls, so that the exact stack is visible to the cycle GC.
2024-10-07 14:56:39 +01:00
Mark Shannon
bb1d30336e GH-118093: Make CALL_ALLOC_AND_ENTER_INIT suitable for tier 2. (GH-123140)
* Convert CALL_ALLOC_AND_ENTER_INIT to micro-ops such that tier 2 supports it

* Allow inexact arguments for CALL_ALLOC_AND_ENTER_INIT.
2024-08-20 16:52:58 +01:00
Mark Shannon
eec7bdaf01 GH-120024: Remove CHECK_EVAL_BREAKER macro. (GH-122968)
* Factor some instructions into micro-ops to isolate CHECK_EVAL_BREAKER for escape analysis

* Eliminate CHECK_EVAL_BREAKER macro
2024-08-14 12:04:05 +01:00
Sam Gross
1069190bad gh-122860: Remove unused macro _Py_atomic_load_relaxed_int32 (#122861) 2024-08-11 22:45:02 +05:30
Sam Gross
2b163aa9e7 gh-117657: Avoid race in PAUSE_ADAPTIVE_COUNTER in free-threaded build (#122190)
The adaptive counter doesn't do anything currently in the free-threaded
build and TSan reports a data race due to concurrent modifications to
the counter.
2024-07-30 13:53:47 -04:00
Mark Shannon
afb0aa6ed2 GH-121131: Clean up and fix some instrumented instructions. (GH-121132)
* Add support for 'prev_instr' to code generator and refactor some INSTRUMENTED instructions
2024-07-26 12:24:12 +01:00
Brandt Bucher
33903c53db GH-116017: Get rid of _COLD_EXITs (GH-120960) 2024-07-01 13:17:40 -07:00
Ken Jin
22b0de2755 gh-117139: Convert the evaluation stack to stack refs (#118450)
This PR sets up tagged pointers for CPython.

The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly.

Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out.

This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it.

The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs.

Please read Include/internal/pycore_stackref.h for more information!

---------

Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
2024-06-27 03:10:43 +08:00
Mark Shannon
8f5a01707f GH-120982: Add stack check assertions to generated interpreter code (GH-120992) 2024-06-25 16:42:29 +01:00
Tian Gao
9c14ed0618 gh-107674: Improve performance of sys.settrace (GH-117133)
* Check tracing in RESUME_CHECK

* Only change to RESUME_CHECK if not tracing
2024-05-03 19:49:24 +01:00
Dino Viehland
4a1cf66c5c gh-117657: Fix small issues with instrumentation and TSAN (#118064)
Small TSAN fixups for instrumentation
2024-04-30 11:38:05 -07:00
Mark Shannon
3e06c7f719 GH-118095: Add dynamic exit support and FOR_ITER_GEN support to tier 2 (GH-118279) 2024-04-26 18:08:50 +01:00
Mark Shannon
f180b31e76 GH-118095: Handle RETURN_GENERATOR in tier 2 (GH-118180) 2024-04-25 11:32:47 +01:00
Guido van Rossum
060a96f1a9 gh-116968: Reimplement Tier 2 counters (#117144)
Introduce a unified 16-bit backoff counter type (``_Py_BackoffCounter``),
shared between the Tier 1 adaptive specializer and the Tier 2 optimizer. The
API used for adaptive specialization counters is changed but the behavior is
(supposed to be) identical.

The behavior of the Tier 2 counters is changed:
- There are no longer dynamic thresholds (we never varied these).
- All counters now use the same exponential backoff.
- The counter for ``JUMP_BACKWARD`` starts counting down from 16.
- The ``temperature`` in side exits starts counting down from 64.
2024-04-04 15:03:27 +00:00
Michael Droettboom
26d328b2ba GH-117121: Add pystats to JIT builds (GH-117346) 2024-03-28 15:23:08 -07:00
Mark Shannon
bf82f77957 GH-116422: Tier2 hot/cold splitting (GH-116813)
Splits the "cold" path, deopts and exits, from the "hot" path, reducing the size of most jitted instructions, at the cost of slower exits.
2024-03-26 09:35:11 +00:00
Tian Gao
7895a61168 gh-116098: Revert "gh-107674: Improve performance of sys.settrace (GH-114986)" (GH-116178)
Revert "gh-107674: Improve performance of `sys.settrace` (GH-114986)"

This reverts commit 0a61e23700.
2024-03-01 07:46:33 +01:00
Brett Simmers
339c8e1c13 gh-115999: Disable the specializing adaptive interpreter in free-threaded builds (#116013)
For now, disable all specialization when the GIL might be disabled.
2024-02-29 21:53:32 -05:00
Brandt Bucher
f0df35eeca GH-115802: JIT "small" code for Windows (GH-115964) 2024-02-29 08:11:28 -08:00
Tian Gao
0a61e23700 gh-107674: Improve performance of sys.settrace (GH-114986) 2024-02-28 15:21:42 +00:00