Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c341d2
vm: add per-interpreter runtime state and interpreter registry
youknowone Aug 13, 2026
43f4b23
gc: stop every interpreter while collecting
youknowone Aug 13, 2026
ffd3d1e
vm: scope the interpreter registry per thread without threading
youknowone Aug 13, 2026
0079994
vm: keep the interpreter registry usable across bootstrap, drop and fork
youknowone Aug 13, 2026
8f108ff
vm: attach and detach thread slots when switching interpreters
youknowone Aug 13, 2026
696a8c1
vm: list only the current interpreter's subclasses
youknowone Aug 14, 2026
562b657
gc: give each interpreter its own collector state
youknowone Aug 14, 2026
30e2020
_queue, _thread: detach before taking locks held across waits
youknowone Aug 14, 2026
5ce062e
_io, _winapi: detach on the remaining stopped-holdable lock takes
youknowone Aug 14, 2026
87b6c68
gc: size the interpreter owner tag to the header padding
youknowone Aug 15, 2026
fd27902
vm: reuse cleared frame blocks and shorten interpreter hot paths
youknowone Aug 15, 2026
c3fcc70
gc, vm: address review notes on owner tags and interpreter docs
youknowone Aug 15, 2026
57428cd
vm: gate interpreter registration on stop-the-world admission
youknowone Aug 15, 2026
8d07831
gc: keep the tracking counters off the barrier path
youknowone Aug 15, 2026
4e518d3
dict: settle lookups and iteration steps under one read guard
youknowone Aug 15, 2026
eb94daf
vm: build a call's argument vector once
youknowone Aug 15, 2026
f70db35
vm: reach an instance dict without cloning it
youknowone Aug 15, 2026
4a76424
vm: shorten the per-instruction safepoint and the call preamble
youknowone Aug 15, 2026
b0f0dcc
vm: give KwArgs a zero-sized hasher
youknowone Aug 15, 2026
f9bbc6d
vm: promote borrowed stack refs before a yield
youknowone Aug 15, 2026
b4bb43c
vm: run the exact-args vectorcall on a heap frame again
youknowone Aug 15, 2026
98d2410
vm: release a tail call's function at the callee's return
youknowone Aug 16, 2026
08bd522
vm: stop copying a running frame's locals when it materializes
youknowone Aug 16, 2026
c7c1452
vm: key data stack frame reuse on the exact frame size
youknowone Aug 16, 2026
2d58fc8
vm: store the frame object payload address in the cross-thread slot
youknowone Aug 16, 2026
e24d831
vm: copy a foreign thread's frames instead of linking them
youknowone Aug 16, 2026
5d0d9be
vm: resolve the two rustdoc links this branch added
youknowone Aug 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
_io, _winapi: detach on the remaining stopped-holdable lock takes
`TextIOWrapper.__repr__` took `data` directly while every other method takes it
through `lock_opt`, which detaches. `Overlapped` holds `inner` across the
`allow_threads` in `GetOverlappedResult`, and all four of its takes were direct.

A thread stopped by stop-the-world can be holding either mutex, so taking one
while attached left the blocked thread with no safepoint to reach.

Assisted-by: Claude
  • Loading branch information
youknowone committed Aug 15, 2026
commit 5ce062e18758fa9c3afe165ccb60cb88c1379d11
5 changes: 4 additions & 1 deletion crates/vm/src/stdlib/_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4078,7 +4078,10 @@ mod _io {
vm.new_runtime_error(format!("reentrant call inside {type_name}.__repr__"))
);
};
let Some(data) = zelf.data.lock() else {
// Detach while blocked, like `lock_opt`: another thread can be
// stopped holding this mutex, and blocking on it while attached
// would leave no safepoint for that stop to complete at.
let Some(data) = zelf.data.lock_wrapped(|do_lock| vm.allow_threads(do_lock)) else {
// Reentrant call
return Ok(vm.ctx.new_str(Wtf8Buf::from(format!("<{type_name}>"))));
};
Expand Down
21 changes: 15 additions & 6 deletions crates/vm/src/stdlib/_winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod _winapi {
use crate::{
Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
builtins::PyStrRef,
common::lock::PyMutex,
common::lock::{PyMutex, PyMutexGuard},
convert::ToPyException,
function::{ArgMapping, ArgSequence, OptionalArg},
types::Constructor,
Expand Down Expand Up @@ -566,17 +566,26 @@ mod _winapi {
.map_err(|e| e.to_pyexception(vm))
}

/// Take `inner`, detaching while blocked.
///
/// `GetOverlappedResult` holds this mutex across its `allow_threads`
/// wait, so a stopped thread can still be holding it. Blocking on it
/// while attached would leave no safepoint for that stop to complete at.
fn lock_inner(&self, vm: &VirtualMachine) -> PyMutexGuard<'_, host_overlapped::Operation> {
vm.allow_threads(|| self.inner.lock())
}

#[pymethod]
fn GetOverlappedResult(&self, wait: bool, vm: &VirtualMachine) -> PyResult<(u32, u32)> {
let mut inner = self.inner.lock();
let mut inner = self.lock_inner(vm);
vm.allow_threads(|| inner.get_result(wait))
.map(|result| (result.transferred, result.error))
.map_err(|e| e.to_pyexception(vm))
}

#[pymethod]
fn getbuffer(&self, vm: &VirtualMachine) -> PyResult<Option<PyObjectRef>> {
let inner = self.inner.lock();
let inner = self.lock_inner(vm);
if !inner.is_completed() {
return Err(vm.new_value_error(
"can't get read buffer before GetOverlappedResult() signals the operation completed",
Expand All @@ -589,13 +598,13 @@ mod _winapi {

#[pymethod]
fn cancel(&self, vm: &VirtualMachine) -> PyResult<()> {
let mut inner = self.inner.lock();
let mut inner = self.lock_inner(vm);
inner.cancel().map_err(|e| e.to_pyexception(vm))
}

#[pygetset]
fn event(&self) -> isize {
let inner = self.inner.lock();
fn event(&self, vm: &VirtualMachine) -> isize {
let inner = self.lock_inner(vm);
inner.event() as isize
}
}
Expand Down