Skip to content

Commit 5e27581

Browse files
committed
ZJIT: Use rb_zjit_writebarrier_check_immediate() instead of rb_gc_writebarrier() in gen_write_barrier()
* To avoid calling rb_gc_writebarrier() with an immediate value in gen_write_barrier(), and avoid the LIR jump issue.
1 parent cc048f7 commit 5e27581

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

zjit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ rb_zjit_class_has_default_allocator(VALUE klass)
302302

303303
VALUE rb_vm_get_untagged_block_handler(rb_control_frame_t *reg_cfp);
304304

305+
void
306+
rb_zjit_writebarrier_check_immediate(VALUE recv, VALUE val)
307+
{
308+
if (!RB_SPECIAL_CONST_P(val)) {
309+
rb_gc_writebarrier(recv, val);
310+
}
311+
}
312+
305313
// Primitives used by zjit.rb. Don't put other functions below, which wouldn't use them.
306314
VALUE rb_zjit_enable(rb_execution_context_t *ec, VALUE self);
307315
VALUE rb_zjit_assert_compiles(rb_execution_context_t *ec, VALUE self);

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn main() {
144144
.allowlist_function("rb_gc_location")
145145
.allowlist_function("rb_gc_writebarrier")
146146
.allowlist_function("rb_gc_writebarrier_remember")
147+
.allowlist_function("rb_zjit_writebarrier_check_immediate")
147148

148149
// VALUE variables for Ruby class objects
149150
.allowlist_var("rb_cBasicObject")

zjit/src/codegen.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,11 +1130,12 @@ fn gen_store_field(asm: &mut Assembler, recv: Opnd, id: ID, offset: i32, val: Op
11301130
}
11311131

11321132
fn gen_write_barrier(asm: &mut Assembler, recv: Opnd, val: Opnd, val_type: Type) {
1133-
// See RB_OBJ_WRITE/rb_obj_write: it's just assignment and rb_obj_written()->rb_gc_writebarrier()
1133+
// See RB_OBJ_WRITE/rb_obj_write: it's just assignment and rb_obj_written().
1134+
// rb_obj_written() does: if (!RB_SPECIAL_CONST_P(val)) { rb_gc_writebarrier(recv, val); }
11341135
if !val_type.is_immediate() {
11351136
asm_comment!(asm, "Write barrier");
11361137
let recv = asm.load(recv);
1137-
asm_ccall!(asm, rb_gc_writebarrier, recv, val);
1138+
asm_ccall!(asm, rb_zjit_writebarrier_check_immediate, recv, val);
11381139
}
11391140
}
11401141

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.

0 commit comments

Comments
 (0)