@@ -81,6 +81,7 @@ get_index_for_executor(PyCodeObject *code, _Py_CODEUNIT *instr)
8181 if (new == NULL ) {
8282 return -1 ;
8383 }
84+ new -> is_finalizing = 0 ;
8485 new -> capacity = new_capacity ;
8586 new -> size = size ;
8687 code -> co_executors = new ;
@@ -1698,7 +1699,7 @@ _PyJit_Tracer_InvalidateDependency(PyThreadState *tstate, void *obj)
16981699 * May cause other executors to be invalidated as well
16991700 */
17001701void
1701- _Py_Executors_InvalidateDependency (PyInterpreterState * interp , void * obj , int is_invalidation )
1702+ _Py_Executors_InvalidateDependencyWorldStopped (PyInterpreterState * interp , void * obj , int is_invalidation )
17021703{
17031704 _PyBloomFilter obj_filter ;
17041705 _Py_BloomFilter_Init (& obj_filter );
@@ -1711,7 +1712,6 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is
17111712 }
17121713 /* Clearing an executor can deallocate others, so we need to make a list of
17131714 * executors to invalidate first */
1714- _PyEval_StopTheWorldAll (& _PyRuntime );
17151715 _Py_FOR_EACH_TSTATE_UNLOCKED (interp , p ) {
17161716 _PyJit_Tracer_InvalidateDependency (p , obj );
17171717 for (_PyExecutorObject * exec = ((_PyThreadStateImpl * )p )-> jit_executor_state .executor_list_head ; exec != NULL ;) {
@@ -1728,7 +1728,6 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is
17281728 exec = next ;
17291729 }
17301730 }
1731- _PyEval_StartTheWorldAll (& _PyRuntime );
17321731 for (Py_ssize_t i = 0 ; i < PyList_GET_SIZE (invalidate ); i ++ ) {
17331732 PyObject * exec = PyList_GET_ITEM (invalidate , i );
17341733 executor_clear (exec );
@@ -1741,13 +1740,19 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is
17411740error :
17421741 PyErr_Clear ();
17431742 Py_XDECREF (invalidate );
1744- // If we're truly out of memory, wiping out everything is a fine fallback:
1745- _Py_Executors_InvalidateAll (interp , is_invalidation );
1743+ // If we're truly out of memory, DO NOT wipe everything as the world is stopped, and we might deadlock.
17461744}
17471745
1748- /* Invalidate all executors */
17491746void
1750- _Py_Executors_InvalidateAll (PyInterpreterState * interp , int is_invalidation )
1747+ _Py_Executors_InvalidateDependency (PyInterpreterState * interp , void * obj , int is_invalidation )
1748+ {
1749+ _PyEval_StopTheWorld (interp );
1750+ _Py_Executors_InvalidateDependencyWorldStopped (interp , obj , is_invalidation );
1751+ _PyEval_StartTheWorld (interp );
1752+ }
1753+
1754+ void
1755+ _Py_Executors_InvalidateAllWorldStopped (PyInterpreterState * interp , int is_invalidation )
17511756{
17521757 PyObject * invalidate = PyList_New (0 );
17531758 if (invalidate == NULL ) {
@@ -1756,7 +1761,6 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
17561761 }
17571762 /* Clearing an executor can deallocate others, so we need to make a list of
17581763 * executors to invalidate first */
1759- _PyEval_StopTheWorldAll (& _PyRuntime );
17601764 _Py_FOR_EACH_TSTATE_UNLOCKED (interp , p ) {
17611765 for (_PyExecutorObject * exec = ((_PyThreadStateImpl * )p )-> jit_executor_state .executor_list_head ; exec != NULL ;) {
17621766 assert (exec -> vm_data .valid );
@@ -1771,7 +1775,6 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
17711775 exec = next ;
17721776 }
17731777 }
1774- _PyEval_StartTheWorldAll (& _PyRuntime );
17751778 Py_ssize_t list_len = PyList_GET_SIZE (invalidate );
17761779 for (Py_ssize_t i = 0 ; i < list_len ; i ++ ) {
17771780 _PyExecutorObject * executor = (_PyExecutorObject * )PyList_GET_ITEM (invalidate , i );
@@ -1787,6 +1790,16 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
17871790 }
17881791 }
17891792 Py_DECREF (invalidate );
1793+ // If we're truly out of memory, DO NOT wipe everything as the world is stopped, and we might deadlock.
1794+ }
1795+
1796+ /* Invalidate all executors */
1797+ void
1798+ _Py_Executors_InvalidateAll (PyInterpreterState * interp , int is_invalidation )
1799+ {
1800+ _PyEval_StopTheWorld (interp );
1801+ _Py_Executors_InvalidateAllWorldStopped (interp , is_invalidation );
1802+ _PyEval_StartTheWorld (interp );
17901803}
17911804
17921805
0 commit comments