Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ tmp
.DS_Store

test.rb

__pycache__
2 changes: 0 additions & 2 deletions gc/mmtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions gc/mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ sysinfo = "0.32.0"
features = ["vo_bit", "non_moving_root", "object_pinning", "sticky_immix_non_moving_nursery"]

# Uncomment the following lines to use mmtk-core from the official repository.
git = "https://github.com/mmtk/mmtk-core.git"
rev = "42c1ac176c4d931c5503e880e650bb9e84bf802c"
#git = "https://github.com/mmtk/mmtk-core.git"
#rev = "42c1ac176c4d931c5503e880e650bb9e84bf802c"

# Uncomment the following line to use mmtk-core from a local repository.
# path = "../../../mmtk-core"
path = "/home/wks/projects/mmtk-github/parallels/feature/ebpf-edge-node/mmtk-core"

[features]
default = []
Expand Down
14 changes: 14 additions & 0 deletions gc/mmtk/src/pinning_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ struct PinPinningChildren {

impl GCWork<Ruby> for PinPinningChildren {
fn do_work(&mut self, worker: &mut GCWorker<Ruby>, _mmtk: &'static MMTK<Ruby>) {
let num_pinning_objs = self.pinning_objs.len();

let gc_tls = unsafe { GCThreadTLS::from_vwt_check(worker.tls) };
let mut pinned_objs = vec![];
let mut newly_pinned_objs = vec![];
Expand Down Expand Up @@ -136,12 +138,24 @@ impl GCWork<Ruby> for PinPinningChildren {
}
});

let num_pinned_objs = pinned_objs.len();

for target_object in pinned_objs {
if memory_manager::pin_object(target_object) {
newly_pinned_objs.push(target_object);
}
}

let num_newly_pinned_objs = newly_pinned_objs.len();

probe::probe!(
ruby_mmtk,
pin_pinning_children,
num_pinning_objs,
num_pinned_objs,
num_newly_pinned_objs
);

let mut pinned_objs = crate::binding()
.pinning_registry
.pinned_objs
Expand Down
22 changes: 21 additions & 1 deletion gc/mmtk/src/weak_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,27 @@ impl WeakProcessor {
}

fn process_obj_free_candidates(obj_free_candidates: &mut Vec<ObjectReference>) {
let num_candidates = obj_free_candidates.len();
let mut num_retained = 0;

obj_free_candidates.retain_mut(|object| {
if object.is_reachable() {
let new_object = object.forward();
trace!("Forwarding obj_free candidate: {object} -> {new_object}");
*object = new_object;
num_retained += 1;
true
} else {
upcalls::call_obj_free(*object);
false
}
});
probe::probe!(
ruby_mmtk,
process_obj_free_candidates,
num_candidates,
num_retained
);
}

struct ProcessParallelObjFreeCandidates {
Expand Down Expand Up @@ -210,6 +220,9 @@ impl ProcessWeakReferences {
.try_lock()
.expect("Mutators should not be holding the lock.");

let num_weakrefs = weak_references.len();
let mut num_retained = 0;

weak_references.retain_mut(|object_ptr| {
let object = object_ptr.get_forwarded_object().unwrap_or(*object_ptr);

Expand All @@ -219,12 +232,19 @@ impl ProcessWeakReferences {

if object.is_reachable() {
upcalls::handle_weak_references(object, moving_gc);

num_retained += 1;
true
} else {
false
}
});

probe::probe!(
ruby_mmtk,
process_weak_references,
num_weakrefs,
num_retained
);
}
}

Expand Down
17 changes: 17 additions & 0 deletions tools/timeline/capture_ruby_mmtk.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
usdt:$MMTK:ruby_mmtk:process_obj_free_candidates {
if (@enable_print) {
printf("process_obj_free_candidates,meta,%d,%lu,%lu,%lu\n", tid, nsecs, arg0, arg1);
}
}

usdt:$MMTK:ruby_mmtk:process_weak_references {
if (@enable_print) {
printf("process_weak_references,meta,%d,%lu,%lu,%lu\n", tid, nsecs, arg0, arg1);
}
}

usdt:$MMTK:ruby_mmtk:pin_pinning_children {
if (@enable_print) {
printf("pin_pinning_children,meta,%d,%lu,%lu,%lu,%lu\n", tid, nsecs, arg0, arg1, arg2);
}
}
47 changes: 47 additions & 0 deletions tools/timeline/visualize_ruby_mmtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

def enrich_meta_extra(log_processor, name, tid, ts, gc, wp, args):
match name:
case "process_obj_free_candidates":
num_candidates, num_retained = [int(arg) for arg in args]
num_freed = num_candidates - num_retained

aggregate_dict = {
"num_candidates": num_candidates,
"num_retained": num_retained,
"num_freed": num_freed,
}

if wp is not None:
log_processor.add_aggregatable_arg(wp, name, aggregate_dict)
if gc is not None:
log_processor.add_aggregatable_arg(gc, name, aggregate_dict)

case "process_weak_references":
num_weakrefs, num_retained = [int(arg) for arg in args]
num_removed = num_weakrefs - num_retained

aggregate_dict = {
"num_weakrefs": num_weakrefs,
"num_retained": num_retained,
"num_removed": num_removed,
}

if wp is not None:
log_processor.add_aggregatable_arg(wp, name, aggregate_dict)
if gc is not None:
log_processor.add_aggregatable_arg(gc, name, aggregate_dict)

case "pin_pinning_children":
num_pinning_objs, num_pinned_objs, num_newly_pinned_objs = [int(arg) for arg in args]

aggregate_dict = {
"num_pinning_objs": num_pinning_objs,
"num_pinned_objs": num_pinned_objs,
"num_newly_pinned_objs": num_newly_pinned_objs,
}

if wp is not None:
log_processor.add_aggregatable_arg(wp, name, aggregate_dict)
if gc is not None:
log_processor.add_aggregatable_arg(gc, name, aggregate_dict)
Loading