Skip to content

Commit d6cc8e8

Browse files
committed
Reduce the size of the debug stencils to less than half.
For AArch64 linux, reduces the total bytes in the code bodies from 489kb to 218kb. Reduces the size of the stencils files from 394k lines to 167k lines.
1 parent d8ff4f8 commit d6cc8e8

10 files changed

Lines changed: 1887 additions & 1860 deletions

File tree

Include/cpython/pystats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ typedef struct _optimization_stats {
163163
uint64_t jit_code_size;
164164
uint64_t jit_trampoline_size;
165165
uint64_t jit_data_size;
166+
uint64_t jit_got_size;
166167
uint64_t jit_padding_size;
167168
uint64_t jit_freed_memory_size;
168169
uint64_t trace_total_memory_hist[_Py_UOP_HIST_SIZE];

Include/internal/pycore_interpframe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ _PyFrame_GetLocalsArray(_PyInterpreterFrame *frame)
230230
static inline _PyStackRef*
231231
_PyFrame_GetStackPointer(_PyInterpreterFrame *frame)
232232
{
233+
#ifndef _Py_JIT
233234
assert(frame->stackpointer != NULL);
235+
#endif
234236
_PyStackRef *sp = frame->stackpointer;
235237
#ifndef NDEBUG
236238
frame->stackpointer = NULL;
@@ -241,7 +243,10 @@ _PyFrame_GetStackPointer(_PyInterpreterFrame *frame)
241243
static inline void
242244
_PyFrame_SetStackPointer(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
243245
{
246+
/* Avoid bloating the JIT code */
247+
#ifndef _Py_JIT
244248
assert(frame->stackpointer == NULL);
249+
#endif
245250
frame->stackpointer = stack_pointer;
246251
}
247252

Include/internal/pycore_jit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ _Py_CODEUNIT *_PyJIT_Entry(
3131
int _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction *trace, size_t length);
3232
void _PyJIT_Free(_PyExecutorObject *executor);
3333
PyAPI_FUNC(int) _PyJIT_AddressInJitCode(PyInterpreterState *interp, uintptr_t addr);
34+
PyAPI_FUNC(void) _Py_jit_assert_within_stack_bounds(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, int lineno);
35+
PyAPI_FUNC(int) _Py_jit_assertion_failure(int line);
3436

3537
#endif // _Py_JIT
3638

Include/internal/pycore_uop.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ typedef struct _PyUOpInstruction{
3838

3939
// Fitness is the target length of the trace we translate initially. The uop
4040
// buffer has a small amount of extra space for entry/loop-closing overhead.
41-
#if defined(Py_DEBUG) && defined(_Py_JIT)
42-
// With asserts, the stencils are a lot larger
43-
#define FITNESS_INITIAL 1000
44-
#else
4541
#define FITNESS_INITIAL 2500
46-
#endif
4742

4843
#define UOP_TRACE_BUFFER_OVERHEAD 10
4944
#define UOP_MAX_TRACE_LENGTH (FITNESS_INITIAL + UOP_TRACE_BUFFER_OVERHEAD)

Python/ceval.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,14 @@ _Py_assert_within_stack_bounds(
997997
abort();
998998
}
999999
}
1000+
#ifdef _Py_JIT
1001+
void
1002+
_Py_jit_assert_within_stack_bounds(
1003+
_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, int lineno
1004+
) {
1005+
_Py_assert_within_stack_bounds(frame, stack_pointer, "executor_cases.c.h", lineno);
1006+
}
1007+
#endif
10001008
#endif
10011009

10021010
int _Py_CheckRecursiveCallPy(

Python/ceval_macros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ GETITEM(PyObject *v, Py_ssize_t i) {
268268

269269
#if defined(Py_DEBUG) && !defined(_Py_JIT)
270270
// This allows temporary stack "overflows", provided it's all in the cache at any point of time.
271-
#define WITHIN_STACK_BOUNDS_IGNORING_CACHE() \
272-
(frame->owner == FRAME_OWNED_BY_INTERPRETER || (STACK_LEVEL() >= 0 && (STACK_LEVEL()) <= STACK_SIZE()))
271+
#define ASSERT_WITHIN_STACK_BOUNDS_IGNORING_CACHE(F, L) \
272+
assert(frame->owner == FRAME_OWNED_BY_INTERPRETER || (STACK_LEVEL() >= 0 && (STACK_LEVEL()) <= STACK_SIZE()))
273273
#else
274-
#define WITHIN_STACK_BOUNDS_IGNORING_CACHE WITHIN_STACK_BOUNDS
274+
#define ASSERT_WITHIN_STACK_BOUNDS_IGNORING_CACHE ASSERT_WITHIN_STACK_BOUNDS
275275
#endif
276276

277277
/* Data access macros */

0 commit comments

Comments
 (0)