Skip to content

Commit 657ce11

Browse files
committed
gh-129231: group executable JIT code in memory
1 parent ec91e1c commit 657ce11

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Python/jit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
501501
// Round up to the nearest page:
502502
size_t page_size = get_page_size();
503503
assert((page_size & (page_size - 1)) == 0);
504-
size_t padding = page_size - ((code_size + data_size + state.trampolines.size) & (page_size - 1));
505-
size_t total_size = code_size + data_size + state.trampolines.size + padding;
504+
size_t padding = page_size - ((code_size + state.trampolines.size + data_size) & (page_size - 1));
505+
size_t total_size = code_size + state.trampolines.size + data_size + padding;
506506
unsigned char *memory = jit_alloc(total_size);
507507
if (memory == NULL) {
508508
return -1;
@@ -516,8 +516,8 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
516516
}
517517
// Loop again to emit the code:
518518
unsigned char *code = memory;
519-
unsigned char *data = memory + code_size;
520-
state.trampolines.mem = memory + code_size + data_size;
519+
state.trampolines.mem = memory + code_size;
520+
unsigned char *data = memory + code_size + state.trampolines.size;
521521
// Compile the shim, which handles converting between the native
522522
// calling convention and the calling convention used by jitted code
523523
// (which may be different for efficiency reasons).
@@ -539,7 +539,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
539539
code += group->code_size;
540540
data += group->data_size;
541541
assert(code == memory + code_size);
542-
assert(data == memory + code_size + data_size);
542+
assert(data == memory + code_size + state.trampolines.size + data_size);
543543
#ifdef MAP_JIT
544544
pthread_jit_write_protect_np(1);
545545
#endif

Tools/jit/_stencils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _get_trampoline_mask(self) -> str:
364364

365365
def as_c(self, opname: str) -> str:
366366
"""Dump this hole as a StencilGroup initializer."""
367-
return f"{{emit_{opname}, {len(self.code.body)}, {len(self.data.body)}, {self._get_trampoline_mask()}}}"
367+
return f"{{emit_{opname}, {len(self.code.body)}, {self._get_trampoline_mask()}, {len(self.data.body)}}}"
368368

369369

370370
def symbol_to_value(symbol: str) -> tuple[HoleValue, str | None]:

Tools/jit/_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def _dump_footer(
1818
yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor,"
1919
yield " const _PyUOpInstruction *instruction, jit_state *state);"
2020
yield " size_t code_size;"
21-
yield " size_t data_size;"
2221
yield " symbol_mask trampoline_mask;"
22+
yield " size_t data_size;"
2323
yield "} StencilGroup;"
2424
yield ""
2525
yield f"static const StencilGroup shim = {groups['shim'].as_c('shim')};"

0 commit comments

Comments
 (0)