mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-43760: Check for tracing using 'bitwise or' instead of branch in dispatch. (GH-28723)
This commit is contained in:
parent
ef6196028f
commit
bd627eb7ed
7 changed files with 249 additions and 217 deletions
1
Include/opcode.h
generated
1
Include/opcode.h
generated
|
@ -167,6 +167,7 @@ extern "C" {
|
||||||
#define LOAD_FAST__LOAD_CONST 134
|
#define LOAD_FAST__LOAD_CONST 134
|
||||||
#define LOAD_CONST__LOAD_FAST 140
|
#define LOAD_CONST__LOAD_FAST 140
|
||||||
#define STORE_FAST__STORE_FAST 143
|
#define STORE_FAST__STORE_FAST 143
|
||||||
|
#define DO_TRACING 255
|
||||||
#ifdef NEED_OPCODE_JUMP_TABLES
|
#ifdef NEED_OPCODE_JUMP_TABLES
|
||||||
static uint32_t _PyOpcode_RelativeJump[8] = {
|
static uint32_t _PyOpcode_RelativeJump[8] = {
|
||||||
0U,
|
0U,
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
The number of hardware branches per instruction dispatch is reduced from two
|
||||||
|
to one by adding a special instruction for tracing. Patch by Mark Shannon.
|
||||||
|
|
451
Python/ceval.c
451
Python/ceval.c
File diff suppressed because it is too large
Load diff
|
@ -32,6 +32,7 @@ def write_contents(f):
|
||||||
"""
|
"""
|
||||||
opcode = find_module('opcode')
|
opcode = find_module('opcode')
|
||||||
targets = ['_unknown_opcode'] * 256
|
targets = ['_unknown_opcode'] * 256
|
||||||
|
targets[255] = "TARGET_DO_TRACING"
|
||||||
for opname, op in opcode.opmap.items():
|
for opname, op in opcode.opmap.items():
|
||||||
targets[op] = "TARGET_%s" % opname
|
targets[op] = "TARGET_%s" % opname
|
||||||
next_op = 1
|
next_op = 1
|
||||||
|
|
2
Python/opcode_targets.h
generated
2
Python/opcode_targets.h
generated
|
@ -254,5 +254,5 @@ static void *opcode_targets[256] = {
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode
|
&&TARGET_DO_TRACING
|
||||||
};
|
};
|
||||||
|
|
|
@ -268,7 +268,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (canTrace) {
|
if (canTrace) {
|
||||||
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc);
|
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0;
|
||||||
ts->tracing--;
|
ts->tracing--;
|
||||||
}
|
}
|
||||||
PyObject* args[2] = {eventName, eventArgs};
|
PyObject* args[2] = {eventName, eventArgs};
|
||||||
|
@ -283,7 +283,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
|
||||||
Py_DECREF(o);
|
Py_DECREF(o);
|
||||||
Py_CLEAR(hook);
|
Py_CLEAR(hook);
|
||||||
}
|
}
|
||||||
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc);
|
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0;
|
||||||
ts->tracing--;
|
ts->tracing--;
|
||||||
if (_PyErr_Occurred(ts)) {
|
if (_PyErr_Occurred(ts)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
|
@ -72,7 +72,7 @@ def main(opcode_py, outfile='Include/opcode.h'):
|
||||||
next_op += 1
|
next_op += 1
|
||||||
fobj.write("#define %-23s %3s\n" % (name, next_op))
|
fobj.write("#define %-23s %3s\n" % (name, next_op))
|
||||||
used[next_op] = True
|
used[next_op] = True
|
||||||
|
fobj.write("#define DO_TRACING 255\n")
|
||||||
fobj.write("#ifdef NEED_OPCODE_JUMP_TABLES\n")
|
fobj.write("#ifdef NEED_OPCODE_JUMP_TABLES\n")
|
||||||
write_int_array_from_ops("_PyOpcode_RelativeJump", opcode['hasjrel'], fobj)
|
write_int_array_from_ops("_PyOpcode_RelativeJump", opcode['hasjrel'], fobj)
|
||||||
write_int_array_from_ops("_PyOpcode_Jump", opcode['hasjrel'] + opcode['hasjabs'], fobj)
|
write_int_array_from_ops("_PyOpcode_Jump", opcode['hasjrel'] + opcode['hasjabs'], fobj)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue