Skip to content
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

GH-96421: Insert shim frame on entry to interpreter #96319

Merged
merged 39 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4d5e9a5
Handle _PyEval_EvalFrameDefault exit in bytecode.
markshannon Aug 24, 2022
cf78d2b
Merge branch 'main' into entry-frame
markshannon Aug 25, 2022
7f5348a
Get entry frame shim working.
markshannon Aug 26, 2022
59e7727
Delay destruction of trampoline code object and make symbol private
markshannon Aug 30, 2022
9f710e6
Make sure that previous never points into the C stack after return.
markshannon Aug 30, 2022
4ee84ab
Use explicit stacksize in _Py_MakeTrampoline. Allow interpreter to cl…
markshannon Aug 30, 2022
f5161e3
Move assert before use.
markshannon Aug 31, 2022
06c2ad6
Use typedef name.
markshannon Aug 31, 2022
cb6134e
Merge branch 'main' into entry-frame
markshannon Sep 5, 2022
11b3b17
Merge branch 'main' into entry-frame
markshannon Sep 7, 2022
053f488
More on-stack C structs into a big struct and add sentinels, as we wa…
markshannon Sep 8, 2022
4dad69a
Skip a test if ASAN is turned on.
markshannon Sep 8, 2022
0db3b25
Remove extra semicolons.
markshannon Sep 9, 2022
05b4f68
Add news
markshannon Sep 9, 2022
6cca61c
Merge branch 'main' into entry-frame
markshannon Sep 9, 2022
5099861
Merge branch 'main' into entry-frame
markshannon Sep 13, 2022
4015c72
Halve the number of writes for shim frame.
markshannon Sep 14, 2022
fb19e94
Remove one more write to shim frame.
markshannon Sep 14, 2022
95ef81b
Fix lltrace
markshannon Sep 14, 2022
972425d
Merge branch 'main' into entry-frame
markshannon Oct 19, 2022
aa8bd73
Remove first_instr local variable.
markshannon Oct 19, 2022
f7072e1
Add news and update frame_layout.md
markshannon Oct 19, 2022
52406d2
Merge branch 'main' into entry-frame
markshannon Oct 19, 2022
bd2b0ee
Remove debugging scaffolding and give C compiler more freedom to layo…
markshannon Oct 20, 2022
10b03c8
Remove typo
markshannon Oct 20, 2022
b62f5f3
Address code review comments.
markshannon Oct 21, 2022
1a0b08f
Generate linetable when creating shim code.
markshannon Oct 21, 2022
76e437a
Bundle shim code definition into single struct.
markshannon Oct 21, 2022
945e26a
Remove incorrect assert.
markshannon Oct 21, 2022
676321a
assert generator is cleared after returning or raising.
markshannon Oct 21, 2022
3cb22e6
Rename pyframe to entry_frame.
markshannon Oct 21, 2022
e5dcbd9
Pass correct length.
markshannon Oct 21, 2022
bd29356
Address review comments
markshannon Nov 7, 2022
9446325
Merge branch 'main' into entry-frame
markshannon Nov 7, 2022
f6a6457
Post merge cleanup
markshannon Nov 8, 2022
d113655
Turn ASAN back on for subprocess test.
markshannon Nov 8, 2022
ed7af1e
Apply suggestions from code review
markshannon Nov 9, 2022
48410d9
Merge branch 'main' into entry-frame
markshannon Nov 9, 2022
7cda3ef
Merge branch 'main' into entry-frame
markshannon Nov 10, 2022
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
10 changes: 10 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ _PyCode_LineNumberFromArray(PyCodeObject *co, int index)
}
}

typedef struct _PyShimCodeDef {
const uint8_t *code;
int codelen;
int stacksize;
const char *cname;
} _PyShimCodeDef;

extern PyCodeObject *
_Py_MakeShimCode(const _PyShimCodeDef *code);


#ifdef __cplusplus
}
Expand Down
17 changes: 8 additions & 9 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ typedef enum _framestate {
enum _frameowner {
FRAME_OWNED_BY_THREAD = 0,
FRAME_OWNED_BY_GENERATOR = 1,
FRAME_OWNED_BY_FRAME_OBJECT = 2
FRAME_OWNED_BY_FRAME_OBJECT = 2,
FRAME_OWNED_BY_CSTACK = 3,
};

typedef struct _PyInterpreterFrame {
/* "Specials" section */
PyObject *f_funcobj; /* Strong reference */
PyObject *f_globals; /* Borrowed reference */
PyObject *f_builtins; /* Borrowed reference */
PyObject *f_locals; /* Strong reference, may be NULL */
PyObject *f_funcobj; /* Strong reference. Only valid if not on C stack */
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
PyCodeObject *f_code; /* Strong reference */
PyFrameObject *frame_obj; /* Strong reference, may be NULL */
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
/* Linkage section */
struct _PyInterpreterFrame *previous;
// NOTE: This is not necessarily the last instruction started in the given
// frame. Rather, it is the code unit *prior to* the *next* instruction. For
// example, it may be an inline CACHE entry, an instruction we just jumped
// over, or (in the case of a newly-created frame) a totally invalid value:
_Py_CODEUNIT *prev_instr;
int stacktop; /* Offset of TOS from localsplus */
int stacktop; /* Offset of TOS from localsplus */
uint16_t yield_offset;
bool is_entry; // Whether this is the "root" frame for the current _PyCFrame.
char owner;
/* Locals and stack */
PyObject *localsplus[1];
Expand Down Expand Up @@ -110,7 +110,6 @@ _PyFrame_InitializeSpecials(
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->prev_instr = _PyCode_CODE(code) - 1;
frame->is_entry = false;
frame->yield_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;
}
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct _Py_global_strings {
STRUCT_FOR_STR(newline, "\n")
STRUCT_FOR_STR(open_br, "{")
STRUCT_FOR_STR(percent, "%")
STRUCT_FOR_STR(shim_name, "<shim>")
STRUCT_FOR_STR(utf_8, "utf-8")
} literals;

Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct _is {
struct ast_state ast;
struct types_state types;
struct callable_cache callable_cache;
PyCodeObject *interpreter_trampoline;

/* The following fields are here to avoid allocation during init.
The data is exposed through PyInterpreterState pointer fields.
Expand Down
44 changes: 22 additions & 22 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading