Skip to content

Commit a29a9c0

Browse files
authored
GH-129231: Group executable JIT code in memory (GH-129232)
1 parent 5673945 commit a29a9c0

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve memory layout of JIT traces. Patch by Diego Russo

Python/jit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
502502
// Round up to the nearest page:
503503
size_t page_size = get_page_size();
504504
assert((page_size & (page_size - 1)) == 0);
505-
size_t padding = page_size - ((code_size + data_size + state.trampolines.size) & (page_size - 1));
506-
size_t total_size = code_size + data_size + state.trampolines.size + padding;
505+
size_t padding = page_size - ((code_size + state.trampolines.size + data_size) & (page_size - 1));
506+
size_t total_size = code_size + state.trampolines.size + data_size + padding;
507507
unsigned char *memory = jit_alloc(total_size);
508508
if (memory == NULL) {
509509
return -1;
@@ -524,8 +524,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
524524
}
525525
// Loop again to emit the code:
526526
unsigned char *code = memory;
527-
unsigned char *data = memory + code_size;
528-
state.trampolines.mem = memory + code_size + data_size;
527+
state.trampolines.mem = memory + code_size;
528+
unsigned char *data = memory + code_size + state.trampolines.size;
529529
// Compile the shim, which handles converting between the native
530530
// calling convention and the calling convention used by jitted code
531531
// (which may be different for efficiency reasons).
@@ -547,7 +547,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
547547
code += group->code_size;
548548
data += group->data_size;
549549
assert(code == memory + code_size);
550-
assert(data == memory + code_size + data_size);
550+
assert(data == memory + code_size + state.trampolines.size + data_size);
551551
#ifdef MAP_JIT
552552
pthread_jit_write_protect_np(1);
553553
#endif

0 commit comments

Comments
 (0)