Skip to content

Commit f5085c7

Browse files
authored
ZJIT: Mark profiled objects when marking ISEQ (ruby#13784)
1 parent 1df94aa commit f5085c7

File tree

16 files changed

+128
-61
lines changed

16 files changed

+128
-61
lines changed

common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9376,6 +9376,7 @@ iseq.$(OBJEXT): {$(VPATH)}vm_debug.h
93769376
iseq.$(OBJEXT): {$(VPATH)}vm_opts.h
93779377
iseq.$(OBJEXT): {$(VPATH)}vm_sync.h
93789378
iseq.$(OBJEXT): {$(VPATH)}yjit.h
9379+
iseq.$(OBJEXT): {$(VPATH)}zjit.h
93799380
jit.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
93809381
jit.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
93819382
jit.$(OBJEXT): $(CCAN_DIR)/list/list.h

iseq.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "builtin.h"
4545
#include "insns.inc"
4646
#include "insns_info.inc"
47+
#include "zjit.h"
4748

4849
VALUE rb_cISeq;
4950
static VALUE iseqw_new(const rb_iseq_t *iseq);
@@ -401,11 +402,17 @@ rb_iseq_mark_and_move(rb_iseq_t *iseq, bool reference_updating)
401402
if (reference_updating) {
402403
#if USE_YJIT
403404
rb_yjit_iseq_update_references(iseq);
405+
#endif
406+
#if USE_ZJIT
407+
rb_zjit_iseq_update_references(body->zjit_payload);
404408
#endif
405409
}
406410
else {
407411
#if USE_YJIT
408412
rb_yjit_iseq_mark(body->yjit_payload);
413+
#endif
414+
#if USE_ZJIT
415+
rb_zjit_iseq_mark(body->zjit_payload);
409416
#endif
410417
}
411418
}

jit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ rb_assert_iseq_handle(VALUE handle)
415415
RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(handle, imemo_iseq));
416416
}
417417

418+
// Assert that we have the VM lock. Relevant mostly for multi ractor situations.
419+
// The GC takes the lock before calling us, and this asserts that it indeed happens.
420+
void
421+
rb_assert_holding_vm_lock(void)
422+
{
423+
ASSERT_vm_locking();
424+
}
425+
418426
int
419427
rb_IMEMO_TYPE_P(VALUE imemo, enum imemo_type imemo_type)
420428
{

test/ruby/test_zjit.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,12 @@ def test_instruction_order
951951
end
952952
end
953953

954+
def test_require_rubygems
955+
assert_runs 'true', %q{
956+
require 'rubygems'
957+
}, call_threshold: 2
958+
end
959+
954960
def test_module_name_with_guard_passes
955961
assert_compiles '"Integer"', %q{
956962
def test(mod)

yjit.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,6 @@ rb_yjit_shape_index(shape_id_t shape_id)
792792
return RSHAPE_INDEX(shape_id);
793793
}
794794

795-
// Assert that we have the VM lock. Relevant mostly for multi ractor situations.
796-
// The GC takes the lock before calling us, and this asserts that it indeed happens.
797-
void
798-
rb_yjit_assert_holding_vm_lock(void)
799-
{
800-
ASSERT_vm_locking();
801-
}
802-
803795
// The number of stack slots that vm_sendish() pops for send and invokesuper.
804796
size_t
805797
rb_yjit_sendish_sp_pops(const struct rb_callinfo *ci)

yjit/bindgen/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,16 @@ fn main() {
341341
.allowlist_function("rb_yjit_exit_locations_dict")
342342
.allowlist_function("rb_yjit_icache_invalidate")
343343
.allowlist_function("rb_optimized_call")
344-
.allowlist_function("rb_yjit_assert_holding_vm_lock")
345344
.allowlist_function("rb_yjit_sendish_sp_pops")
346345
.allowlist_function("rb_yjit_invokeblock_sp_pops")
347346
.allowlist_function("rb_yjit_set_exception_return")
348347
.allowlist_function("rb_yjit_str_concat_codepoint")
349348
.allowlist_type("robject_offsets")
350349
.allowlist_type("rstring_offsets")
351350

351+
// From jit.c
352+
.allowlist_function("rb_assert_holding_vm_lock")
353+
352354
// from vm_sync.h
353355
.allowlist_function("rb_vm_barrier")
354356

yjit/src/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ pub extern "C" fn rb_yjit_iseq_mark(payload: *mut c_void) {
19201920
// For aliasing, having the VM lock hopefully also implies that no one
19211921
// else has an overlapping &mut IseqPayload.
19221922
unsafe {
1923-
rb_yjit_assert_holding_vm_lock();
1923+
rb_assert_holding_vm_lock();
19241924
&*(payload as *const IseqPayload)
19251925
}
19261926
};
@@ -2009,7 +2009,7 @@ pub extern "C" fn rb_yjit_iseq_update_references(iseq: IseqPtr) {
20092009
// For aliasing, having the VM lock hopefully also implies that no one
20102010
// else has an overlapping &mut IseqPayload.
20112011
unsafe {
2012-
rb_yjit_assert_holding_vm_lock();
2012+
rb_assert_holding_vm_lock();
20132013
&*(payload as *const IseqPayload)
20142014
}
20152015
};

yjit/src/cruby_bindings.inc.rs

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

zjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ void rb_zjit_profile_insn(enum ruby_vminsn_type insn, rb_execution_context_t *ec
1313
void rb_zjit_profile_enable(const rb_iseq_t *iseq);
1414
void rb_zjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
1515
void rb_zjit_invalidate_ep_is_bp(const rb_iseq_t *iseq);
16+
void rb_zjit_iseq_mark(void *payload);
17+
void rb_zjit_iseq_update_references(void *payload);
1618
#else
1719
#define rb_zjit_enabled_p false
1820
static inline void rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception) {}

zjit/bindgen/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ fn main() {
352352
.allowlist_type("robject_offsets")
353353
.allowlist_type("rstring_offsets")
354354

355+
// From jit.c
356+
.allowlist_function("rb_assert_holding_vm_lock")
357+
355358
// from vm_sync.h
356359
.allowlist_function("rb_vm_barrier")
357360

0 commit comments

Comments
 (0)