Skip to content

Commit 49444fb

Browse files
authored
bpo-45753: Interpreter internal tweaks (GH-29575)
* 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.
1 parent 0aa0bd0 commit 49444fb

File tree

3 files changed

+211
-150
lines changed

3 files changed

+211
-150
lines changed

Include/internal/pycore_code.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,25 @@ _GetSpecializedCacheEntryForInstruction(const _Py_CODEUNIT *first_instr, int nex
137137
#define QUICKENING_INITIAL_WARMUP_VALUE (-QUICKENING_WARMUP_DELAY)
138138
#define QUICKENING_WARMUP_COLDEST 1
139139

140-
static inline void
141-
PyCodeObject_IncrementWarmup(PyCodeObject * co)
142-
{
143-
co->co_warmup++;
144-
}
140+
int _Py_Quicken(PyCodeObject *code);
145141

146-
/* Used by the interpreter to determine when a code object should be quickened */
142+
/* Returns 1 if quickening occurs.
143+
* -1 if an error occurs
144+
* 0 otherwise */
147145
static inline int
148-
PyCodeObject_IsWarmedUp(PyCodeObject * co)
146+
_Py_IncrementCountAndMaybeQuicken(PyCodeObject *code)
149147
{
150-
return (co->co_warmup == 0);
148+
if (code->co_warmup != 0) {
149+
code->co_warmup++;
150+
if (code->co_warmup == 0) {
151+
return _Py_Quicken(code) ? -1 : 1;
152+
}
153+
}
154+
return 0;
151155
}
152156

153-
int _Py_Quicken(PyCodeObject *code);
154-
155157
extern Py_ssize_t _Py_QuickenedCount;
156158

157-
158159
/* "Locals plus" for a code object is the set of locals + cell vars +
159160
* free vars. This relates to variable names as well as offsets into
160161
* the "fast locals" storage array of execution frames. The compiler

Include/internal/pycore_frame.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ enum _framestate {
1919

2020
typedef signed char PyFrameState;
2121

22+
/*
23+
frame->f_lasti refers to the index of the last instruction,
24+
unless it's -1 in which case next_instr should be first_instr.
25+
*/
26+
2227
typedef struct _interpreter_frame {
2328
PyFunctionObject *f_func; /* Strong reference */
2429
PyObject *f_globals; /* Borrowed reference */

0 commit comments

Comments
 (0)