Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve memory layout of JIT traces. Patch by Diego Russo
10 changes: 5 additions & 5 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,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;
Expand All @@ -516,8 +516,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).
Expand All @@ -539,7 +539,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
Expand Down
Loading