mirror of
https://github.com/python/cpython.git
synced 2026-04-15 08:11:10 +00:00
gh-131798: split recursion check to _CHECK_RECURSION_LIMIT and combine checks (GH-148070)
This commit is contained in:
parent
113038f940
commit
e7bf8eac0f
12 changed files with 1393 additions and 1271 deletions
|
|
@ -4811,8 +4811,6 @@ dummy_func(
|
|||
if (!PyStackRef_IsNull(self_or_null)) {
|
||||
arguments--;
|
||||
}
|
||||
// CPython promises to check all non-vectorcall function calls.
|
||||
EXIT_IF(_Py_ReachedRecursionLimit(tstate));
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
|
|
@ -4830,9 +4828,12 @@ dummy_func(
|
|||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
op(_CHECK_RECURSION_LIMIT, ( -- )) {
|
||||
EXIT_IF(_Py_ReachedRecursionLimit(tstate));
|
||||
}
|
||||
|
||||
tier2 op(_CALL_METHOD_DESCRIPTOR_O_INLINE, (callable, args[oparg], cfunc/4 -- res, c, s, a)) {
|
||||
assert(oparg == 2);
|
||||
EXIT_IF(_Py_ReachedRecursionLimit(tstate));
|
||||
STAT_INC(CALL, hit);
|
||||
volatile PyCFunction cfunc_v = (PyCFunction)cfunc;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]);
|
||||
|
|
@ -4855,6 +4856,7 @@ dummy_func(
|
|||
unused/1 +
|
||||
unused/2 +
|
||||
_GUARD_CALLABLE_METHOD_DESCRIPTOR_O +
|
||||
_CHECK_RECURSION_LIMIT +
|
||||
_CALL_METHOD_DESCRIPTOR_O +
|
||||
POP_TOP +
|
||||
POP_TOP +
|
||||
|
|
@ -4956,8 +4958,6 @@ dummy_func(
|
|||
}
|
||||
_PyStackRef self_stackref = args[0];
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
|
||||
// CPython promises to check all non-vectorcall function calls.
|
||||
EXIT_IF(_Py_ReachedRecursionLimit(tstate));
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, self, NULL);
|
||||
|
|
@ -4975,7 +4975,6 @@ dummy_func(
|
|||
assert(oparg == 1);
|
||||
_PyStackRef self_stackref = args[0];
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
|
||||
EXIT_IF(_Py_ReachedRecursionLimit(tstate));
|
||||
STAT_INC(CALL, hit);
|
||||
volatile PyCFunction cfunc_v = (PyCFunction)cfunc;
|
||||
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc_v, self, NULL);
|
||||
|
|
@ -4993,6 +4992,7 @@ dummy_func(
|
|||
unused/1 +
|
||||
unused/2 +
|
||||
_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS +
|
||||
_CHECK_RECURSION_LIMIT +
|
||||
_CALL_METHOD_DESCRIPTOR_NOARGS +
|
||||
_CHECK_PERIODIC_AT_END;
|
||||
|
||||
|
|
|
|||
90
Python/executor_cases.c.h
generated
90
Python/executor_cases.c.h
generated
|
|
@ -17086,11 +17086,6 @@
|
|||
if (!PyStackRef_IsNull(self_or_null)) {
|
||||
arguments--;
|
||||
}
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
|
|
@ -17119,6 +17114,76 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _CHECK_RECURSION_LIMIT_r00: {
|
||||
CHECK_CURRENT_CACHED_VALUES(0);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _CHECK_RECURSION_LIMIT_r11: {
|
||||
CHECK_CURRENT_CACHED_VALUES(1);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(1);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(1);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _CHECK_RECURSION_LIMIT_r22: {
|
||||
CHECK_CURRENT_CACHED_VALUES(2);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache1 = _stack_item_1;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache1 = _stack_item_1;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _CHECK_RECURSION_LIMIT_r33: {
|
||||
CHECK_CURRENT_CACHED_VALUES(3);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
_PyStackRef _stack_item_2 = _tos_cache2;
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache2 = _stack_item_2;
|
||||
_tos_cache1 = _stack_item_1;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache2 = _stack_item_2;
|
||||
_tos_cache1 = _stack_item_1;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _CALL_METHOD_DESCRIPTOR_O_INLINE_r03: {
|
||||
CHECK_CURRENT_CACHED_VALUES(0);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
|
|
@ -17133,11 +17198,6 @@
|
|||
callable = stack_pointer[-1 - oparg];
|
||||
PyObject *cfunc = (PyObject *)CURRENT_OPERAND0_64();
|
||||
assert(oparg == 2);
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
volatile PyCFunction cfunc_v = (PyCFunction)cfunc;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]);
|
||||
|
|
@ -17361,11 +17421,6 @@
|
|||
}
|
||||
_PyStackRef self_stackref = args[0];
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
|
|
@ -17407,11 +17462,6 @@
|
|||
assert(oparg == 1);
|
||||
_PyStackRef self_stackref = args[0];
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
volatile PyCFunction cfunc_v = (PyCFunction)cfunc;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
|
|
|
|||
26
Python/generated_cases.c.h
generated
26
Python/generated_cases.c.h
generated
|
|
@ -4006,6 +4006,14 @@
|
|||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
}
|
||||
// _CHECK_RECURSION_LIMIT
|
||||
{
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
}
|
||||
// _CALL_METHOD_DESCRIPTOR_NOARGS
|
||||
{
|
||||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
|
||||
|
|
@ -4016,11 +4024,6 @@
|
|||
}
|
||||
_PyStackRef self_stackref = args[0];
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
|
|
@ -4111,6 +4114,14 @@
|
|||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
}
|
||||
// _CHECK_RECURSION_LIMIT
|
||||
{
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
}
|
||||
// _CALL_METHOD_DESCRIPTOR_O
|
||||
{
|
||||
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
|
||||
|
|
@ -4119,11 +4130,6 @@
|
|||
if (!PyStackRef_IsNull(self_or_null)) {
|
||||
arguments--;
|
||||
}
|
||||
if (_Py_ReachedRecursionLimit(tstate)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
STAT_INC(CALL, hit);
|
||||
PyCFunction cfunc = method->d_method->ml_meth;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
|
|
|
|||
|
|
@ -1397,6 +1397,13 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_CHECK_RECURSION_LIMIT, ( -- )) {
|
||||
if (ctx->frame->is_c_recursion_checked) {
|
||||
ADD_OP(_NOP, 0, 0);
|
||||
}
|
||||
ctx->frame->is_c_recursion_checked = true;
|
||||
}
|
||||
|
||||
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
|
||||
PyObject *callable_o = sym_get_const(ctx, callable);
|
||||
if (callable_o && Py_IS_TYPE(callable_o, &PyMethodDescr_Type)
|
||||
|
|
|
|||
8
Python/optimizer_cases.c.h
generated
8
Python/optimizer_cases.c.h
generated
|
|
@ -4136,6 +4136,14 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _CHECK_RECURSION_LIMIT: {
|
||||
if (ctx->frame->is_c_recursion_checked) {
|
||||
ADD_OP(_NOP, 0, 0);
|
||||
}
|
||||
ctx->frame->is_c_recursion_checked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case _CALL_METHOD_DESCRIPTOR_O_INLINE: {
|
||||
JitOptRef res;
|
||||
JitOptRef c;
|
||||
|
|
|
|||
|
|
@ -1514,6 +1514,7 @@ _Py_uop_frame_new(
|
|||
frame->globals_watched = false;
|
||||
frame->func = NULL;
|
||||
frame->caller = false;
|
||||
frame->is_c_recursion_checked = false;
|
||||
if (ctx->locals.used > ctx->locals.end || ctx->stack.used > ctx->stack.end) {
|
||||
ctx->done = true;
|
||||
ctx->out_of_space = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue