Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument
  • Loading branch information
corona10 committed Aug 27, 2023
commit 8820df8d90b1631838c00577e8484fcfb62d0f8f
3 changes: 3 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ extern void _PyLineTable_InitAddressRange(
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);

/** API for executors */
extern void _PyCode_Clear_Executors(PyCodeObject *code);

#define ENABLE_SPECIALIZATION 1

/* Specialization functions */
Expand Down
4 changes: 4 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,10 @@ clear_executors(PyCodeObject *co)
co->co_executors = NULL;
}

void _PyCode_Clear_Executors(PyCodeObject *code) {
Comment thread
corona10 marked this conversation as resolved.
Outdated
clear_executors(code);
Comment thread
gvanrossum marked this conversation as resolved.
}

static void
deopt_code(PyCodeObject *code, _Py_CODEUNIT *instructions)
{
Expand Down
15 changes: 15 additions & 0 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1549,6 +1550,20 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
return 0;
}
int code_len = (int)Py_SIZE(code);
if (code->co_executors != NULL && code->co_executors->size > 0 ) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Address by @markshannon's comment
: #108482 (comment)

for (int i = 0; i < code_len; i += _PyInstruction_GetLength(code, 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];
assert(exec->vm_data.opcode != ENTER_EXECUTOR);
instr->op.code = _PyOpcode_Deopt[exec->vm_data.opcode];
instr->op.arg = exec->vm_data.oparg;
}
}
_PyCode_Clear_Executors(code);
Comment thread
gvanrossum marked this conversation as resolved.
}
if (update_instrumentation_data(code, interp)) {
return -1;
}
Expand Down