Skip to content

Commit d114944

Browse files
Cleanup, bugfixes to sys trace
1 parent 093578c commit d114944

File tree

9 files changed

+32
-12
lines changed

9 files changed

+32
-12
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Programs/test_frozenmain.h generated
9797
Python/Python-ast.c generated
9898
Python/executor_cases.c.h generated
9999
Python/generated_cases.c.h generated
100+
Python/generated_tracer_cases.c.h generated
100101
Python/optimizer_cases.c.h generated
101102
Python/opcode_targets.h generated
102103
Python/stdlib_module_names.h generated

Objects/frameobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "frameobject.h" // PyFrameLocalsProxyObject
1919
#include "opcode.h" // EXTENDED_ARG
20+
#include "../Include/pytypedefs.h"
21+
#include "../Include/internal/pycore_optimizer.h"
2022

2123
#include "clinic/frameobject.c.h"
2224

@@ -260,7 +262,10 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
260262
return -1;
261263
}
262264

265+
#if _Py_TIER2
263266
_Py_Executors_InvalidateDependency(PyInterpreterState_Get(), co, 1);
267+
_Py_JITTracer_InvalidateDependency(PyThreadState_GET(), co);
268+
#endif
264269

265270
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
266271
_PyStackRef oldvalue = fast[i];

Python/bytecodes.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,8 +2971,11 @@ dummy_func(
29712971
DISPATCH();
29722972
}
29732973
}
2974-
_PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
2975-
ENTER_TRACING();
2974+
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);
2975+
if (!_is_sys_tracing) {
2976+
_PyJIT_InitializeTracing(tstate, frame, this_instr, STACK_LEVEL(), 0, NULL);
2977+
ENTER_TRACING();
2978+
}
29762979
// Don't add the JUMP_BACKWARD_JIT instruction to the trace.
29772980
DISPATCH();
29782981
}

Python/ceval_macros.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@
161161
} \
162162
} while (0);
163163
# define RECORD_TRACE_NO_DISPATCH() do { \
164-
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc == NULL); \
165-
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)) { \
164+
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); \
165+
if (_is_sys_tracing) { \
166+
LEAVE_TRACING(); \
167+
} \
168+
else if ((IS_JIT_TRACING() && add_to_code_trace(tstate, frame, old_code, old_func, this_instr, next_instr, opcode, oparg, _jump_taken))) { \
166169
BAIL_TRACING_NO_DISPATCH(); \
167170
} \
168171
} while (0);

Python/generated_cases.c.h

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

Python/generated_tracer_cases.c.h

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

Python/instrumentation.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "pycore_tuple.h" // _PyTuple_FromArraySteal()
1919

2020
#include "opcode_ids.h"
21+
#include "../Include/internal/pycore_optimizer.h"
2122

2223

2324
/* Uncomment this to dump debugging output when assertions fail */
@@ -1785,6 +1786,7 @@ force_instrument_lock_held(PyCodeObject *code, PyInterpreterState *interp)
17851786
_PyCode_Clear_Executors(code);
17861787
}
17871788
_Py_Executors_InvalidateDependency(interp, code, 1);
1789+
_Py_JITTracer_InvalidateDependency(PyThreadState_GET(), code);
17881790
#endif
17891791
int code_len = (int)Py_SIZE(code);
17901792
/* Exit early to avoid creating instrumentation

Python/optimizer.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,6 @@ _PyJIT_translate_single_bytecode_to_trace(
649649

650650
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
651651

652-
RESERVE_RAW(expansion->nuops + needs_guard_ip + 3, "uop and various checks");
653-
654652
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
655653

656654
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
@@ -686,6 +684,9 @@ _PyJIT_translate_single_bytecode_to_trace(
686684
max_length--;
687685
}
688686

687+
RESERVE_RAW(expansion->nuops + needs_guard_ip + 3, "uop and various checks");
688+
689+
689690
switch (opcode) {
690691
case POP_JUMP_IF_NONE:
691692
case POP_JUMP_IF_NOT_NONE:
@@ -1543,7 +1544,6 @@ _Py_JITTracer_InvalidateDependency(PyThreadState *old_tstate, void *obj)
15431544
_PyBloomFilter obj_filter;
15441545
_Py_BloomFilter_Init(&obj_filter);
15451546
_Py_BloomFilter_Add(&obj_filter, obj);
1546-
HEAD_LOCK(&_PyRuntime);
15471547

15481548
PyInterpreterState *interp = old_tstate->interp;
15491549

@@ -1554,7 +1554,6 @@ _Py_JITTracer_InvalidateDependency(PyThreadState *old_tstate, void *obj)
15541554
}
15551555

15561556
}
1557-
HEAD_UNLOCK(&_PyRuntime);
15581557
}
15591558
/* Invalidate all executors */
15601559
void

Tools/c-analyzer/cpython/_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def format_tsv_lines(lines):
7878
'Python/deepfreeze/*.c',
7979
'Python/frozen_modules/*.h',
8080
'Python/generated_cases.c.h',
81+
'Python/generated_tracer_cases.c.h',
8182
'Python/executor_cases.c.h',
8283
'Python/optimizer_cases.c.h',
8384
'Python/opcode_targets.h',

0 commit comments

Comments
 (0)