Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 25 additions & 19 deletions crates/vm/src/builtins/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,14 @@ impl FrameObject {
} else {
self.iframe()
};
target.pending_stack_pops.store(pop_count as u32, Relaxed);
target.pending_unwind_from_stack.store(start_stack, Relaxed);
target
.cold()
.pending_stack_pops
.store(pop_count as u32, Relaxed);
target
.cold()
.pending_unwind_from_stack
.store(start_stack, Relaxed);
target.lasti.store(best_addr as u32, Relaxed);
Ok(())
}
Expand All @@ -647,9 +653,9 @@ impl FrameObject {
// Read from live source iframe if available.
let live = self.find_live_source_iframe();
let trace = if !live.is_null() {
unsafe { &*live }.trace.lock().clone()
unsafe { &*live }.cold().trace.lock().clone()
} else {
self.iframe().trace.lock().clone()
self.iframe().cold().trace.lock().clone()
};
trace.unwrap_or_else(|| vm.ctx.none())
}
Expand All @@ -667,13 +673,13 @@ impl FrameObject {
PySetterValue::Delete => None,
};
// Set on the materialized FrameObject.
(*self.iframe().trace.lock()).clone_from(&trace);
(*self.iframe().cold().trace.lock()).clone_from(&trace);
// Also propagate to the live source iframe if this is a
// materialized copy of a stack-allocated frame, so pdb's
// f_trace assignment takes effect on the executing frame.
let live = self.find_live_source_iframe();
if !live.is_null() {
*unsafe { &*live }.trace.lock() = trace;
*unsafe { &*live }.cold().trace.lock() = trace;
}
}

Expand All @@ -682,7 +688,7 @@ impl FrameObject {
fn f_trace_lines(vm: &VirtualMachine, zelf: PyObjectRef) -> PyResult {
let zelf: FrameObjectRef = zelf.downcast().unwrap_or_else(|_| unreachable!());

let boxed = zelf.iframe().trace_lines.lock();
let boxed = zelf.iframe().cold().trace_lines.lock();
Ok(vm.ctx.new_bool(*boxed).into())
}

Expand All @@ -701,11 +707,11 @@ impl FrameObject {
.map_err(|_| vm.new_type_error("attribute value type must be bool"))?;

let val = !value.as_bigint().is_zero();
*zelf.iframe().trace_lines.lock() = val;
*zelf.iframe().cold().trace_lines.lock() = val;
// Propagate to live source iframe.
let live = zelf.find_live_source_iframe();
if !live.is_null() {
*unsafe { &*live }.trace_lines.lock() = val;
*unsafe { &*live }.cold().trace_lines.lock() = val;
}

Ok(())
Expand All @@ -718,7 +724,7 @@ impl FrameObject {
#[pymember(type = "bool")]
fn f_trace_opcodes(vm: &VirtualMachine, zelf: PyObjectRef) -> PyResult {
let zelf: FrameObjectRef = zelf.downcast().unwrap_or_else(|_| unreachable!());
let trace_opcodes = zelf.iframe().trace_opcodes.lock();
let trace_opcodes = zelf.iframe().cold().trace_opcodes.lock();
Ok(vm.ctx.new_bool(*trace_opcodes).into())
}

Expand All @@ -737,11 +743,11 @@ impl FrameObject {
.map_err(|_| vm.new_type_error("attribute value type must be bool"))?;

let val = !value.as_bigint().is_zero();
*zelf.iframe().trace_opcodes.lock() = val;
*zelf.iframe().cold().trace_opcodes.lock() = val;
// Propagate to live source iframe.
let live = zelf.find_live_source_iframe();
if !live.is_null() {
*unsafe { &*live }.trace_opcodes.lock() = val;
*unsafe { &*live }.cold().trace_opcodes.lock() = val;
}

// TODO: Implement the equivalent of _PyEval_SetOpcodeTrace()
Expand Down Expand Up @@ -798,10 +804,10 @@ impl Py<FrameObject> {
self.clear_stack_and_cells();

// Clear temporary refs
self.iframe().temporary_refs.lock().clear();
self.iframe().f_locals_hidden_overlay.lock().take();
self.iframe().f_extra_locals.lock().take();
self.iframe().retained_back.lock().take();
self.iframe().cold().temporary_refs.lock().clear();
self.iframe().cold().f_locals_hidden_overlay.lock().take();
self.iframe().cold().f_extra_locals.lock().take();
self.iframe().cold().retained_back.lock().take();

Ok(())
}
Expand Down Expand Up @@ -853,7 +859,7 @@ impl Py<FrameObject> {
}
if prev.is_null() {
// Check retained_back for frames whose callers have returned
let retained = self.iframe().retained_back.lock().clone();
let retained = self.iframe().cold().retained_back.lock().clone();
if let Some(frame) = retained {
frame.mark_escaped();
return Some(frame);
Expand All @@ -879,7 +885,7 @@ impl Py<FrameObject> {
}

// The caller already returned — check retained_back
let retained = self.iframe().retained_back.lock().clone();
let retained = self.iframe().cold().retained_back.lock().clone();
if let Some(frame) = retained {
frame.mark_escaped();
return Some(frame);
Expand All @@ -906,7 +912,7 @@ impl Py<FrameObject> {
let iframe = unsafe { &*cur };
let fo = iframe.materialize(vm).to_owned();
if let Some(child) = child_fo.take() {
let mut guard = child.iframe().retained_back.lock();
let mut guard = child.iframe().cold().retained_back.lock();
if guard.is_none() {
*guard = Some(fo.clone());
}
Expand Down
7 changes: 6 additions & 1 deletion crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,12 @@ impl PyType {
// temporary refs so they never see a dangling pointer.
let keep_alive = |type_ref: PyTypeRef, retired: &mut Vec<PyObjectRef>| {
if let Some(frame) = vm.current_frame() {
frame.iframe().temporary_refs.lock().push(type_ref.into());
frame
.iframe()
.cold()
.temporary_refs
.lock()
.push(type_ref.into());
} else {
retired.push(type_ref.into());
}
Expand Down
Loading
Loading