Skip to content

Commit 7b6378d

Browse files
committed
Scan references to the heap from jl_handler_t from tasks
1 parent 9a25c65 commit 7b6378d

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

mmtk/src/conservative.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub unsafe fn mmtk_conservative_scan_task_stack(ta: *const jl_task_t) {
8080
log::debug!("Skip guard page: {}, {}", active_start, guard_page_start);
8181
conservative_scan_range(guard_page_start, active_start + size);
8282
} else {
83-
log::warn!("Skip stack for {:?}", ta);
83+
// log::warn!("Skip stack for {:?}", ta);
8484
}
8585
}
8686
pub unsafe fn mmtk_conservative_scan_task_registers(ta: *const jl_task_t) {
@@ -99,12 +99,12 @@ pub fn mmtk_conservative_scan_ptls_registers(ptls: &mut _jl_tls_states_t) {
9999
}
100100
// TODO: This scans the entire context type, which is slower.
101101
// We actually only need to scan registers.
102-
fn get_range<T>(ctx: &T) -> (Address, Address) {
102+
pub fn get_range<T>(ctx: &T) -> (Address, Address) {
103103
let start = Address::from_ptr(ctx);
104104
let ty_size = std::mem::size_of::<T>();
105105
(start, start + ty_size)
106106
}
107-
fn conservative_scan_range(lo: Address, hi: Address) {
107+
pub fn conservative_scan_range(lo: Address, hi: Address) {
108108
// The high address is exclusive
109109
let hi = if hi.is_aligned_to(BYTES_IN_ADDRESS) {
110110
hi - BYTES_IN_ADDRESS
@@ -122,7 +122,7 @@ fn conservative_scan_range(lo: Address, hi: Address) {
122122
cursor -= BYTES_IN_ADDRESS;
123123
}
124124
}
125-
fn is_potential_mmtk_object(addr: Address) -> Option<ObjectReference> {
125+
pub fn is_potential_mmtk_object(addr: Address) -> Option<ObjectReference> {
126126
if crate::object_model::is_addr_in_immixspace(addr) {
127127
// We only care about immix space. If the object is in other spaces, we won't move them, and we don't need to pin them.
128128
memory_manager::find_object_from_internal_pointer(addr, usize::MAX)

mmtk/src/scanning.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,51 @@ impl Scanning<JuliaVM> for VMScanning {
9393
}
9494
// }
9595

96+
// process jl_handler_t eh from task
97+
unsafe {
98+
use crate::conservative::is_potential_mmtk_object;
99+
use crate::conservative::CONSERVATIVE_ROOTS;
100+
101+
let mut eh = (*task).eh;
102+
loop {
103+
if !eh.is_null() {
104+
// get scope and add it as root
105+
let scope_address = Address::from_ptr((*eh).scope);
106+
if crate::object_model::is_addr_in_immixspace(scope_address) {
107+
let objref =
108+
ObjectReference::from_raw_address_unchecked(scope_address);
109+
node_buffer.push(objref);
110+
}
111+
112+
// conservatively scan eh_ctx and potentially traverse the list of handlers (_jl_handler_t *prev)
113+
let sigjump_buf = (*eh).eh_ctx[0].__jmpbuf;
114+
for buff in sigjump_buf {
115+
if let Some(obj) =
116+
is_potential_mmtk_object(Address::from_usize(buff as usize))
117+
{
118+
println!(
119+
"buf_addr (mmtk object) = {:x}, type = {}",
120+
buff,
121+
crate::julia_scanning::get_julia_object_type(
122+
Address::from_usize(buff as usize)
123+
)
124+
);
125+
CONSERVATIVE_ROOTS.lock().unwrap().insert(obj);
126+
}
127+
}
128+
129+
// Another option, call conservative_scan_range on the __jmpbuf array
130+
// use crate::conservative::conservative_scan_range;
131+
// use crate::conservative::get_range;
132+
// let (lo, hi) = get_range(&(*eh).eh_ctx[0].__jmpbuf);
133+
// conservative_scan_range(lo, hi);
134+
eh = (*eh).prev;
135+
} else {
136+
break;
137+
}
138+
}
139+
}
140+
96141
if task_is_root {
97142
// captures wrong root nodes before creating the work
98143
debug_assert!(

0 commit comments

Comments
 (0)