Skip to content

Commit 9996d69

Browse files
committed
Add comments for cryptic functions in iseq.c
1 parent 58e3aa0 commit 9996d69

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

iseq.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,8 @@ rb_iseq_event_flags(const rb_iseq_t *iseq, size_t pos)
23772377
}
23782378
}
23792379

2380+
// Clear tracing event flags and turn off tracing for a given instruction as needed.
2381+
// This is currently used after updating a one-shot line coverage for the current instruction.
23802382
void
23812383
rb_iseq_clear_event_flags(const rb_iseq_t *iseq, size_t pos, rb_event_flag_t reset)
23822384
{
@@ -3767,6 +3769,8 @@ rb_free_encoded_insn_data(void)
37673769
st_free_table(encoded_insn_data);
37683770
}
37693771

3772+
// Initialize a table to decode bare, trace, and zjit instructions.
3773+
// This function also determines which instructions are used when TracePoint is enabled.
37703774
void
37713775
rb_vm_encoded_insn_data_table_init(void)
37723776
{
@@ -3783,7 +3787,8 @@ rb_vm_encoded_insn_data_table_init(void)
37833787
insn_data[insn].insn_len = insn_len(insn);
37843788

37853789
// 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
3790+
// opt_invokebuiltin_delegate + trace_leave, presumably because we don't want to fire
3791+
// :return events before invokebuiltin. https://github.com/ruby/ruby/pull/3256
37873792
int notrace_insn = (insn != BIN(opt_invokebuiltin_delegate_leave)) ? insn : BIN(opt_invokebuiltin_delegate);
37883793
insn_data[insn].notrace_encoded_insn = (void *)INSN_CODE(notrace_insn);
37893794
insn_data[insn].trace_encoded_insn = (void *)INSN_CODE(notrace_insn + VM_BARE_INSTRUCTION_SIZE);
@@ -3806,6 +3811,9 @@ rb_vm_encoded_insn_data_table_init(void)
38063811
}
38073812
}
38083813

3814+
// Decode an insn address to an insn. This returns bare instructions
3815+
// even if they're trace/zjit instructions. Use rb_vm_insn_addr2opcode
3816+
// to decode trace/zjit instructions as is.
38093817
int
38103818
rb_vm_insn_addr2insn(const void *addr)
38113819
{
@@ -3820,7 +3828,8 @@ rb_vm_insn_addr2insn(const void *addr)
38203828
rb_bug("rb_vm_insn_addr2insn: invalid insn address: %p", addr);
38213829
}
38223830

3823-
// Unlike rb_vm_insn_addr2insn, this function can return trace opcode variants.
3831+
// Decode an insn address to an insn. Unlike rb_vm_insn_addr2insn,
3832+
// this function can return trace/zjit opcode variants.
38243833
int
38253834
rb_vm_insn_addr2opcode(const void *addr)
38263835
{
@@ -3844,7 +3853,9 @@ rb_vm_insn_addr2opcode(const void *addr)
38443853
rb_bug("rb_vm_insn_addr2opcode: invalid insn address: %p", addr);
38453854
}
38463855

3847-
// Decode `ISEQ_BODY(iseq)->iseq_encoded[i]` to an insn.
3856+
// Decode `ISEQ_BODY(iseq)->iseq_encoded[i]` to an insn. This returns
3857+
// bare instructions even if they're trace/zjit instructions. Use
3858+
// rb_vm_insn_addr2opcode to decode trace/zjit instructions as is.
38483859
int
38493860
rb_vm_insn_decode(const VALUE encoded)
38503861
{
@@ -3856,6 +3867,7 @@ rb_vm_insn_decode(const VALUE encoded)
38563867
return insn;
38573868
}
38583869

3870+
// Turn on or off tracing for a given instruction address
38593871
static inline int
38603872
encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon, bool remain_current_trace)
38613873
{
@@ -3874,6 +3886,7 @@ encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon,
38743886
rb_bug("trace_instrument: invalid insn address: %p", (void *)*iseq_encoded_insn);
38753887
}
38763888

3889+
// Turn off tracing for an instruction at pos after tracing event flags are cleared
38773890
void
38783891
rb_iseq_trace_flag_cleared(const rb_iseq_t *iseq, size_t pos)
38793892
{

0 commit comments

Comments
 (0)