https://github.com/python/cpython/commit/a29a9c0f3890fec843b7151f6a1defa25f570504
commit: a29a9c0f3890fec843b7151f6a1defa25f570504
branch: main
author: Diego Russo <[email protected]>
committer: brandtbucher <[email protected]>
date: 2025-02-02T15:19:55-08:00
summary:
GH-129231: Group executable JIT code in memory (GH-129232)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2025-01-24-11-37-22.gh-issue-129231.ZsAP9v.rst
M Python/jit.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2025-01-24-11-37-22.gh-issue-129231.ZsAP9v.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-24-11-37-22.gh-issue-129231.ZsAP9v.rst
new file mode 100644
index 00000000000000..b30492a1947058
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-24-11-37-22.gh-issue-129231.ZsAP9v.rst
@@ -0,0 +1 @@
+Improve memory layout of JIT traces. Patch by Diego Russo
diff --git a/Python/jit.c b/Python/jit.c
index e6a337a5899b05..092b873bc734e1 100644
--- a/Python/jit.c
+++ b/Python/jit.c
@@ -502,8 +502,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const
_PyUOpInstruction trace[], siz
// Round up to the nearest page:
size_t page_size = get_page_size();
assert((page_size & (page_size - 1)) == 0);
- size_t padding = page_size - ((code_size + data_size +
state.trampolines.size) & (page_size - 1));
- size_t total_size = code_size + data_size + state.trampolines.size +
padding;
+ size_t padding = page_size - ((code_size + state.trampolines.size +
data_size) & (page_size - 1));
+ size_t total_size = code_size + state.trampolines.size + data_size +
padding;
unsigned char *memory = jit_alloc(total_size);
if (memory == NULL) {
return -1;
@@ -524,8 +524,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const
_PyUOpInstruction trace[], siz
}
// Loop again to emit the code:
unsigned char *code = memory;
- unsigned char *data = memory + code_size;
- state.trampolines.mem = memory + code_size + data_size;
+ state.trampolines.mem = memory + code_size;
+ unsigned char *data = memory + code_size + state.trampolines.size;
// Compile the shim, which handles converting between the native
// calling convention and the calling convention used by jitted code
// (which may be different for efficiency reasons).
@@ -547,7 +547,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const
_PyUOpInstruction trace[], siz
code += group->code_size;
data += group->data_size;
assert(code == memory + code_size);
- assert(data == memory + code_size + data_size);
+ assert(data == memory + code_size + state.trampolines.size + data_size);
#ifdef MAP_JIT
pthread_jit_write_protect_np(1);
#endif
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]