Skip to content

Commit 643f454

Browse files
committed
Merge branch 'main' into isearch-paste
2 parents fa96a8e + efcac6f commit 643f454

47 files changed

Lines changed: 2233 additions & 850 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/c-api/perfmaps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Note that holding an :term:`attached thread state` is not required for these API
3131
or ``-2`` on failure to create a lock. Check ``errno`` for more information
3232
about the cause of a failure.
3333

34-
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, unsigned int code_size, const char *entry_name)
34+
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, size_t code_size, const char *entry_name)
3535
3636
Write one single entry to the ``/tmp/perf-$pid.map`` file. This function is
3737
thread safe. Here is what an example entry looks like::

Include/cpython/ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838
PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void);
3939
PyAPI_FUNC(int) PyUnstable_WritePerfMapEntry(
4040
const void *code_addr,
41-
unsigned int code_size,
41+
size_t code_size,
4242
const char *entry_name);
4343
PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void);
4444
PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename);

Include/internal/pycore_ceval.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct {
9494
void* (*init_state)(void);
9595
// Callback to register every trampoline being created
9696
void (*write_state)(void* state, const void *code_addr,
97-
unsigned int code_size, PyCodeObject* code);
97+
size_t code_size, PyCodeObject* code);
9898
// Callback to free the trampoline state
9999
int (*free_state)(void* state);
100100
} _PyPerf_Callbacks;
@@ -108,6 +108,10 @@ extern PyStatus _PyPerfTrampoline_AfterFork_Child(void);
108108
#ifdef PY_HAVE_PERF_TRAMPOLINE
109109
extern _PyPerf_Callbacks _Py_perfmap_callbacks;
110110
extern _PyPerf_Callbacks _Py_perfmap_jit_callbacks;
111+
extern void _PyPerfJit_WriteNamedCode(const void *code_addr,
112+
size_t code_size,
113+
const char *entry,
114+
const char *filename);
111115
#endif
112116

113117
static inline PyObject*

Include/internal/pycore_debug_offsets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ typedef struct _Py_DebugOffsets {
215215
uint64_t state;
216216
uint64_t length;
217217
uint64_t asciiobject_size;
218+
uint64_t compactunicodeobject_size;
218219
} unicode_object;
219220

220221
// GC runtime state offset;
@@ -370,6 +371,7 @@ typedef struct _Py_DebugOffsets {
370371
.state = offsetof(PyUnicodeObject, _base._base.state), \
371372
.length = offsetof(PyUnicodeObject, _base._base.length), \
372373
.asciiobject_size = sizeof(PyASCIIObject), \
374+
.compactunicodeobject_size = sizeof(PyCompactUnicodeObject), \
373375
}, \
374376
.gc = { \
375377
.size = sizeof(struct _gc_runtime_state), \

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct code_arena_st;
6969
struct trampoline_api_st {
7070
void* (*init_state)(void);
7171
void (*write_state)(void* state, const void *code_addr,
72-
unsigned int code_size, PyCodeObject* code);
72+
size_t code_size, PyCodeObject* code);
7373
int (*free_state)(void* state);
7474
void *state;
7575
Py_ssize_t code_padding;

Include/internal/pycore_jit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef _Py_CODEUNIT *(*jit_func)(
2323
_PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
2424
);
2525

26-
_Py_CODEUNIT *_PyJIT(
26+
_Py_CODEUNIT *_PyJIT_Entry(
2727
_PyExecutorObject *executor, _PyInterpreterFrame *frame,
2828
_PyStackRef *stack_pointer, PyThreadState *tstate
2929
);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef Py_INTERNAL_JIT_UNWIND_H
2+
#define Py_INTERNAL_JIT_UNWIND_H
3+
4+
#ifndef Py_BUILD_CORE
5+
# error "this header requires Py_BUILD_CORE define"
6+
#endif
7+
8+
#include <stddef.h>
9+
#include <stdint.h>
10+
11+
#if defined(_Py_JIT) && defined(__linux__) && defined(__ELF__)
12+
# define PY_HAVE_JIT_GDB_UNWIND
13+
#endif
14+
15+
#if defined(PY_HAVE_PERF_TRAMPOLINE) || defined(PY_HAVE_JIT_GDB_UNWIND)
16+
17+
#if defined(PY_HAVE_JIT_GDB_UNWIND)
18+
extern PyMutex _Py_jit_debug_mutex;
19+
#endif
20+
21+
/* DWARF exception-handling pointer encodings shared by JIT unwind users. */
22+
enum {
23+
DWRF_EH_PE_absptr = 0x00,
24+
DWRF_EH_PE_omit = 0xff,
25+
26+
/* Data type encodings */
27+
DWRF_EH_PE_uleb128 = 0x01,
28+
DWRF_EH_PE_udata2 = 0x02,
29+
DWRF_EH_PE_udata4 = 0x03,
30+
DWRF_EH_PE_udata8 = 0x04,
31+
DWRF_EH_PE_sleb128 = 0x09,
32+
DWRF_EH_PE_sdata2 = 0x0a,
33+
DWRF_EH_PE_sdata4 = 0x0b,
34+
DWRF_EH_PE_sdata8 = 0x0c,
35+
DWRF_EH_PE_signed = 0x08,
36+
37+
/* Reference type encodings */
38+
DWRF_EH_PE_pcrel = 0x10,
39+
DWRF_EH_PE_textrel = 0x20,
40+
DWRF_EH_PE_datarel = 0x30,
41+
DWRF_EH_PE_funcrel = 0x40,
42+
DWRF_EH_PE_aligned = 0x50,
43+
DWRF_EH_PE_indirect = 0x80
44+
};
45+
46+
/* Return the size of the generated .eh_frame data for the given encoding. */
47+
size_t _PyJitUnwind_EhFrameSize(int absolute_addr);
48+
49+
/*
50+
* Build DWARF .eh_frame data for JIT code; returns size written or 0 on error.
51+
* absolute_addr selects the FDE address encoding:
52+
* - 0: PC-relative offsets (perf jitdump synthesized DSO).
53+
* - nonzero: absolute addresses (GDB JIT in-memory ELF).
54+
*/
55+
size_t _PyJitUnwind_BuildEhFrame(uint8_t *buffer, size_t buffer_size,
56+
const void *code_addr, size_t code_size,
57+
int absolute_addr);
58+
59+
void *_PyJitUnwind_GdbRegisterCode(const void *code_addr,
60+
size_t code_size,
61+
const char *entry,
62+
const char *filename);
63+
64+
void _PyJitUnwind_GdbUnregisterCode(void *handle);
65+
66+
#endif // defined(PY_HAVE_PERF_TRAMPOLINE) || defined(PY_HAVE_JIT_GDB_UNWIND)
67+
68+
#endif // Py_INTERNAL_JIT_UNWIND_H

Include/internal/pycore_optimizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ typedef struct _PyExecutorObject {
198198
uint32_t code_size;
199199
size_t jit_size;
200200
void *jit_code;
201+
void *jit_gdb_handle;
201202
_PyExitData exits[1];
202203
} _PyExecutorObject;
203204

Lib/pickle.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,17 +920,11 @@ def save_picklebuffer(self, obj):
920920
# Write data in-band
921921
# XXX The C implementation avoids a copy here
922922
buf = m.tobytes()
923-
in_memo = id(buf) in self.memo
924923
if m.readonly:
925-
if in_memo:
926-
self._save_bytes_no_memo(buf)
927-
else:
928-
self.save_bytes(buf)
924+
self._save_bytes_no_memo(buf)
929925
else:
930-
if in_memo:
931-
self._save_bytearray_no_memo(buf)
932-
else:
933-
self.save_bytearray(buf)
926+
self._save_bytearray_no_memo(buf)
927+
self.memoize(obj)
934928
else:
935929
# Write data out-of-band
936930
self.write(NEXT_BUFFER)

Lib/profiling/sampling/sample.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def __init__(self, pid, sample_interval_usec, all_threads, *, mode=PROFILING_MOD
5858
try:
5959
self.unwinder = self._new_unwinder(native, gc, opcodes, skip_non_matching_threads)
6060
except RuntimeError as err:
61+
if os.name == "nt" and sys.executable.endswith("python.exe"):
62+
raise SystemExit(
63+
"Running profiling.sampling from virtualenv on Windows platform is not supported"
64+
) from err
6165
raise SystemExit(err) from err
6266
# Track sample intervals and total sample count
6367
self.sample_intervals = deque(maxlen=100)

0 commit comments

Comments
 (0)