Skip to content

Commit eeb9f7f

Browse files
authored
Process pinning roots - port PR mmtk#142 (mmtk#192)
Port mmtk#142 to `dev`. Process both transitively pinning roots, and non transitively pinning roots.
1 parent 5918de4 commit eeb9f7f

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea/
22
julia/*.o
33
julia/*.dbj.obj
4-
.vscode
4+
.vscode
5+
mmtk/src/julia_types.rs
6+

mmtk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2018"
1111
[package.metadata.julia]
1212
# Our CI matches the following line and extract mmtk/julia. If this line is updated, please check ci yaml files and make sure it works.
1313
julia_repo = "https://github.com/mmtk/julia.git"
14-
julia_version = "0517ff8d7981202989ef055296ad42c52a79b758"
14+
julia_version = "7a953be76af34dee24e17cf2b33ba5fb0a7eac02"
1515

1616
[lib]
1717
crate-type = ["cdylib"]

mmtk/src/julia_scanning.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
162162

163163
let ta = obj.to_ptr::<jl_task_t>();
164164

165-
mmtk_scan_gcstack(ta, closure);
165+
mmtk_scan_gcstack(ta, closure, None);
166166

167167
let layout = (*jl_task_type).layout;
168168
debug_assert!((*layout).fielddesc_type_custom() == 0);
@@ -375,9 +375,10 @@ unsafe fn mmtk_jl_genericmemory_data_owner_field_address(m: *const jl_genericmem
375375
// mmtk_jl_genericmemory_data_owner_field_address(m).load::<*const mmtk_jl_value_t>()
376376
// }
377377

378-
pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
378+
pub unsafe fn mmtk_scan_gcstack<'a, EV: SlotVisitor<JuliaVMSlot>>(
379379
ta: *const jl_task_t,
380-
closure: &mut EV,
380+
mut closure: &'a mut EV,
381+
mut pclosure: Option<&'a mut EV>,
381382
) {
382383
let stkbuf = (*ta).ctx.stkbuf;
383384
let copy_stack = (*ta).ctx.copy_stack_custom();
@@ -406,16 +407,28 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
406407
let s_nroots_addr = ::std::ptr::addr_of!((*s).nroots);
407408
let mut nroots = read_stack(Address::from_ptr(s_nroots_addr), offset, lb, ub);
408409
debug_assert!(nroots.as_usize() as u32 <= std::u32::MAX);
409-
let mut nr = nroots >> 2;
410+
let mut nr = nroots >> 3;
410411

411412
loop {
413+
// if the 'pin' bit on the root type is not set, must transitively pin
414+
// and therefore use transitive pinning closure
415+
let closure_to_use: &mut &mut EV = if (nroots.as_usize() & 4) == 0 {
416+
&mut closure
417+
} else {
418+
// otherwise, use the pinning closure (if available)
419+
match &mut pclosure {
420+
Some(c) => c,
421+
None => &mut closure,
422+
}
423+
};
424+
412425
let rts = Address::from_mut_ptr(s).shift::<Address>(2);
413426
let mut i = 0;
414427
while i < nr {
415428
if (nroots.as_usize() & 1) != 0 {
416429
let slot = read_stack(rts.shift::<Address>(i as isize), offset, lb, ub);
417430
let real_addr = get_stack_addr(slot, offset, lb, ub);
418-
process_slot(closure, real_addr);
431+
process_slot(*closure_to_use, real_addr);
419432
} else {
420433
let real_addr =
421434
get_stack_addr(rts.shift::<Address>(i as isize), offset, lb, ub);
@@ -431,12 +444,12 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
431444

432445
// pointer is not malloced but function is native, so skip it
433446
if gc_ptr_tag(slot, 1) {
434-
process_offset_slot(closure, real_addr, 1);
447+
process_offset_slot(*closure_to_use, real_addr, 1);
435448
i += 2;
436449
continue;
437450
}
438451

439-
process_slot(closure, real_addr);
452+
process_slot(*closure_to_use, real_addr);
440453
}
441454

442455
i += 1;
@@ -452,7 +465,7 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
452465
let s_nroots_addr = ::std::ptr::addr_of!((*s).nroots);
453466
let new_nroots = read_stack(Address::from_ptr(s_nroots_addr), offset, lb, ub);
454467
nroots = new_nroots;
455-
nr = nroots >> 2;
468+
nr = nroots >> 3;
456469
continue;
457470
}
458471
}

mmtk/src/scanning.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ impl Scanning<JuliaVM> for VMScanning {
5353
use mmtk::util::Address;
5454

5555
let ptls: &mut _jl_tls_states_t = unsafe { std::mem::transmute(mutator.mutator_tls) };
56-
let mut slot_buffer = SlotBuffer { buffer: vec![] }; // need to be tpinned as they're all from the shadow stack
56+
let mut tpinning_slot_buffer = SlotBuffer { buffer: vec![] }; // need to be transitively pinned
57+
let mut pinning_slot_buffer = SlotBuffer { buffer: vec![] }; // roots from the shadow stack that we know that do not need to be transitively pinned
5758
let mut node_buffer = vec![];
5859

5960
// Scan thread local from ptls: See gc_queue_thread_local in gc.c
6061
let mut root_scan_task = |task: *const _jl_task_t, task_is_root: bool| {
6162
if !task.is_null() {
6263
unsafe {
63-
crate::julia_scanning::mmtk_scan_gcstack(task, &mut slot_buffer);
64+
crate::julia_scanning::mmtk_scan_gcstack(
65+
task,
66+
&mut tpinning_slot_buffer,
67+
Some(&mut pinning_slot_buffer),
68+
);
6469
}
6570
if task_is_root {
6671
// captures wrong root nodes before creating the work
@@ -134,13 +139,20 @@ impl Scanning<JuliaVM> for VMScanning {
134139

135140
// Push work
136141
const CAPACITY_PER_PACKET: usize = 4096;
137-
for tpinning_roots in slot_buffer
142+
for tpinning_roots in tpinning_slot_buffer
138143
.buffer
139144
.chunks(CAPACITY_PER_PACKET)
140145
.map(|c| c.to_vec())
141146
{
142147
factory.create_process_tpinning_roots_work(tpinning_roots);
143148
}
149+
for pinning_roots in pinning_slot_buffer
150+
.buffer
151+
.chunks(CAPACITY_PER_PACKET)
152+
.map(|c| c.to_vec())
153+
{
154+
factory.create_process_pinning_roots_work(pinning_roots);
155+
}
144156
for nodes in node_buffer.chunks(CAPACITY_PER_PACKET).map(|c| c.to_vec()) {
145157
factory.create_process_pinning_roots_work(nodes);
146158
}

0 commit comments

Comments
 (0)