diff --git a/.gitignore b/.gitignore index 1c8c8f1..23e6425 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ tmp .DS_Store test.rb + +__pycache__ diff --git a/gc/mmtk/Cargo.lock b/gc/mmtk/Cargo.lock index 98046ed..cff4b72 100644 --- a/gc/mmtk/Cargo.lock +++ b/gc/mmtk/Cargo.lock @@ -489,7 +489,6 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "mmtk" version = "0.33.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=42c1ac176c4d931c5503e880e650bb9e84bf802c#42c1ac176c4d931c5503e880e650bb9e84bf802c" dependencies = [ "atomic", "atomic-traits", @@ -525,7 +524,6 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.33.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=42c1ac176c4d931c5503e880e650bb9e84bf802c#42c1ac176c4d931c5503e880e650bb9e84bf802c" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/gc/mmtk/Cargo.toml b/gc/mmtk/Cargo.toml index 23902c6..1343cc4 100644 --- a/gc/mmtk/Cargo.toml +++ b/gc/mmtk/Cargo.toml @@ -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 = [] diff --git a/gc/mmtk/src/pinning_registry.rs b/gc/mmtk/src/pinning_registry.rs index bd51148..bb7c910 100644 --- a/gc/mmtk/src/pinning_registry.rs +++ b/gc/mmtk/src/pinning_registry.rs @@ -106,6 +106,8 @@ struct PinPinningChildren { impl GCWork for PinPinningChildren { fn do_work(&mut self, worker: &mut GCWorker, _mmtk: &'static MMTK) { + 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![]; @@ -136,12 +138,24 @@ impl GCWork 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 diff --git a/gc/mmtk/src/weak_proc.rs b/gc/mmtk/src/weak_proc.rs index 68d79b7..7df613d 100644 --- a/gc/mmtk/src/weak_proc.rs +++ b/gc/mmtk/src/weak_proc.rs @@ -131,17 +131,27 @@ impl WeakProcessor { } fn process_obj_free_candidates(obj_free_candidates: &mut Vec) { + 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 { @@ -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); @@ -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 + ); } } diff --git a/tools/timeline/capture_ruby_mmtk.bt b/tools/timeline/capture_ruby_mmtk.bt new file mode 100644 index 0000000..c2569cc --- /dev/null +++ b/tools/timeline/capture_ruby_mmtk.bt @@ -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); + } +} diff --git a/tools/timeline/visualize_ruby_mmtk.py b/tools/timeline/visualize_ruby_mmtk.py new file mode 100644 index 0000000..781bc5b --- /dev/null +++ b/tools/timeline/visualize_ruby_mmtk.py @@ -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)