Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-107265: Fix initialize/remove_tools for ENTER_EXECUTOR case#108482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
corona10 merged 6 commits intopython:mainfromcorona10:gh-107265-initialize_tools
Aug 27, 2023
Merged
Changes from3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletionsPython/instrumentation.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -566,7 +566,12 @@ de_instrument(PyCodeObject *code, int i, int event)
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
uint8_t *opcode_ptr = &instr->op.code;
int opcode = *opcode_ptr;
assert(opcode != ENTER_EXECUTOR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This assertion is correct. Please don't remove assertions, unless you are really sure that they are incorrect.

ENTER_EXECUTOR should never have associated instrumentation.

Copy link
MemberAuthor

@corona10corona10Aug 27, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It was moved to L574, it will be the same effect no?

if (opcode == ENTER_EXECUTOR) {
int oparg = instr->op.arg;
_PyExecutorObject *exec = code->co_executors->executors[oparg];
opcode_ptr = &exec->vm_data.opcode;
opcode = *opcode_ptr;
}
if (opcode == INSTRUMENTED_LINE) {
opcode_ptr = &code->_co_monitoring->lines[i].original_opcode;
opcode = *opcode_ptr;
Expand All@@ -575,6 +580,7 @@ de_instrument(PyCodeObject *code, int i, int event)
opcode_ptr = &code->_co_monitoring->per_instruction_opcodes[i];
opcode = *opcode_ptr;
}
assert(opcode != ENTER_EXECUTOR);
int deinstrumented = DE_INSTRUMENT[opcode];
if (deinstrumented == 0) {
return;
Expand DownExpand Up@@ -711,7 +717,21 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
assert(event != PY_MONITORING_EVENT_LINE);
assert(event != PY_MONITORING_EVENT_INSTRUCTION);
assert(PY_MONITORING_IS_INSTRUMENTED_EVENT(event));
assert(opcode_has_event(_Py_GetBaseOpcode(code, offset)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is also correct, provided the assertionassert(PY_MONITORING_IS_INSTRUMENTED_EVENT(event)) is true.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hmm, it will guarantee that the opcode is not ENTER_EXECUTOR?

_Py_CODEUNIT co_instr = _PyCode_CODE(code)[offset];
uint8_t co_code = co_instr.op.code;
uint8_t co_arg = co_instr.op.arg;
if (co_code == ENTER_EXECUTOR) {
_PyExecutorObject *exec = code->co_executors->executors[co_arg];
assert(exec != NULL);
assert(exec->vm_data.opcode != ENTER_EXECUTOR);
co_code = _PyOpcode_Deopt[exec->vm_data.opcode];
co_arg = exec->vm_data.oparg;
}
else {
co_code = _Py_GetBaseOpcode(code, offset);
}
assert(co_code != ENTER_EXECUTOR);
assert(opcode_has_event(co_code));
_PyCoMonitoringData *monitoring = code->_co_monitoring;
if (monitoring && monitoring->tools) {
monitoring->tools[offset] &= ~tools;
Expand DownExpand Up@@ -1282,9 +1302,16 @@ initialize_tools(PyCodeObject *code)
for (int i = 0; i < code_len; i++) {
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i];
int opcode = instr->op.code;
if (opcode == INSTRUMENTED_LINE) {
int oparg = instr->op.arg;
if (opcode == ENTER_EXECUTOR) {
_PyExecutorObject *exec = code->co_executors->executors[oparg];
opcode = exec->vm_data.opcode;
oparg = exec->vm_data.oparg;
}
else if (opcode == INSTRUMENTED_LINE) {
opcode = code->_co_monitoring->lines[i].original_opcode;
}
assert(opcode != ENTER_EXECUTOR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This assert should be moved before the originalif (opcode == INSTRUMENTED_LINE) {, we shouldn't get here with andENTER_EXECUTOR present.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Move it to L1310 will be enough?

bool instrumented = is_instrumented(opcode);
if (instrumented) {
opcode = DE_INSTRUMENT[opcode];
Expand All@@ -1295,7 +1322,7 @@ initialize_tools(PyCodeObject *code)
if (instrumented) {
int8_t event;
if (opcode == RESUME) {
event =instr->op.arg != 0;
event =oparg != 0;
}
else {
event = EVENT_FOR_OPCODE[opcode];
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp