summaryrefslogtreecommitdiffstats
path: root/Include/cpython
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-21 09:57:35 (GMT)
committerGitHub <noreply@github.com>2021-05-21 09:57:35 (GMT)
commitb11a951f16f0603d98de24fee5c023df83ea552c (patch)
tree82e7807515db0e284d9ebc3b8c3ba6ff08699ea5 /Include/cpython
parentbe4dd7fcd93ed29d362c4bbcc48151bc619d6595 (diff)
downloadcpython-b11a951f16f0603d98de24fee5c023df83ea552c.zip
cpython-b11a951f16f0603d98de24fee5c023df83ea552c.tar.gz
cpython-b11a951f16f0603d98de24fee5c023df83ea552c.tar.bz2
bpo-44032: Move data stack to thread from FrameObject. (GH-26076)
* Remove 'zombie' frames. We won't need them once we are allocating fixed-size frames. * Add co_nlocalplus field to code object to avoid recomputing size of locals + frees + cells. * Move locals, cells and freevars out of frame object into separate memory buffer. * Use per-threadstate allocated memory chunks for local variables. * Move globals and builtins from frame object to per-thread stack. * Move (slow) locals frame object to per-thread stack. * Move internal frame functions to internal header.
Diffstat (limited to 'Include/cpython')
-rw-r--r--Include/cpython/code.h2
-rw-r--r--Include/cpython/frameobject.h10
-rw-r--r--Include/cpython/pystate.h9
3 files changed, 14 insertions, 7 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index 330f1f5..575a4b7 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -40,8 +40,8 @@ struct PyCodeObject {
PyObject *co_name; /* unicode (name, for reference) */
PyObject *co_linetable; /* string (encoding addr<->lineno mapping) See
Objects/lnotab_notes.txt for details. */
+ int co_nlocalsplus; /* Number of locals + free + cell variables */
PyObject *co_exceptiontable; /* Byte string encoding exception handling table */
- void *co_zombieframe; /* for optimization only (see frameobject.c) */
PyObject *co_weakreflist; /* to support weakrefs to code objects */
/* Scratch space for extra data relating to the code object.
Type is a void* to keep the format private in codeobject.c to force
diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h
index 5816647..fc20bc2 100644
--- a/Include/cpython/frameobject.h
+++ b/Include/cpython/frameobject.h
@@ -20,12 +20,9 @@ enum _framestate {
typedef signed char PyFrameState;
struct _frame {
- PyObject_VAR_HEAD
+ PyObject_HEAD
struct _frame *f_back; /* previous frame, or NULL */
PyCodeObject *f_code; /* code segment */
- PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
- PyObject *f_globals; /* global symbol table (PyDictObject) */
- PyObject *f_locals; /* local symbol table (any mapping) */
PyObject **f_valuestack; /* points after the last local */
PyObject *f_trace; /* Trace function */
/* Borrowed reference to a generator, or NULL */
@@ -36,7 +33,8 @@ struct _frame {
PyFrameState f_state; /* What state the frame is in */
char f_trace_lines; /* Emit per-line trace events? */
char f_trace_opcodes; /* Emit per-opcode trace events? */
- PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
+ char f_own_locals_memory; /* This frame owns the memory for the locals */
+ PyObject **f_localsptr; /* Pointer to locals, cells, free */
};
static inline int _PyFrame_IsRunnable(struct _frame *f) {
@@ -62,7 +60,7 @@ PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
/* only internal use */
PyFrameObject*
-_PyFrame_New_NoTrack(PyThreadState *, PyFrameConstructor *, PyObject *);
+_PyFrame_New_NoTrack(PyThreadState *, PyFrameConstructor *, PyObject *, PyObject **);
/* The rest of the interface is specific for frame objects */
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index e3ccc54..63ba600 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -57,6 +57,12 @@ typedef struct _err_stackitem {
} _PyErr_StackItem;
+typedef struct _stack_chunk {
+ struct _stack_chunk *previous;
+ size_t size;
+ size_t top;
+ PyObject * data[1]; /* Variable sized */
+} _PyStackChunk;
// The PyThreadState typedef is in Include/pystate.h.
struct _ts {
@@ -149,6 +155,9 @@ struct _ts {
CFrame root_cframe;
+ _PyStackChunk *datastack_chunk;
+ PyObject **datastack_top;
+ PyObject **datastack_limit;
/* XXX signal handlers should also be here */
};