Bug report
Bug description:
Below is the example I triggered. i am in commit 3dadc22a2796af7718f1aec02e30f100ac6553bd of the main branch.
The CPython is compiled with --with-pydebug --enable-experimental-jit. OS is ubuntu24.04.
With PYTHON_JIT=0 python ./test.py we successfully get we finished.
However with PYTHON_JIT=1 python ./test.py,
We get
python: Python/optimizer.c:804: _PyJit_translate_single_bytecode_to_trace: Assertion `jump_happened == (target_instr[1].cache & 1)' failed.
Aborted (core dumped)
Code is below
importrandomfuzzer_rng=random.Random(1070)
fromrandomimportrandomfromsysimportstderrdefuop_harness_f1():
importgcgc.set_threshold(1)
class_SurferA:
def__init__(self, val):
self.val=valdef__bool__(self):
self.__class__=_SurferBreturnTruedef__int__(self):
self.__class__=_SurferBreturnint(self.val)
def__index__(self):
self.__class__=_SurferBreturnint(self.val)
def__add__(self, other):
self.__class__=_SurferBreturnself.val+otherclass_SurferB:
def__init__(self, val):
self.val=valdef__bool__(self):
self.__class__=_SurferAreturnFalsedef__int__(self):
self.__class__=_SurferAreturnint(self.val)
def__index__(self):
self.__class__=_SurferAreturnint(self.val)
def__add__(self, other):
self.__class__=_SurferAreturnself.val+otherclassChaoticIterator_comp_8805:
def__init__(self, items):
self._items=list(items)
self._index=0def__iter__(self):
returnselfdef__next__(self):
iffuzzer_rng.random() <0.05:
self._items.clear()
iffuzzer_rng.random() <0.05:
self._items.extend([999, 'chaos', None])
iffuzzer_rng.random() >=0.1:
return'unexpected_type_from_iterator'ifself._index>=len(self._items):
raiseStopIterationitem=self._items[self._index]
self._index+=1returnitemevil_iter_comp_8805=ChaoticIterator_comp_8805(range(200))
try:
_= [x+yforxinevil_iter_comp_8805foryinevil_iter_comp_8805ifevil_iter_comp_8805._items.append(x) orTrue]
exceptException:
passfori_f1inrange(300):
try:
final_harness_locals=uop_harness_f1()
exceptExceptionase:
print(f'EXCEPTION: {e.__class__.__name__}: {e}', file=stderr)
passprint("we finished")Below is the diff i used to trigger JIT easier
diff --git a/Include/internal/pycore_backoff.h b/Include/internal/pycore_backoff.h
index ee907ae0534..7fd2c960cc4 100644
--- a/Include/internal/pycore_backoff.h
+++ b/Include/internal/pycore_backoff.h
@@ -125,7 +125,7 @@ trigger_backoff_counter(void)
// For example, 4095 does not work for the nqueens benchmark on pyperformance
// as we always end up tracing the loop iteration's
// exhaustion iteration. Which aborts our current tracer.
-#define JUMP_BACKWARD_INITIAL_VALUE 4000
+#define JUMP_BACKWARD_INITIAL_VALUE 63
#define JUMP_BACKWARD_INITIAL_BACKOFF 6
static inline _Py_BackoffCounter
initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)
@@ -139,7 +139,7 @@ initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)
* Must be larger than ADAPTIVE_COOLDOWN_VALUE,
* otherwise when a side exit warms up we may construct
* a new trace before the Tier 1 code has properly re-specialized. */
-#define SIDE_EXIT_INITIAL_VALUE 4000
+#define SIDE_EXIT_INITIAL_VALUE 63
#define SIDE_EXIT_INITIAL_BACKOFF 6
static inline _Py_BackoffCounter
diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h
index 79a2d60eb78..ac7d9205e74 100644
--- a/Include/internal/pycore_optimizer.h
+++ b/Include/internal/pycore_optimizer.h
@@ -173,7 +173,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
// Used as the threshold to trigger executor invalidation when
// executor_creation_counter is greater than this value.
// This value is arbitrary and was not optimized.
-#define JIT_CLEANUP_THRESHOLD 1000
+#define JIT_CLEANUP_THRESHOLD 10000
int _Py_uop_analyze_and_optimize(
_PyThreadStateImpl *tstate,
diff --git a/Include/internal/pycore_optimizer_types.h b/Include/internal/pycore_optimizer_types.h
index 57c0c828c2a..afe2804eaba 100644
--- a/Include/internal/pycore_optimizer_types.h
+++ b/Include/internal/pycore_optimizer_types.h
@@ -12,7 +12,7 @@ extern "C" {
#include "pycore_uop.h" // UOP_MAX_TRACE_LENGTH
// Holds locals, stack, locals, stack ... (in that order)
-#define MAX_ABSTRACT_INTERP_SIZE 512
+#define MAX_ABSTRACT_INTERP_SIZE 8192
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
@@ -23,7 +23,7 @@ extern "C" {
// progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this
// is the "maximum amount of polymorphism" that an isolated trace tree can
// handle before rejoining the rest of the program.
-#define MAX_CHAIN_DEPTH 4
+#define MAX_CHAIN_DEPTH 16
/* Symbols */
/* See explanation in optimizer_symbols.c */
diff --git a/Python/optimizer.c b/Python/optimizer.c
index bf5d8a28264..acad398ec35 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -534,7 +534,7 @@ guard_ip_uop[MAX_UOP_ID + 1] = {
#define CONFIDENCE_RANGE 1000
-#define CONFIDENCE_CUTOFF 333
+#define CONFIDENCE_CUTOFF 100
#ifdef Py_DEBUG
#define DPRINTF(level, ...) \
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
Below is the example I triggered. i am in commit
3dadc22a2796af7718f1aec02e30f100ac6553bdof the main branch.The CPython is compiled with
--with-pydebug --enable-experimental-jit. OS isubuntu24.04.With
PYTHON_JIT=0 python ./test.pywe successfully getwe finished.However with
PYTHON_JIT=1 python ./test.py,We get
Code is below
Below is the diff i used to trigger JIT easier
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs