diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 7723a44..6c8d602 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -43,22 +43,22 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys", + "windows-sys 0.60.2", ] [[package]] @@ -94,9 +94,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" [[package]] name = "built" @@ -124,14 +124,14 @@ checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "cc" -version = "1.2.30" +version = "1.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" dependencies = [ "jobserver", "libc", @@ -140,9 +140,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "colorchoice" @@ -220,7 +220,7 @@ checksum = "6178a82cf56c836a3ba61a7935cdb1c49bfaa6fa4327cd5bf554a503087de26b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -252,7 +252,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -280,9 +280,9 @@ dependencies = [ [[package]] name = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] @@ -326,9 +326,9 @@ checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -363,7 +363,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi", "libc", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -402,14 +402,14 @@ checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "jobserver" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ "getrandom", "libc", @@ -423,9 +423,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libgit2-sys" @@ -485,7 +485,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.31.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=31a78a41f02fc7228780b501c4944ba750e32ee4#31a78a41f02fc7228780b501c4944ba750e32ee4" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=6eb1328bfce34a7e0fc4b84fd0b65a849b083e0e#6eb1328bfce34a7e0fc4b84fd0b65a849b083e0e" dependencies = [ "atomic", "atomic-traits", @@ -511,6 +511,7 @@ dependencies = [ "num_cpus", "portable-atomic", "probe", + "rayon-core", "regex", "rustversion", "spin", @@ -523,12 +524,12 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.31.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=31a78a41f02fc7228780b501c4944ba750e32ee4#31a78a41f02fc7228780b501c4944ba750e32ee4" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=6eb1328bfce34a7e0fc4b84fd0b65a849b083e0e#6eb1328bfce34a7e0fc4b84fd0b65a849b083e0e" dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -587,9 +588,9 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pkg-config" @@ -644,9 +645,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -688,9 +689,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" dependencies = [ "aho-corasick", "memchr", @@ -700,9 +701,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" dependencies = [ "aho-corasick", "memchr", @@ -711,9 +712,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" [[package]] name = "rustc_version" @@ -726,9 +727,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "scopeguard" @@ -759,7 +760,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -791,21 +792,20 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strum" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" [[package]] name = "strum_macros" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" dependencies = [ "heck", "proc-macro2", "quote", - "rustversion", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -820,9 +820,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -845,9 +845,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" dependencies = [ "tinyvec_macros", ] @@ -887,13 +887,14 @@ dependencies = [ [[package]] name = "url" -version = "2.5.4" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -958,7 +959,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ "windows-core", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -970,7 +971,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-result", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -981,7 +982,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -992,16 +993,22 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-result" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1010,7 +1017,16 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -1019,14 +1035,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -1035,48 +1068,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "wit-bindgen-rt" version = "0.39.0" diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index ce087c8..1b2940b 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 = "64c07dcd7ca763e25607848df3be909135e02589" +rev = "fe51e6277b4df810a90c4474f951ed0a263acea0" [lib] name = "mmtk_ruby" @@ -37,7 +37,7 @@ features = ["is_mmtk_object", "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 = "31a78a41f02fc7228780b501c4944ba750e32ee4" +rev = "6eb1328bfce34a7e0fc4b84fd0b65a849b083e0e" # Uncomment the following line to use mmtk-core from a local repository. #path = "../../mmtk-core" diff --git a/mmtk/cbindgen.toml b/mmtk/cbindgen.toml index 84837b8..3a2a920 100644 --- a/mmtk/cbindgen.toml +++ b/mmtk/cbindgen.toml @@ -8,8 +8,9 @@ tab_width = 4 usize_is_size_t = true -after_includes = """ +includes = ["ruby/internal/value.h"] +after_includes = """ typedef struct MMTk_Builder MMTk_Builder; typedef struct MMTk_Mutator MMTk_Mutator; @@ -26,6 +27,7 @@ typedef uint32_t MMTk_AllocationSemantics; [export] include = ["HiddenHeader"] +exclude = ["VALUE"] [export.rename] "MMTKBuilder" = "MMTk_Builder" diff --git a/mmtk/src/abi.rs b/mmtk/src/abi.rs index e697dee..f562180 100644 --- a/mmtk/src/abi.rs +++ b/mmtk/src/abi.rs @@ -15,6 +15,27 @@ 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; +pub(crate) const RUBY_IMMEDIATE_MASK: usize = 0x07; + +#[allow(non_upper_case_globals)] // Match Ruby definition +pub(crate) const Qundef: VALUE = VALUE(0x24); + +#[repr(transparent)] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub struct VALUE(pub usize); + +impl VALUE { + pub fn is_special_const(&self) -> bool { + self.0 == 0 || self.0 & RUBY_IMMEDIATE_MASK != 0 + } +} + +impl From for VALUE { + fn from(value: ObjectReference) -> Self { + Self(value.to_raw_address().as_usize()) + } +} + // An opaque type for the C counterpart. #[allow(non_camel_case_types)] pub struct st_table; diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 3867a7f..106fe15 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -9,6 +9,7 @@ use crate::abi; use crate::abi::HiddenHeader; use crate::abi::RawVecOfObjRef; use crate::abi::RubyBindingOptions; +use crate::abi::VALUE; use crate::binding; use crate::binding::RubyBinding; use crate::mmtk; @@ -421,3 +422,8 @@ pub extern "C" fn mmtk_current_gc_is_nursery() -> bool { .generational() .is_some_and(|gen| gen.is_current_gc_nursery()) } + +#[no_mangle] +pub extern "C" fn mmtk_discover_weak_field(field: *mut VALUE) { + crate::binding().weak_proc.discover_weak_field(field) +} diff --git a/mmtk/src/weak_proc.rs b/mmtk/src/weak_proc.rs index f9622bc..ea5ab1c 100644 --- a/mmtk/src/weak_proc.rs +++ b/mmtk/src/weak_proc.rs @@ -2,12 +2,12 @@ use std::sync::Mutex; use mmtk::{ scheduler::{GCWork, GCWorker, WorkBucketStage}, - util::ObjectReference, + util::{Address, ObjectReference}, vm::ObjectTracerContext, }; use crate::{ - abi::{self, GCThreadTLS}, + abi::{self, GCThreadTLS, Qundef, VALUE}, extra_assert, is_mmtk_object_safe, upcalls, Ruby, }; @@ -27,11 +27,15 @@ pub enum WeakConcurrentSetKind { GlobalSymbols = abi::MMTK_WEAK_CONCURRENT_SET_KIND_GLOBAL_SYMBOLS, } +pub type FieldType = *mut VALUE; + pub struct WeakProcessor { /// Objects that needs `obj_free` called when dying. /// If it is a bottleneck, replace it with a lock-free data structure, /// or add candidates in batch. obj_free_candidates: Mutex>, + /// Weak fields discovered during the current GC. + weak_fields: Mutex>, } impl Default for WeakProcessor { @@ -44,6 +48,7 @@ impl WeakProcessor { pub fn new() -> Self { Self { obj_free_candidates: Mutex::new(Vec::new()), + weak_fields: Default::default(), } } @@ -70,6 +75,28 @@ impl WeakProcessor { std::mem::take(obj_free_candidates.as_mut()) } + pub fn clear_weak_fields(&self) { + let mut weak_fields = self + .weak_fields + .try_lock() + .expect("Should not have contention."); + weak_fields.clear(); + } + + pub fn discover_weak_field(&self, field: FieldType) { + let mut weak_fields = self.weak_fields.lock().unwrap(); + weak_fields.push(field); + trace!("Pushed weak field {field:?}"); + } + + pub fn get_all_weak_fields(&self) -> Vec { + let mut weak_fields = self + .weak_fields + .try_lock() + .expect("Should not have contention."); + std::mem::take(&mut weak_fields) + } + pub fn process_weak_stuff( &self, worker: &mut GCWorker, @@ -88,6 +115,7 @@ impl WeakProcessor { Box::new(UpdateCCRefinementTable) as _, // END: Weak tables Box::new(UpdateWbUnprotectedObjectsList) as _, + Box::new(UpdateWeakFields) as _, ]); if SPECIALIZE_FSTRING_TABLE_PROCESSING { @@ -317,3 +345,49 @@ impl Forwardable for ObjectReference { self.get_forwarded_object().unwrap_or(*self) } } + +struct UpdateWeakFields; + +impl GCWork for UpdateWeakFields { + fn do_work(&mut self, _worker: &mut GCWorker, _mmtk: &'static mmtk::MMTK) { + let weak_fields = crate::binding().weak_proc.get_all_weak_fields(); + + let num_fields = weak_fields.len(); + let mut live = 0usize; + let mut forwarded = 0usize; + + debug!("Updating {num_fields} weak fields..."); + + for field in weak_fields { + let old_value = unsafe { *field }; + trace!(" Visiting weak field {field:?} -> {old_value:?}"); + + if old_value.is_special_const() { + continue; + } + + let addr = unsafe { Address::from_usize(old_value.0) }; + if !addr.is_mapped() { + panic!("Field {field:?} value {addr} points to unmapped area"); + } + let Some(old_objref) = mmtk::memory_manager::is_mmtk_object(addr) else { + panic!("Field {field:?} value {addr} is an invalid object reference"); + }; + + if old_objref.is_reachable() { + live += 1; + if let Some(new_objref) = old_objref.get_forwarded_object() { + forwarded += 1; + let new_value = VALUE::from(new_objref); + trace!(" Updated weak field {field:?} to {new_value:?}"); + unsafe { *field = new_value }; + } + } else { + unsafe { *field = Qundef }; + } + } + + debug!("Updated {num_fields} weak fields. {live} live, {forwarded} forwarded."); + probe!(mmtk_ruby, update_weak_fields, num_fields, live, forwarded); + } +} diff --git a/tools/tracing/timeline/capture_ruby.bt b/tools/tracing/timeline/capture_ruby.bt index 0dfa715..0e1472a 100644 --- a/tools/tracing/timeline/capture_ruby.bt +++ b/tools/tracing/timeline/capture_ruby.bt @@ -99,3 +99,9 @@ usdt:$MMTK:mmtk_ruby:update_wb_unprotected_objects_list { printf("update_wb_unprotected_objects_list,meta,%d,%lu,%lu,%lu\n", tid, nsecs, arg0, arg1); } } + +usdt:$MMTK:mmtk_ruby:update_weak_fields { + if (@enable_print) { + printf("update_weak_fields,meta,%d,%lu,%lu,%lu,%lu\n", tid, nsecs, arg0, arg1, arg2); + } +} diff --git a/tools/tracing/timeline/visualize_ruby.py b/tools/tracing/timeline/visualize_ruby.py index 1298014..62eeaff 100755 --- a/tools/tracing/timeline/visualize_ruby.py +++ b/tools/tracing/timeline/visualize_ruby.py @@ -71,6 +71,8 @@ def enrich_meta_extra(log_processor, name, tid, ts, gc, wp, args): case "weak_cs_par_final": num_entries = int(args[0]) + if "set_name" not in wp["args"]: + return set_name = wp["args"]["set_name"] gc["args"].setdefault(set_name, {}) gc["args"][set_name] |= { @@ -178,3 +180,14 @@ def enrich_meta_extra(log_processor, name, tid, ts, gc, wp, args): "diff": after - before, }, } + + case "update_weak_fields": + num_fields, live, forwarded = [int(x) for x in args[0:3]] + wp["args"] |= { + "wb_unprotected_objects": { + "num_fields": num_fields, + "live": live, + "forwarded": forwarded, + "cleared": num_fields - live, + }, + }