@@ -59,6 +59,22 @@ jit_get_arg(jitstate_t* jit, size_t arg_idx)
5959 return * (jit -> pc + arg_idx + 1 );
6060}
6161
62+ // Load a pointer to a GC'd object into a register and keep track of the reference
63+ static void
64+ jit_mov_gc_ptr (jitstate_t * jit , codeblock_t * cb , x86opnd_t reg , VALUE ptr )
65+ {
66+ RUBY_ASSERT (reg .type == OPND_REG && reg .num_bits == 64 );
67+ RUBY_ASSERT (!SPECIAL_CONST_P (ptr ));
68+
69+ mov (cb , reg , const_ptr_opnd ((void * )ptr ));
70+ // The pointer immediate is encoded as the last part of the mov written out.
71+ uint32_t ptr_offset = cb -> write_pos - sizeof (VALUE );
72+
73+ if (!rb_darray_append (& jit -> block -> gc_object_offsets , ptr_offset )) {
74+ rb_bug ("allocation failed" );
75+ }
76+ }
77+
6278/**
6379Generate an inline exit to return to the interpreter
6480*/
@@ -1083,7 +1099,7 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
10831099 assume_method_lookup_stable (cd -> cc , cme , jit -> block );
10841100
10851101 // Bail if receiver class is different from compile-time call cache class
1086- mov ( cb , REG1 , imm_opnd ( cd -> cc -> klass ) );
1102+ jit_mov_gc_ptr ( jit , cb , REG1 , ( VALUE ) cd -> cc -> klass );
10871103 cmp (cb , klass_opnd , REG1 );
10881104 jne_ptr (cb , side_exit );
10891105
@@ -1107,7 +1123,7 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
11071123
11081124 // Put compile time cme into REG1. It's assumed to be valid because we are notified when
11091125 // any cme we depend on become outdated. See rb_ujit_method_lookup_change().
1110- mov ( cb , REG1 , const_ptr_opnd ( cme ) );
1126+ jit_mov_gc_ptr ( jit , cb , REG1 , ( VALUE ) cme );
11111127 // Write method entry at sp[-3]
11121128 // sp[-3] = me;
11131129 mov (cb , mem_opnd (64 , REG0 , 8 * -3 ), REG1 );
@@ -1161,9 +1177,9 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
11611177
11621178 // Call check_cfunc_dispatch
11631179 mov (cb , RDI , recv );
1164- mov ( cb , RSI , const_ptr_opnd ( cd ) );
1180+ jit_mov_gc_ptr ( jit , cb , RSI , ( VALUE ) cd );
11651181 mov (cb , RDX , const_ptr_opnd ((void * )cfunc -> func ));
1166- mov ( cb , RCX , const_ptr_opnd ( cme ) );
1182+ jit_mov_gc_ptr ( jit , cb , RCX , ( VALUE ) cme );
11671183 call_ptr (cb , REG0 , (void * )& check_cfunc_dispatch );
11681184
11691185 // Restore registers
@@ -1242,7 +1258,7 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
12421258
12431259bool rb_simple_iseq_p (const rb_iseq_t * iseq );
12441260
1245- void
1261+ static void
12461262gen_return_branch (codeblock_t * cb , uint8_t * target0 , uint8_t * target1 , uint8_t shape )
12471263{
12481264 switch (shape )
@@ -1315,7 +1331,7 @@ gen_oswb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_ca
13151331 assume_method_lookup_stable (cd -> cc , cme , jit -> block );
13161332
13171333 // Bail if receiver class is different from compile-time call cache class
1318- mov ( cb , REG1 , imm_opnd ( cd -> cc -> klass ) );
1334+ jit_mov_gc_ptr ( jit , cb , REG1 , ( VALUE ) cd -> cc -> klass );
13191335 cmp (cb , klass_opnd , REG1 );
13201336 jne_ptr (cb , side_exit );
13211337
@@ -1343,7 +1359,7 @@ gen_oswb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_ca
13431359
13441360 // Put compile time cme into REG1. It's assumed to be valid because we are notified when
13451361 // any cme we depend on become outdated. See rb_ujit_method_lookup_change().
1346- mov ( cb , REG1 , const_ptr_opnd ( cme ) );
1362+ jit_mov_gc_ptr ( jit , cb , REG1 , ( VALUE ) cme );
13471363 // Write method entry at sp[-3]
13481364 // sp[-3] = me;
13491365 mov (cb , mem_opnd (64 , REG0 , 8 * -3 ), REG1 );
@@ -1378,7 +1394,7 @@ gen_oswb_iseq(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_ca
13781394 mov (cb , member_opnd (REG_CFP , rb_control_frame_t , ep ), REG0 );
13791395 mov (cb , REG0 , recv );
13801396 mov (cb , member_opnd (REG_CFP , rb_control_frame_t , self ), REG0 );
1381- mov ( cb , REG0 , const_ptr_opnd ( iseq ) );
1397+ jit_mov_gc_ptr ( jit , cb , REG0 , ( VALUE ) iseq );
13821398 mov (cb , member_opnd (REG_CFP , rb_control_frame_t , iseq ), REG0 );
13831399 mov (cb , REG0 , const_ptr_opnd (start_pc ));
13841400 mov (cb , member_opnd (REG_CFP , rb_control_frame_t , pc ), REG0 );
0 commit comments