Skip to content

Commit 242ddf4

Browse files
committed
jit: lazy executor flush while the world stopped
1 parent dcac498 commit 242ddf4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Python/optimizer.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ _Py_ClearExecutorDeletionList(PyInterpreterState *interp)
293293
interp->executor_deletion_list_remaining_capacity = EXECUTOR_DELETE_LIST_MAX;
294294
}
295295

296+
static inline int
297+
can_clear_executor_deletion_list(PyInterpreterState *interp)
298+
{
299+
#ifdef Py_GIL_DISABLED
300+
if (_PyRuntime.stoptheworld.world_stopped || interp->stoptheworld.world_stopped) {
301+
return 0;
302+
}
303+
#endif
304+
return 1;
305+
}
306+
296307
static void
297308
add_to_pending_deletion_list(_PyExecutorObject *self)
298309
{
@@ -302,7 +313,7 @@ add_to_pending_deletion_list(_PyExecutorObject *self)
302313
if (interp->executor_deletion_list_remaining_capacity > 0) {
303314
interp->executor_deletion_list_remaining_capacity--;
304315
}
305-
else {
316+
else if (can_clear_executor_deletion_list(interp)) {
306317
_Py_ClearExecutorDeletionList(interp);
307318
}
308319
}

Python/pystate.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,18 @@ start_the_world(struct _stoptheworld_state *stw)
23582358
_PyRuntimeState *runtime = &_PyRuntime;
23592359
assert(PyMutex_IsLocked(&stw->mutex));
23602360

2361+
#ifdef _Py_TIER2
2362+
if (stw->is_global) {
2363+
_Py_FOR_EACH_STW_INTERP(stw, interp) {
2364+
_Py_ClearExecutorDeletionList(interp);
2365+
}
2366+
}
2367+
else {
2368+
PyInterpreterState *interp = _Py_CONTAINER_OF(stw, PyInterpreterState, stoptheworld);
2369+
_Py_ClearExecutorDeletionList(interp);
2370+
}
2371+
#endif
2372+
23612373
HEAD_LOCK(runtime);
23622374
stw->requested = 0;
23632375
stw->world_stopped = 0;

0 commit comments

Comments
 (0)