From 7bdb42249ebeffbb71ff2bb9c55cc65d1221e80a Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Fri, 23 Aug 2024 18:01:20 +0800 Subject: [PATCH] Expose an API for heap traversal. Expose the `MMTK::enumerate_object` method for implementing heap traversal. That allows the Ruby VM to enable ObjectSpace.each_object and TracePoint. The test case whitelist is also updated to not exclude related test cases so that mmtk-core binding tests will use those test cases. --- mmtk/Cargo.toml | 2 +- mmtk/src/api.rs | 12 ++++++++++++ ruby-test-cases.txt | 8 ++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 0b9d773..79bb6a9 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 = "8c5bd19b7a73c5156c4e2b9ee25cbf89c66816b8" +rev = "fd77eb5b3bd85f1e1ae15a8cfd704e027b25b0a5" [lib] name = "mmtk_ruby" diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 2b2500a..8d1c67e 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -374,3 +374,15 @@ pub extern "C" fn mmtk_object_reference_write_post( ignored_target, ) } + +/// Enumerate objects. This function will call `callback(object, data)` for each object. It has +/// undefined behavior if allocation or GC happens while this function is running. +#[no_mangle] +pub extern "C" fn mmtk_enumerate_objects( + callback: extern "C" fn(ObjectReference, *mut libc::c_void), + data: *mut libc::c_void, +) { + crate::mmtk().enumerate_objects(|object| { + callback(object, data); + }) +} diff --git a/ruby-test-cases.txt b/ruby-test-cases.txt index 499fd23..1337784 100644 --- a/ruby-test-cases.txt +++ b/ruby-test-cases.txt @@ -53,7 +53,7 @@ test/ruby/test_integer.rb test/ruby/test_io_buffer.rb test/ruby/test_io_m17n.rb # test/ruby/test_io.rb XXXXX leaks? -# test/ruby/test_iseq.rb XXXXX failures +test/ruby/test_iseq.rb test/ruby/test_iterator.rb test/ruby/test_key_error.rb test/ruby/test_keyword.rb @@ -75,8 +75,8 @@ test/ruby/test_nomethod_error.rb test/ruby/test_not.rb test/ruby/test_numeric.rb test/ruby/test_object.rb -# test/ruby/test_objectspace.rb XXXX failures -# test/ruby/test_optimization.rb XXXXX hard crash +test/ruby/test_objectspace.rb +test/ruby/test_optimization.rb test/ruby/test_pack.rb test/ruby/test_parse.rb test/ruby/test_path.rb @@ -98,7 +98,7 @@ test/ruby/test_require.rb # test/ruby/test_rubyoptions.rb XXXX failures and crashes # test/ruby/test_rubyvm_mjit.rb XXXXX query test/ruby/test_rubyvm.rb -# test/ruby/test_settracefunc.rb XXXX failures +test/ruby/test_settracefunc.rb test/ruby/test_signal.rb test/ruby/test_sleep.rb test/ruby/test_sprintf_comb.rb