@@ -494,10 +494,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
494494 size_t code_size = 0 ;
495495 size_t data_size = 0 ;
496496 jit_state state = {0 };
497- group = & shim ;
498- code_size += group -> code_size ;
499- data_size += group -> data_size ;
500- combine_symbol_mask (group -> trampoline_mask , state .trampolines .mask );
501497 for (size_t i = 0 ; i < length ; i ++ ) {
502498 const _PyUOpInstruction * instruction = & trace [i ];
503499 group = & stencil_groups [instruction -> opcode ];
@@ -539,13 +535,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
539535 unsigned char * code = memory ;
540536 state .trampolines .mem = memory + code_size ;
541537 unsigned char * data = memory + code_size + state .trampolines .size + code_padding ;
542- // Compile the shim, which handles converting between the native
543- // calling convention and the calling convention used by jitted code
544- // (which may be different for efficiency reasons).
545- group = & shim ;
546- group -> emit (code , data , executor , NULL , & state );
547- code += group -> code_size ;
548- data += group -> data_size ;
549538 assert (trace [0 ].opcode == _START_EXECUTOR || trace [0 ].opcode == _COLD_EXIT );
550539 for (size_t i = 0 ; i < length ; i ++ ) {
551540 const _PyUOpInstruction * instruction = & trace [i ];
@@ -566,7 +555,6 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
566555 return -1 ;
567556 }
568557 executor -> jit_code = memory ;
569- executor -> jit_side_entry = memory + shim .code_size ;
570558 executor -> jit_size = total_size ;
571559 return 0 ;
572560}
@@ -615,19 +603,23 @@ compile_trampoline(void)
615603 return (_PyJitEntryFuncPtr )memory ;
616604}
617605
606+ static PyMutex lazy_jit_mutex = { 0 };
618607
619608_Py_CODEUNIT *
620609_Py_LazyJitTrampoline (
621610 _PyExecutorObject * executor , _PyInterpreterFrame * frame , _PyStackRef * stack_pointer , PyThreadState * tstate
622611) {
623- assert (_Py_jit_entry == _Py_LazyJitTrampoline );
624- PyInterpreterState * interp = PyInterpreterState_Get ();
625- _PyJitEntryFuncPtr trampoline = compile_trampoline ();
626- if (trampoline == NULL ) {
627- Py_FatalError ("Cannot allocate core JIT code" );
612+ PyMutex_Lock (& lazy_jit_mutex );
613+ if (_Py_jit_entry == _Py_LazyJitTrampoline ) {
614+ _PyJitEntryFuncPtr trampoline = compile_trampoline ();
615+ if (trampoline == NULL ) {
616+ PyMutex_Unlock (& lazy_jit_mutex );
617+ Py_FatalError ("Cannot allocate core JIT code" );
618+ }
619+ _Py_jit_entry = trampoline ;
628620 }
629- _Py_jit_entry = trampoline ;
630- return trampoline (executor , frame , stack_pointer , tstate );
621+ PyMutex_Unlock ( & lazy_jit_mutex ) ;
622+ return _Py_jit_entry (executor , frame , stack_pointer , tstate );
631623}
632624
633625void
@@ -637,7 +629,6 @@ _PyJIT_Free(_PyExecutorObject *executor)
637629 size_t size = executor -> jit_size ;
638630 if (memory ) {
639631 executor -> jit_code = NULL ;
640- executor -> jit_side_entry = NULL ;
641632 executor -> jit_size = 0 ;
642633 if (jit_free (memory , size )) {
643634 PyErr_FormatUnraisable ("Exception ignored while "
0 commit comments