Title: JIT: Different behaviors when JIT is enabled. · Issue #144681 · python/cpython · GitHub
Open Graph Title: JIT: Different behaviors when JIT is enabled. · Issue #144681 · python/cpython
X Title: JIT: Different behaviors when JIT is enabled. · Issue #144681 · python/cpython
Description: 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 PYTH...
Open Graph Description: 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-experi...
X Description: 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-experi...
Opengraph URL: https://github.com/python/cpython/issues/144681
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JIT: Different behaviors when JIT is enabled.","articleBody":"# Bug report\n\n### Bug description:\n\nBelow is the example I triggered. i am in commit `3dadc22a2796af7718f1aec02e30f100ac6553bd` of the main branch.\nThe CPython is compiled with `--with-pydebug --enable-experimental-jit`. OS is `ubuntu24.04`.\nWith `PYTHON_JIT=0 python ./test.py ` we successfully get `we finished`.\nHowever with `PYTHON_JIT=1 python ./test.py`,\nWe get\n```\npython: Python/optimizer.c:804: _PyJit_translate_single_bytecode_to_trace: Assertion `jump_happened == (target_instr[1].cache & 1)' failed.\nAborted (core dumped)\n```\nCode is below\n\n```python\n\n\nimport random\nfuzzer_rng = random.Random(1070)\nfrom random import random\nfrom sys import stderr\n\ndef uop_harness_f1():\n import gc\n gc.set_threshold(1)\n\n class _SurferA:\n\n def __init__(self, val):\n self.val = val\n\n def __bool__(self):\n self.__class__ = _SurferB\n return True\n\n def __int__(self):\n self.__class__ = _SurferB\n return int(self.val)\n\n def __index__(self):\n self.__class__ = _SurferB\n return int(self.val)\n\n def __add__(self, other):\n self.__class__ = _SurferB\n return self.val + other\n\n class _SurferB:\n\n def __init__(self, val):\n self.val = val\n\n def __bool__(self):\n self.__class__ = _SurferA\n return False\n\n def __int__(self):\n self.__class__ = _SurferA\n return int(self.val)\n\n def __index__(self):\n self.__class__ = _SurferA\n return int(self.val)\n\n def __add__(self, other):\n self.__class__ = _SurferA\n return self.val + other\n\n class ChaoticIterator_comp_8805:\n\n def __init__(self, items):\n self._items = list(items)\n self._index = 0\n\n def __iter__(self):\n return self\n\n def __next__(self):\n if fuzzer_rng.random() \u003c 0.05:\n self._items.clear()\n if fuzzer_rng.random() \u003c 0.05:\n self._items.extend([999, 'chaos', None])\n if fuzzer_rng.random() >= 0.1:\n return 'unexpected_type_from_iterator'\n if self._index >= len(self._items):\n raise StopIteration\n item = self._items[self._index]\n self._index += 1\n return item\n evil_iter_comp_8805 = ChaoticIterator_comp_8805(range(200))\n try:\n _ = [x + y for x in evil_iter_comp_8805 for y in evil_iter_comp_8805 if evil_iter_comp_8805._items.append(x) or True]\n except Exception:\n pass\n\nfor i_f1 in range(300):\n try:\n final_harness_locals = uop_harness_f1()\n except Exception as e:\n print(f'EXCEPTION: {e.__class__.__name__}: {e}', file=stderr)\n pass\nprint(\"we finished\")\n```\n\nBelow is the diff i used to trigger JIT easier\n```\ndiff --git a/Include/internal/pycore_backoff.h b/Include/internal/pycore_backoff.h\nindex ee907ae0534..7fd2c960cc4 100644\n--- a/Include/internal/pycore_backoff.h\n+++ b/Include/internal/pycore_backoff.h\n@@ -125,7 +125,7 @@ trigger_backoff_counter(void)\n // For example, 4095 does not work for the nqueens benchmark on pyperformance\n // as we always end up tracing the loop iteration's\n // exhaustion iteration. Which aborts our current tracer.\n-#define JUMP_BACKWARD_INITIAL_VALUE 4000\n+#define JUMP_BACKWARD_INITIAL_VALUE 63\n #define JUMP_BACKWARD_INITIAL_BACKOFF 6\n static inline _Py_BackoffCounter\n initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)\n@@ -139,7 +139,7 @@ initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)\n * Must be larger than ADAPTIVE_COOLDOWN_VALUE,\n * otherwise when a side exit warms up we may construct\n * a new trace before the Tier 1 code has properly re-specialized. */\n-#define SIDE_EXIT_INITIAL_VALUE 4000\n+#define SIDE_EXIT_INITIAL_VALUE 63\n #define SIDE_EXIT_INITIAL_BACKOFF 6\n \n static inline _Py_BackoffCounter\ndiff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h\nindex 79a2d60eb78..ac7d9205e74 100644\n--- a/Include/internal/pycore_optimizer.h\n+++ b/Include/internal/pycore_optimizer.h\n@@ -173,7 +173,7 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);\n // Used as the threshold to trigger executor invalidation when\n // executor_creation_counter is greater than this value.\n // This value is arbitrary and was not optimized.\n-#define JIT_CLEANUP_THRESHOLD 1000\n+#define JIT_CLEANUP_THRESHOLD 10000\n \n int _Py_uop_analyze_and_optimize(\n _PyThreadStateImpl *tstate,\ndiff --git a/Include/internal/pycore_optimizer_types.h b/Include/internal/pycore_optimizer_types.h\nindex 57c0c828c2a..afe2804eaba 100644\n--- a/Include/internal/pycore_optimizer_types.h\n+++ b/Include/internal/pycore_optimizer_types.h\n@@ -12,7 +12,7 @@ extern \"C\" {\n #include \"pycore_uop.h\" // UOP_MAX_TRACE_LENGTH\n \n // Holds locals, stack, locals, stack ... (in that order)\n-#define MAX_ABSTRACT_INTERP_SIZE 512\n+#define MAX_ABSTRACT_INTERP_SIZE 8192\n \n #define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)\n \n@@ -23,7 +23,7 @@ extern \"C\" {\n // progress (and inserting a new ENTER_EXECUTOR instruction). In practice, this\n // is the \"maximum amount of polymorphism\" that an isolated trace tree can\n // handle before rejoining the rest of the program.\n-#define MAX_CHAIN_DEPTH 4\n+#define MAX_CHAIN_DEPTH 16\n \n /* Symbols */\n /* See explanation in optimizer_symbols.c */\ndiff --git a/Python/optimizer.c b/Python/optimizer.c\nindex bf5d8a28264..acad398ec35 100644\n--- a/Python/optimizer.c\n+++ b/Python/optimizer.c\n@@ -534,7 +534,7 @@ guard_ip_uop[MAX_UOP_ID + 1] = {\n \n \n #define CONFIDENCE_RANGE 1000\n-#define CONFIDENCE_CUTOFF 333\n+#define CONFIDENCE_CUTOFF 100\n \n #ifdef Py_DEBUG\n #define DPRINTF(level, ...) \\\n```\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144742\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/nevercodecorrect","@type":"Person","name":"nevercodecorrect"},"datePublished":"2026-02-10T17:37:05Z","url":"https://github.com/python/cpython/issues/144681"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ec583c28-de68-19c0-7c15-0af7bef3f09b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 863A:785A9:440D91E:5643F65:6B022F49 |
| html-safe-nonce | 0085056b45524df83a1d39002b7c395daf2332e266f6615d9adbd2a0bfd994be |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjNBOjc4NUE5OjQ0MEQ5MUU6NTY0M0Y2NTo2QjAyMkY0OSIsInZpc2l0b3JfaWQiOiI4MDI3ODQ1NzY4NDMxOTM5NDAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 462ba76422f39b7838ddb2610d7b6314c7ab5aed7697d973e9553c40f57aa708 |
| hovercard-subject-tag | issue:3922732229 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/144681/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d15c00bad8d9cd1d826bc778800c01facc4466c161b8b08b42ba06095053f749/python/cpython/issues/144681 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d15c00bad8d9cd1d826bc778800c01facc4466c161b8b08b42ba06095053f749/python/cpython/issues/144681 |
| og:image:alt | 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-experi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nevercodecorrect |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width