Skip to content

Commit c4f21d7

Browse files
authored
gh-133171: Re-enable JUMP_BACKWARD to free-threading build (gh-137800)
1 parent c8624cd commit c4f21d7

File tree

7 files changed

+47
-34
lines changed

7 files changed

+47
-34
lines changed

.github/workflows/jit.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ jobs:
134134
make all --jobs 4
135135
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
136136
137+
jit-with-disabled-gil:
138+
name: Free-Threaded (Debug)
139+
needs: interpreter
140+
runs-on: ubuntu-24.04
141+
timeout-minutes: 90
142+
strategy:
143+
fail-fast: false
144+
matrix:
145+
llvm:
146+
- 19
147+
steps:
148+
- uses: actions/checkout@v4
149+
with:
150+
persist-credentials: false
151+
- uses: actions/setup-python@v5
152+
with:
153+
python-version: '3.11'
154+
- name: Build with JIT enabled and GIL disabled
155+
run: |
156+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
157+
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
158+
./configure --enable-experimental-jit --with-pydebug --disable-gil
159+
make all --jobs 4
160+
- name: Run tests
161+
run: |
162+
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
163+
continue-on-error: true
164+
137165
no-opt-jit:
138166
name: JIT without optimizations (Debug)
139167
needs: interpreter
@@ -160,31 +188,3 @@ jobs:
160188
- name: Run tests without optimizations
161189
run: |
162190
PYTHON_UOPS_OPTIMIZE=0 ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
163-
164-
# XXX: GH-133171
165-
# jit-with-disabled-gil:
166-
# name: Free-Threaded (Debug)
167-
# needs: interpreter
168-
# runs-on: ubuntu-24.04
169-
# timeout-minutes: 90
170-
# strategy:
171-
# fail-fast: false
172-
# matrix:
173-
# llvm:
174-
# - 19
175-
# steps:
176-
# - uses: actions/checkout@v4
177-
# with:
178-
# persist-credentials: false
179-
# - uses: actions/setup-python@v5
180-
# with:
181-
# python-version: '3.11'
182-
# - name: Build with JIT enabled and GIL disabled
183-
# run: |
184-
# sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
185-
# export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
186-
# ./configure --enable-experimental-jit --with-pydebug --disable-gil
187-
# make all --jobs 4
188-
# - name: Run tests
189-
# run: |
190-
# ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3

Include/internal/pycore_stackref.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
464464
PyStackRef_CLOSE(ref);
465465
}
466466

467+
static inline int
468+
PyStackRef_RefcountOnObject(_PyStackRef ref)
469+
{
470+
return (ref.bits & Py_TAG_REFCNT) == 0;
471+
}
472+
467473
static inline _PyStackRef
468474
PyStackRef_DUP(_PyStackRef stackref)
469475
{

Python/bytecodes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,9 +2940,10 @@ dummy_func(
29402940
};
29412941

29422942
tier1 op(_SPECIALIZE_JUMP_BACKWARD, (--)) {
2943-
#if ENABLE_SPECIALIZATION
2943+
#if ENABLE_SPECIALIZATION_FT
29442944
if (this_instr->op.code == JUMP_BACKWARD) {
2945-
this_instr->op.code = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
2945+
uint8_t desired = tstate->interp->jit ? JUMP_BACKWARD_JIT : JUMP_BACKWARD_NO_JIT;
2946+
FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, desired);
29462947
// Need to re-dispatch so the warmup counter isn't off by one:
29472948
next_instr = this_instr;
29482949
DISPATCH_SAME_OPARG();

Python/generated_cases.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ _PyOptimizer_Optimize(
119119
PyInterpreterState *interp = _PyInterpreterState_GET();
120120
assert(interp->jit);
121121
assert(!interp->compiling);
122+
#ifndef Py_GIL_DISABLED
122123
interp->compiling = true;
123124
// The first executor in a chain and the MAX_CHAIN_DEPTH'th executor *must*
124125
// make progress in order to avoid infinite loops or excessively-long
@@ -160,6 +161,9 @@ _PyOptimizer_Optimize(
160161
assert((*executor_ptr)->vm_data.valid);
161162
interp->compiling = false;
162163
return 1;
164+
#else
165+
return 0;
166+
#endif
163167
}
164168

165169
static _PyExecutorObject *

configure

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ AC_MSG_RESULT([$tier2_flags $jit_flags])
27992799
if test "$disable_gil" = "yes" -a "$enable_experimental_jit" != "no"; then
28002800
# GH-133171: This configuration builds the JIT but never actually uses it,
28012801
# which is surprising (and strictly worse than not building it at all):
2802-
AC_MSG_ERROR([--enable-experimental-jit cannot be used with --disable-gil.])
2802+
AC_MSG_WARN([--enable-experimental-jit does not work correctly with --disable-gil.])
28032803
fi
28042804

28052805
case "$ac_cv_cc_name" in

0 commit comments

Comments
 (0)