]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Cleanup, bugfixes to sys trace
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 18 Oct 2025 20:56:18 +0000 (21:56 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 18 Oct 2025 20:56:18 +0000 (21:56 +0100)
.gitattributes
Objects/frameobject.c
Python/bytecodes.c
Python/ceval_macros.h
Python/generated_cases.c.h
Python/generated_tracer_cases.c.h
Python/instrumentation.c
Python/optimizer.c
Tools/c-analyzer/cpython/_parser.py

index 823e3e975a23a8d78d7763083ae6949a96c90ead..58cd96c0d3290dc89640b57d3d564287ac319425 100644 (file)
@@ -97,6 +97,7 @@ Programs/test_frozenmain.h                          generated
 Python/Python-ast.c                                 generated
 Python/executor_cases.c.h                           generated
 Python/generated_cases.c.h                          generated
+Python/generated_tracer_cases.c.h                   generated
 Python/optimizer_cases.c.h                          generated
 Python/opcode_targets.h                             generated
 Python/stdlib_module_names.h                        generated
index 0cae3703d1d0c60151daa695c760435b6f29f3dc..33e57fbfc245b2eea235eaf192155ea51e5c9f35 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "frameobject.h"          // PyFrameLocalsProxyObject
 #include "opcode.h"               // EXTENDED_ARG
+#include "../Include/pytypedefs.h"
+#include "../Include/internal/pycore_optimizer.h"
 
 #include "clinic/frameobject.c.h"
 
@@ -260,7 +262,10 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
             return -1;
         }
 
+#if _Py_TIER2
         _Py_Executors_InvalidateDependency(PyInterpreterState_Get(), co, 1);
+        _Py_JITTracer_InvalidateDependency(PyThreadState_GET(), co);
+#endif
 
         _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
         _PyStackRef oldvalue = fast[i];
index 5b47782ea600873831b9945e9078788950013454..08fc82a7dd34b619373b3a17f58b97e135e8454d 100644 (file)
@@ -2971,8 +2971,11 @@ dummy_func(
                         DISPATCH();
                     }
                 }
-                _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
-                ENTER_TRACING();
+                int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
+                if (!_is_sys_tracing) {
+                    _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
+                    ENTER_TRACING();
+                }
                 // Don't add the JUMP_BACKWARD_JIT instruction to the trace.
                 DISPATCH();
             }
index f68e84e973896e2505ef2e0a586f35bf2e96ceff..39a57a6f830c827128da00b78a4672fa7f905644 100644 (file)
         } \
     } while (0);
 #  define RECORD_TRACE_NO_DISPATCH() do { \
-        int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc == NULL); \
-        if (_is_sys_tracing || IS_JIT_TRACING()  && add_to_code_trace(tstate, frame, old_code, old_func, this_instr, next_instr, opcode, oparg, _jump_taken)) { \
+        int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); \
+        if (_is_sys_tracing) { \
+            LEAVE_TRACING(); \
+        } \
+        else if ((IS_JIT_TRACING() && add_to_code_trace(tstate, frame, old_code, old_func, this_instr, next_instr, opcode, oparg, _jump_taken))) { \
             BAIL_TRACING_NO_DISPATCH(); \
         } \
     } while (0);
index c47b6bec7b27ce93ddae303b8be11ac683158ed5..3595fb6d9376fc33b2c2473b50e2b5b35bb9b16d 100644 (file)
                             DISPATCH();
                         }
                     }
-                    _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
-                    ENTER_TRACING();
+                    int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
+                    if (!_is_sys_tracing) {
+                        _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
+                        ENTER_TRACING();
+                    }
                     DISPATCH();
                 }
                 else {
index 1871af274084fc2b2bb8ae7128246881af459a2d..1f08126774180d4faea30b0af16c9ea0e97252dd 100644 (file)
                             TRACING_DISPATCH();
                         }
                     }
-                    _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
-                    ENTER_TRACING();
+                    int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
+                    if (!_is_sys_tracing) {
+                        _PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
+                        ENTER_TRACING();
+                    }
                     TRACING_DISPATCH();
                 }
                 else {
index b4b2bc5dc69f9de1571e09782dc4f0f67876b719..325acc34a1b5eeeb8ea9d39418bba92d9f392140 100644 (file)
@@ -18,6 +18,7 @@
 #include "pycore_tuple.h"         // _PyTuple_FromArraySteal()
 
 #include "opcode_ids.h"
+#include "../Include/internal/pycore_optimizer.h"
 
 
 /* Uncomment this to dump debugging output when assertions fail */
@@ -1785,6 +1786,7 @@ force_instrument_lock_held(PyCodeObject *code, PyInterpreterState *interp)
         _PyCode_Clear_Executors(code);
     }
     _Py_Executors_InvalidateDependency(interp, code, 1);
+    _Py_JITTracer_InvalidateDependency(PyThreadState_GET(), code);
 #endif
     int code_len = (int)Py_SIZE(code);
     /* Exit early to avoid creating instrumentation
index f3166afd7d59a62d0c3ea8a63f391fa29d665291..8b16edab7cd218decd6a924bdac211635843aa0f 100644 (file)
@@ -649,8 +649,6 @@ _PyJIT_translate_single_bytecode_to_trace(
 
     const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
 
-    RESERVE_RAW(expansion->nuops + needs_guard_ip + 3, "uop and various checks");
-
     ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
 
     assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
@@ -686,6 +684,9 @@ _PyJIT_translate_single_bytecode_to_trace(
         max_length--;
     }
 
+    RESERVE_RAW(expansion->nuops + needs_guard_ip + 3, "uop and various checks");
+
+
     switch (opcode) {
         case POP_JUMP_IF_NONE:
         case POP_JUMP_IF_NOT_NONE:
@@ -1543,7 +1544,6 @@ _Py_JITTracer_InvalidateDependency(PyThreadState *old_tstate, void *obj)
     _PyBloomFilter obj_filter;
     _Py_BloomFilter_Init(&obj_filter);
     _Py_BloomFilter_Add(&obj_filter, obj);
-    HEAD_LOCK(&_PyRuntime);
 
     PyInterpreterState *interp = old_tstate->interp;
 
@@ -1554,7 +1554,6 @@ _Py_JITTracer_InvalidateDependency(PyThreadState *old_tstate, void *obj)
         }
 
     }
-    HEAD_UNLOCK(&_PyRuntime);
 }
 /* Invalidate all executors */
 void
index 17c56c9e8762c6dd508b86d9df277e460b802a58..bee987cb53adab846382b6775ea9b6c415e7b469 100644 (file)
@@ -78,6 +78,7 @@ EXCLUDED = format_conf_lines([
     'Python/deepfreeze/*.c',
     'Python/frozen_modules/*.h',
     'Python/generated_cases.c.h',
+    'Python/generated_tracer_cases.c.h',
     'Python/executor_cases.c.h',
     'Python/optimizer_cases.c.h',
     'Python/opcode_targets.h',