Skip to content

Commit 960fae4

Browse files
XrXrtekknolagik0kubunst0012
authored
ZJIT: Add missing write barrier in profiling (rubyGH-13922)
Fixes `TestZJIT::test_require_rubygems`. It was crashing locally due to false collection of a live object. See <https://alanwu.space/post/write-barrier/>. Co-authored-by: Max Bernstein <max@bernsteinbear.com> Co-authored-by: Takashi Kokubun <takashi.kokubun@shopify.com> Co-authored-by: Stan Lo <stan.lo@shopify.com>
1 parent 571a8d2 commit 960fae4

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn main() {
167167
.allowlist_function("rb_gc_mark_movable")
168168
.allowlist_function("rb_gc_location")
169169
.allowlist_function("rb_gc_writebarrier")
170+
.allowlist_function("rb_gc_writebarrier_remember")
170171

171172
// VALUE variables for Ruby class objects
172173
// From include/ruby/internal/globals.h

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/profile.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ fn profile_operands(profiler: &mut Profiler, profile: &mut IseqProfile, n: usize
8989
let opnd_type = Type::from_value(profiler.peek_at_stack((n - i - 1) as isize));
9090
types[i] = types[i].union(opnd_type);
9191
}
92+
// In the loop above, we probably added a new reference to the profile through
93+
// the VALUE in Type. It's messy and relatively slow to conditionally run a
94+
// write barrier for each Type, so just remember to re-mark the iseq.
95+
unsafe { rb_gc_writebarrier_remember(profiler.iseq.into()) };
9296
}
9397

9498
#[derive(Debug)]

0 commit comments

Comments
 (0)