Skip to content

Commit

Permalink
bpo-45753: Interpreter internal tweaks (GH-29575)
Browse files Browse the repository at this point in the history
* Split exit paths into exceptional and non-exceptional.

* Move exit tracing code to individual bytecodes.

* Wrap all trace entry and exit events in macros to make them clearer and easier to enhance.

* Move return sequence into RETURN_VALUE, YIELD_VALUE and YIELD_FROM. Distinguish between normal trace events and dtrace events.
  • Loading branch information
markshannon authored Dec 1, 2021
1 parent 0aa0bd0 commit 49444fb
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 150 deletions.
23 changes: 12 additions & 11 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,25 @@ _GetSpecializedCacheEntryForInstruction(const _Py_CODEUNIT *first_instr, int nex
#define QUICKENING_INITIAL_WARMUP_VALUE (-QUICKENING_WARMUP_DELAY)
#define QUICKENING_WARMUP_COLDEST 1

static inline void
PyCodeObject_IncrementWarmup(PyCodeObject * co)
{
co->co_warmup++;
}
int _Py_Quicken(PyCodeObject *code);

/* Used by the interpreter to determine when a code object should be quickened */
/* Returns 1 if quickening occurs.
* -1 if an error occurs
* 0 otherwise */
static inline int
PyCodeObject_IsWarmedUp(PyCodeObject * co)
_Py_IncrementCountAndMaybeQuicken(PyCodeObject *code)
{
return (co->co_warmup == 0);
if (code->co_warmup != 0) {
code->co_warmup++;
if (code->co_warmup == 0) {
return _Py_Quicken(code) ? -1 : 1;
}
}
return 0;
}

int _Py_Quicken(PyCodeObject *code);

extern Py_ssize_t _Py_QuickenedCount;


/* "Locals plus" for a code object is the set of locals + cell vars +
* free vars. This relates to variable names as well as offsets into
* the "fast locals" storage array of execution frames. The compiler
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ enum _framestate {

typedef signed char PyFrameState;

/*
frame->f_lasti refers to the index of the last instruction,
unless it's -1 in which case next_instr should be first_instr.
*/

typedef struct _interpreter_frame {
PyFunctionObject *f_func; /* Strong reference */
PyObject *f_globals; /* Borrowed reference */
Expand Down
Loading

0 comments on commit 49444fb

Please sign in to comment.