-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument #108539
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
23e1f48
Revert "gh-107265: Fix initialize/remove_tools for ENTER_EXECUTOR cas…
corona10 8820df8
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument
corona10 e015f14
nit
corona10 7612b8e
Add assert
corona10 7d38c77
nit
corona10 a01354d
Address code review
corona10 9a631d7
nit
corona10 7e81bf0
Add test
corona10 162a870
Merge remote-tracking branch 'upstream/main' into gh-107265-mark
corona10 05773f9
Add test
corona10 9ddbfe7
Add space between +=
corona10 1199dfe
Return -1 if there is ENTER_EXECUTOR
corona10 1232432
Update
corona10 e051be1
Merge remote-tracking branch 'upstream/main' into gh-107265-mark
corona10 4a0be4d
fix
corona10 bc251b5
Fix
corona10 83d8829
Address Guido's review
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "opcode_ids.h" | ||
|
||
#include "pycore_call.h" | ||
#include "pycore_code.h" // _PyCode_Clear_Executors() | ||
#include "pycore_frame.h" | ||
#include "pycore_interp.h" | ||
#include "pycore_long.h" | ||
|
@@ -566,13 +567,7 @@ 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; | ||
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; | ||
assert(opcode != ENTER_EXECUTOR); | ||
} | ||
assert(opcode != ENTER_EXECUTOR); | ||
if (opcode == INSTRUMENTED_LINE) { | ||
opcode_ptr = &code->_co_monitoring->lines[i].original_opcode; | ||
opcode = *opcode_ptr; | ||
|
@@ -717,22 +712,7 @@ 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)); | ||
#ifndef NDEBUG | ||
_Py_CODEUNIT co_instr = _PyCode_CODE(code)[offset]; | ||
uint8_t opcode = co_instr.op.code; | ||
uint8_t oparg = co_instr.op.arg; | ||
if (opcode == ENTER_EXECUTOR) { | ||
_PyExecutorObject *exec = code->co_executors->executors[oparg]; | ||
assert(exec->vm_data.opcode != ENTER_EXECUTOR); | ||
opcode = _PyOpcode_Deopt[exec->vm_data.opcode]; | ||
opcode = exec->vm_data.oparg; | ||
} | ||
else { | ||
opcode = _Py_GetBaseOpcode(code, offset); | ||
} | ||
assert(opcode != ENTER_EXECUTOR); | ||
assert(opcode_has_event(opcode)); | ||
#endif | ||
assert(opcode_has_event(_Py_GetBaseOpcode(code, offset))); | ||
_PyCoMonitoringData *monitoring = code->_co_monitoring; | ||
if (monitoring && monitoring->tools) { | ||
monitoring->tools[offset] &= ~tools; | ||
|
@@ -1303,27 +1283,21 @@ initialize_tools(PyCodeObject *code) | |
for (int i = 0; i < code_len; i++) { | ||
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i]; | ||
int opcode = instr->op.code; | ||
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) { | ||
if (opcode == INSTRUMENTED_LINE) { | ||
opcode = code->_co_monitoring->lines[i].original_opcode; | ||
} | ||
assert(opcode != ENTER_EXECUTOR); | ||
bool instrumented = is_instrumented(opcode); | ||
if (instrumented) { | ||
opcode = DE_INSTRUMENT[opcode]; | ||
assert(opcode != 0); | ||
} | ||
assert(opcode != ENTER_EXECUTOR); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was added to test #107265 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the test could reproduce what you did in that comment? |
||
opcode = _PyOpcode_Deopt[opcode]; | ||
if (opcode_has_event(opcode)) { | ||
if (instrumented) { | ||
int8_t event; | ||
if (opcode == RESUME) { | ||
event = oparg != 0; | ||
event = instr->op.arg != 0; | ||
} | ||
else { | ||
event = EVENT_FOR_OPCODE[opcode]; | ||
|
@@ -1576,7 +1550,9 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp) | |
); | ||
return 0; | ||
} | ||
int code_len = (int)Py_SIZE(code); | ||
if (code->co_executors != NULL) { | ||
_PyCode_Clear_Executors(code); | ||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (update_instrumentation_data(code, interp)) { | ||
return -1; | ||
} | ||
|
@@ -1605,6 +1581,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp) | |
return 0; | ||
} | ||
/* Insert instrumentation */ | ||
int code_len = (int)Py_SIZE(code); | ||
for (int i = code->_co_firsttraceable; i < code_len; i+= _PyInstruction_GetLength(code, i)) { | ||
_Py_CODEUNIT *instr = &_PyCode_CODE(code)[i]; | ||
CHECK(instr->op.code != 0); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.