@@ -151,6 +151,8 @@ typedef struct {
151151 uintptr_t instruction_starts [UOP_MAX_TRACE_LENGTH ];
152152} jit_state ;
153153
154+ static size_t _Py_jit_shim_size = 0 ;
155+
154156// Warning! AArch64 requires you to get your hands dirty. These are your gloves:
155157
156158// value[value_start : value_start + len]
@@ -676,6 +678,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz
676678 * We compile this once only as it effectively a normal
677679 * function, but we need to use the JIT because it needs
678680 * to understand the jit-specific calling convention.
681+ * Don't forget to call _PyJIT_Fini later!
679682 */
680683static _PyJitEntryFuncPtr
681684compile_shim (void )
@@ -717,6 +720,7 @@ compile_shim(void)
717720 jit_free (memory , total_size );
718721 return NULL ;
719722 }
723+ _Py_jit_shim_size = total_size ;
720724 return (_PyJitEntryFuncPtr )memory ;
721725}
722726
@@ -739,6 +743,7 @@ _Py_LazyJitShim(
739743 return _Py_jit_entry (executor , frame , stack_pointer , tstate );
740744}
741745
746+ // Free executor's memory allocated with _PyJIT_Compile
742747void
743748_PyJIT_Free (_PyExecutorObject * executor )
744749{
@@ -754,4 +759,22 @@ _PyJIT_Free(_PyExecutorObject *executor)
754759 }
755760}
756761
762+ // Free shim memory allocated with compile_shim
763+ void
764+ _PyJIT_Fini (void )
765+ {
766+ PyMutex_Lock (& lazy_jit_mutex );
767+ unsigned char * memory = (unsigned char * )_Py_jit_entry ;
768+ size_t size = _Py_jit_shim_size ;
769+ if (size ) {
770+ _Py_jit_entry = _Py_LazyJitShim ;
771+ _Py_jit_shim_size = 0 ;
772+ if (jit_free (memory , size )) {
773+ PyErr_FormatUnraisable ("Exception ignored while "
774+ "freeing JIT entry code" );
775+ }
776+ }
777+ PyMutex_Unlock (& lazy_jit_mutex );
778+ }
779+
757780#endif // _Py_JIT
0 commit comments