mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-103865: add monitoring support to LOAD_SUPER_ATTR (#103866)
This commit is contained in:
parent
febcc6ccfb
commit
f40890b124
10 changed files with 535 additions and 236 deletions
|
@ -1582,6 +1582,14 @@ dummy_func(
|
|||
PREDICT(JUMP_BACKWARD);
|
||||
}
|
||||
|
||||
inst(INSTRUMENTED_LOAD_SUPER_ATTR, (unused/9, unused, unused, unused -- unused if (oparg & 1), unused)) {
|
||||
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
|
||||
// cancel out the decrement that will happen in LOAD_SUPER_ATTR; we
|
||||
// don't want to specialize instrumented instructions
|
||||
INCREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
|
||||
}
|
||||
|
||||
family(load_super_attr, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
|
||||
LOAD_SUPER_ATTR,
|
||||
LOAD_SUPER_ATTR_ATTR,
|
||||
|
@ -1602,10 +1610,34 @@ dummy_func(
|
|||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
|
||||
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
|
||||
PyObject *arg = oparg & 2 ? class : &_PyInstrumentation_MISSING;
|
||||
int err = _Py_call_instrumentation_2args(
|
||||
tstate, PY_MONITORING_EVENT_CALL,
|
||||
frame, next_instr-1, global_super, arg);
|
||||
ERROR_IF(err, error);
|
||||
}
|
||||
|
||||
// we make no attempt to optimize here; specializations should
|
||||
// handle any case whose performance we care about
|
||||
PyObject *stack[] = {class, self};
|
||||
PyObject *super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
|
||||
if (opcode == INSTRUMENTED_LOAD_SUPER_ATTR) {
|
||||
PyObject *arg = oparg & 2 ? class : &_PyInstrumentation_MISSING;
|
||||
if (super == NULL) {
|
||||
_Py_call_instrumentation_exc2(
|
||||
tstate, PY_MONITORING_EVENT_C_RAISE,
|
||||
frame, next_instr-1, global_super, arg);
|
||||
}
|
||||
else {
|
||||
int err = _Py_call_instrumentation_2args(
|
||||
tstate, PY_MONITORING_EVENT_C_RETURN,
|
||||
frame, next_instr-1, global_super, arg);
|
||||
if (err < 0) {
|
||||
Py_CLEAR(super);
|
||||
}
|
||||
}
|
||||
}
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(super == NULL, error);
|
||||
res = PyObject_GetAttr(super, name);
|
||||
|
|
|
@ -4846,6 +4846,8 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
|
|||
int opcode = asdl_seq_LEN(meth->v.Attribute.value->v.Call.args) ?
|
||||
LOAD_SUPER_METHOD : LOAD_ZERO_SUPER_METHOD;
|
||||
ADDOP_NAME(c, loc, opcode, meth->v.Attribute.attr, names);
|
||||
loc = update_start_location_to_match_attr(c, loc, meth);
|
||||
ADDOP(c, loc, NOP);
|
||||
} else {
|
||||
VISIT(c, expr, meth->v.Attribute.value);
|
||||
loc = update_start_location_to_match_attr(c, loc, meth);
|
||||
|
@ -6079,6 +6081,8 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
|
|||
int opcode = asdl_seq_LEN(e->v.Attribute.value->v.Call.args) ?
|
||||
LOAD_SUPER_ATTR : LOAD_ZERO_SUPER_ATTR;
|
||||
ADDOP_NAME(c, loc, opcode, e->v.Attribute.attr, names);
|
||||
loc = update_start_location_to_match_attr(c, loc, e);
|
||||
ADDOP(c, loc, NOP);
|
||||
return SUCCESS;
|
||||
}
|
||||
VISIT(c, expr, e->v.Attribute.value);
|
||||
|
|
490
Python/generated_cases.c.h
generated
490
Python/generated_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -35,6 +35,8 @@ static const int8_t EVENT_FOR_OPCODE[256] = {
|
|||
[INSTRUMENTED_CALL] = PY_MONITORING_EVENT_CALL,
|
||||
[CALL_FUNCTION_EX] = PY_MONITORING_EVENT_CALL,
|
||||
[INSTRUMENTED_CALL_FUNCTION_EX] = PY_MONITORING_EVENT_CALL,
|
||||
[LOAD_SUPER_ATTR] = PY_MONITORING_EVENT_CALL,
|
||||
[INSTRUMENTED_LOAD_SUPER_ATTR] = PY_MONITORING_EVENT_CALL,
|
||||
[RESUME] = -1,
|
||||
[YIELD_VALUE] = PY_MONITORING_EVENT_PY_YIELD,
|
||||
[INSTRUMENTED_YIELD_VALUE] = PY_MONITORING_EVENT_PY_YIELD,
|
||||
|
@ -74,6 +76,7 @@ static const uint8_t DE_INSTRUMENT[256] = {
|
|||
[INSTRUMENTED_FOR_ITER] = FOR_ITER,
|
||||
[INSTRUMENTED_END_FOR] = END_FOR,
|
||||
[INSTRUMENTED_END_SEND] = END_SEND,
|
||||
[INSTRUMENTED_LOAD_SUPER_ATTR] = LOAD_SUPER_ATTR,
|
||||
};
|
||||
|
||||
static const uint8_t INSTRUMENTED_OPCODES[256] = {
|
||||
|
@ -107,6 +110,8 @@ static const uint8_t INSTRUMENTED_OPCODES[256] = {
|
|||
[INSTRUMENTED_END_SEND] = INSTRUMENTED_END_SEND,
|
||||
[FOR_ITER] = INSTRUMENTED_FOR_ITER,
|
||||
[INSTRUMENTED_FOR_ITER] = INSTRUMENTED_FOR_ITER,
|
||||
[LOAD_SUPER_ATTR] = INSTRUMENTED_LOAD_SUPER_ATTR,
|
||||
[INSTRUMENTED_LOAD_SUPER_ATTR] = INSTRUMENTED_LOAD_SUPER_ATTR,
|
||||
|
||||
[INSTRUMENTED_LINE] = INSTRUMENTED_LINE,
|
||||
[INSTRUMENTED_INSTRUCTION] = INSTRUMENTED_INSTRUCTION,
|
||||
|
|
|
@ -211,6 +211,8 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
return 1;
|
||||
case MAP_ADD:
|
||||
return 2;
|
||||
case INSTRUMENTED_LOAD_SUPER_ATTR:
|
||||
return 3;
|
||||
case LOAD_SUPER_ATTR:
|
||||
return 3;
|
||||
case LOAD_SUPER_ATTR_ATTR:
|
||||
|
@ -605,6 +607,8 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
return 0;
|
||||
case MAP_ADD:
|
||||
return 0;
|
||||
case INSTRUMENTED_LOAD_SUPER_ATTR:
|
||||
return ((oparg & 1) ? 1 : 0) + 1;
|
||||
case LOAD_SUPER_ATTR:
|
||||
return ((oparg & 1) ? 1 : 0) + 1;
|
||||
case LOAD_SUPER_ATTR_ATTR:
|
||||
|
@ -902,6 +906,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
|
|||
[DICT_UPDATE] = { true, INSTR_FMT_IB },
|
||||
[DICT_MERGE] = { true, INSTR_FMT_IB },
|
||||
[MAP_ADD] = { true, INSTR_FMT_IB },
|
||||
[INSTRUMENTED_LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC00000000 },
|
||||
[LOAD_SUPER_ATTR] = { true, INSTR_FMT_IBC },
|
||||
[LOAD_SUPER_ATTR_ATTR] = { true, INSTR_FMT_IBC },
|
||||
[LOAD_SUPER_ATTR_METHOD] = { true, INSTR_FMT_IBC },
|
||||
|
|
2
Python/opcode_targets.h
generated
2
Python/opcode_targets.h
generated
|
@ -236,7 +236,7 @@ static void *opcode_targets[256] = {
|
|||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_INSTRUMENTED_LOAD_SUPER_ATTR,
|
||||
&&TARGET_INSTRUMENTED_POP_JUMP_IF_NONE,
|
||||
&&TARGET_INSTRUMENTED_POP_JUMP_IF_NOT_NONE,
|
||||
&&TARGET_INSTRUMENTED_RESUME,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue