@@ -3283,7 +3283,7 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
32833283 VALUE exception = rb_ary_new (); /* [[....]] */
32843284 VALUE misc = rb_hash_new ();
32853285
3286- static ID insn_syms [VM_INSTRUCTION_SIZE / 2 ]; /* w/o-trace only */
3286+ static ID insn_syms [VM_BARE_INSTRUCTION_SIZE ]; /* w/o-trace only */
32873287 struct st_table * labels_table = st_init_numtable ();
32883288 VALUE labels_wrapper = TypedData_Wrap_Struct (0 , & label_wrapper , labels_table );
32893289
@@ -3745,17 +3745,21 @@ rb_iseq_defined_string(enum defined_type type)
37453745 return rb_fstring_cstr (estr );
37463746}
37473747
3748- /* A map from encoded_insn to insn_data: decoded insn number, its len,
3749- * non-trace version of encoded insn, and trace version. */
3750-
3748+ // A map from encoded_insn to insn_data: decoded insn number, its len,
3749+ // decoded ZJIT insn number, non-trace version of encoded insn,
3750+ // trace version, and zjit version.
37513751static st_table * encoded_insn_data ;
37523752typedef struct insn_data_struct {
37533753 int insn ;
37543754 int insn_len ;
37553755 void * notrace_encoded_insn ;
37563756 void * trace_encoded_insn ;
3757+ #if USE_ZJIT
3758+ int zjit_insn ;
3759+ void * zjit_encoded_insn ;
3760+ #endif
37573761} insn_data_t ;
3758- static insn_data_t insn_data [VM_INSTRUCTION_SIZE / 2 ];
3762+ static insn_data_t insn_data [VM_BARE_INSTRUCTION_SIZE ];
37593763
37603764void
37613765rb_free_encoded_insn_data (void )
@@ -3772,27 +3776,33 @@ rb_vm_encoded_insn_data_table_init(void)
37723776#else
37733777#define INSN_CODE (insn ) (insn)
37743778#endif
3775- st_data_t insn ;
3776- encoded_insn_data = st_init_numtable_with_size (VM_INSTRUCTION_SIZE / 2 );
3777-
3778- for (insn = 0 ; insn < VM_INSTRUCTION_SIZE /2 ; insn ++ ) {
3779- st_data_t key1 = (st_data_t )INSN_CODE (insn );
3780- st_data_t key2 = (st_data_t )INSN_CODE (insn + VM_INSTRUCTION_SIZE /2 );
3779+ encoded_insn_data = st_init_numtable_with_size (VM_BARE_INSTRUCTION_SIZE );
37813780
3782- insn_data [insn ].insn = (int )insn ;
3781+ for (int insn = 0 ; insn < VM_BARE_INSTRUCTION_SIZE ; insn ++ ) {
3782+ insn_data [insn ].insn = insn ;
37833783 insn_data [insn ].insn_len = insn_len (insn );
37843784
3785- if (insn != BIN (opt_invokebuiltin_delegate_leave )) {
3786- insn_data [insn ].notrace_encoded_insn = (void * ) key1 ;
3787- insn_data [insn ].trace_encoded_insn = (void * ) key2 ;
3788- }
3789- else {
3790- insn_data [insn ].notrace_encoded_insn = (void * ) INSN_CODE (BIN (opt_invokebuiltin_delegate ));
3791- insn_data [insn ].trace_encoded_insn = (void * ) INSN_CODE (BIN (opt_invokebuiltin_delegate ) + VM_INSTRUCTION_SIZE /2 );
3792- }
3785+ // When tracing :return events, we convert opt_invokebuiltin_delegate_leave + leave into
3786+ // opt_invokebuiltin_delegate + trace_leave. https://github.com/ruby/ruby/pull/3256
3787+ int notrace_insn = (insn != BIN (opt_invokebuiltin_delegate_leave )) ? insn : BIN (opt_invokebuiltin_delegate );
3788+ insn_data [insn ].notrace_encoded_insn = (void * )INSN_CODE (notrace_insn );
3789+ insn_data [insn ].trace_encoded_insn = (void * )INSN_CODE (notrace_insn + VM_BARE_INSTRUCTION_SIZE );
37933790
3791+ st_data_t key1 = (st_data_t )INSN_CODE (insn );
3792+ st_data_t key2 = (st_data_t )INSN_CODE (insn + VM_BARE_INSTRUCTION_SIZE );
37943793 st_add_direct (encoded_insn_data , key1 , (st_data_t )& insn_data [insn ]);
37953794 st_add_direct (encoded_insn_data , key2 , (st_data_t )& insn_data [insn ]);
3795+
3796+ #if USE_ZJIT
3797+ int zjit_insn = vm_bare_insn_to_zjit_insn (insn );
3798+ insn_data [insn ].zjit_insn = zjit_insn ;
3799+ insn_data [insn ].zjit_encoded_insn = (insn != zjit_insn ) ? (void * )INSN_CODE (zjit_insn ) : 0 ;
3800+
3801+ if (insn != zjit_insn ) {
3802+ st_data_t key3 = (st_data_t )INSN_CODE (zjit_insn );
3803+ st_add_direct (encoded_insn_data , key3 , (st_data_t )& insn_data [insn ]);
3804+ }
3805+ #endif
37963806 }
37973807}
37983808
@@ -3821,8 +3831,13 @@ rb_vm_insn_addr2opcode(const void *addr)
38213831 insn_data_t * e = (insn_data_t * )val ;
38223832 int opcode = e -> insn ;
38233833 if (addr == e -> trace_encoded_insn ) {
3824- opcode += VM_INSTRUCTION_SIZE /2 ;
3834+ opcode += VM_BARE_INSTRUCTION_SIZE ;
3835+ }
3836+ #if USE_ZJIT
3837+ else if (addr == e - > zjit_encoded_insn ) {
3838+ opcode = e -> zjit_insn ;
38253839 }
3840+ #endif
38263841 return opcode ;
38273842 }
38283843
0 commit comments