From 191c8dbb00819636cdb8a2c28ee097054cae6ca4 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Thu, 24 Jul 2025 15:50:42 +0800 Subject: [PATCH] Update ruby repo revision We merged the ruby repo with the master branch. The upstream changed the global symbols table to a concurrent set. We handle it in a way similar to the fstrings table. --- mmtk/Cargo.toml | 2 +- mmtk/src/abi.rs | 9 +++++-- mmtk/src/weak_proc.rs | 25 ++++++++++++------- mmtk/src/weak_proc/concurrent_set_parallel.rs | 16 +++++++++--- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 5d3b195..c6d451c 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" # Metadata for the Ruby repository [package.metadata.ci-repos.ruby] repo = "mmtk/ruby" # This is used by actions/checkout, so the format is "owner/repo", not URL. -rev = "2bfc164e05d672cac6dfb5dad303636c6195828a" +rev = "e3be189efb1ddd31949519d9a7201abd7a62a0f2" [lib] name = "mmtk_ruby" diff --git a/mmtk/src/abi.rs b/mmtk/src/abi.rs index 1de2347..e697dee 100644 --- a/mmtk/src/abi.rs +++ b/mmtk/src/abi.rs @@ -1,6 +1,7 @@ use crate::api::RubyMutator; use crate::{extra_assert, upcalls, Ruby}; use mmtk::scheduler::GCWorker; +use mmtk::util::api_util::NullableObjectReference; use mmtk::util::{Address, ObjectReference, VMMutatorThread, VMWorkerThread}; // For the C binding @@ -11,6 +12,9 @@ pub const GC_THREAD_KIND_WORKER: libc::c_int = 1; pub const HIDDEN_SIZE_MASK: usize = 0x0000FFFFFFFFFFFF; +pub const MMTK_WEAK_CONCURRENT_SET_KIND_FSTRING: u8 = 0; +pub const MMTK_WEAK_CONCURRENT_SET_KIND_GLOBAL_SYMBOLS: u8 = 1; + // An opaque type for the C counterpart. #[allow(non_camel_case_types)] pub struct st_table; @@ -361,8 +365,8 @@ pub struct RubyUpcalls { pub get_cc_refinement_table_size: extern "C" fn() -> usize, pub update_cc_refinement_table: extern "C" fn(), // Get tables for specialized processing - pub get_fstring_table_obj: extern "C" fn() -> ObjectReference, - pub get_global_symbols_table: extern "C" fn() -> *mut st_table, + pub get_fstring_table_obj: extern "C" fn() -> NullableObjectReference, + pub get_global_symbols_table_obj: extern "C" fn() -> NullableObjectReference, // Detailed st_table info queries and operations pub st_get_num_entries: extern "C" fn(table: *const st_table) -> usize, pub st_get_size_info: extern "C" fn( @@ -388,6 +392,7 @@ pub struct RubyUpcalls { set: ObjectReference, begin: usize, end: usize, + kind: u8, stats: *mut ConcurrentSetStats, ), // Memory protection for code memory diff --git a/mmtk/src/weak_proc.rs b/mmtk/src/weak_proc.rs index 18ec920..f9622bc 100644 --- a/mmtk/src/weak_proc.rs +++ b/mmtk/src/weak_proc.rs @@ -6,7 +6,10 @@ use mmtk::{ vm::ObjectTracerContext, }; -use crate::{abi::GCThreadTLS, extra_assert, is_mmtk_object_safe, upcalls, Ruby}; +use crate::{ + abi::{self, GCThreadTLS}, + extra_assert, is_mmtk_object_safe, upcalls, Ruby, +}; pub mod concurrent_set_parallel; pub mod st_table_parallel; @@ -17,6 +20,13 @@ const SPECIALIZE_FSTRING_TABLE_PROCESSING: bool = true; /// Set this to true to use chunked processing optimization for the global symbols table. const SPECIALIZE_GLOBAL_SYMBOLS_TABLE_PROCESSING: bool = true; +#[repr(u8)] +#[derive(Clone, Copy)] +pub enum WeakConcurrentSetKind { + FString = abi::MMTK_WEAK_CONCURRENT_SET_KIND_FSTRING, + GlobalSymbols = abi::MMTK_WEAK_CONCURRENT_SET_KIND_GLOBAL_SYMBOLS, +} + pub struct WeakProcessor { /// Objects that needs `obj_free` called when dying. /// If it is a bottleneck, replace it with a lock-free data structure, @@ -80,12 +90,11 @@ impl WeakProcessor { Box::new(UpdateWbUnprotectedObjectsList) as _, ]); - let forward = crate::mmtk().get_plan().current_gc_may_move_object(); - if SPECIALIZE_FSTRING_TABLE_PROCESSING { concurrent_set_parallel::process_weak_concurrent_set_chunked( "fstring", - (upcalls().get_fstring_table_obj)(), + (upcalls().get_fstring_table_obj)().into(), + WeakConcurrentSetKind::FString, worker, ); } else { @@ -94,12 +103,10 @@ impl WeakProcessor { } if SPECIALIZE_GLOBAL_SYMBOLS_TABLE_PROCESSING { - st_table_parallel::process_weak_table_chunked( + concurrent_set_parallel::process_weak_concurrent_set_chunked( "global symbols", - (upcalls().get_global_symbols_table)(), - false, - true, - forward, + (upcalls().get_global_symbols_table_obj)().into(), + WeakConcurrentSetKind::GlobalSymbols, worker, ); } else { diff --git a/mmtk/src/weak_proc/concurrent_set_parallel.rs b/mmtk/src/weak_proc/concurrent_set_parallel.rs index d05915e..0ae5b28 100644 --- a/mmtk/src/weak_proc/concurrent_set_parallel.rs +++ b/mmtk/src/weak_proc/concurrent_set_parallel.rs @@ -8,13 +8,19 @@ use mmtk::{ util::ObjectReference, }; -use crate::{abi::ConcurrentSetStats, upcalls, Ruby}; +use crate::{abi::ConcurrentSetStats, upcalls, weak_proc::WeakConcurrentSetKind, Ruby}; pub fn process_weak_concurrent_set_chunked( name: &'static str, - set: ObjectReference, + set: Option, + kind: WeakConcurrentSetKind, worker: &mut GCWorker, ) { + let Some(set) = set else { + debug!("Set {name} is empty. Skipping."); + return; + }; + let num_entries = (upcalls().concurrent_set_get_num_entries)(set); let capacity = (upcalls().concurrent_set_get_capacity)(set); debug!("name: {name}, num_entries: {num_entries}, capacity: {capacity}"); @@ -44,6 +50,7 @@ pub fn process_weak_concurrent_set_chunked( set, begin, end, + kind: kind as u8, counter: counter.clone(), }) as _ }) @@ -59,6 +66,7 @@ struct UpdateConcurrentSetEntriesParallel { set: ObjectReference, begin: usize, end: usize, + kind: u8, counter: Arc, } @@ -82,7 +90,9 @@ impl GCWork for UpdateConcurrentSetEntriesParallel { ); let mut stats = ConcurrentSetStats::default(); - (upcalls().concurrent_set_update_entries_range)(self.set, self.begin, self.end, &mut stats); + (upcalls().concurrent_set_update_entries_range)( + self.set, self.begin, self.end, self.kind, &mut stats, + ); debug!( "Done updating entries of concurrent set '{}' range {}-{}, live: {}, moved: {}, deleted: {}",