Skip to content

Commit 47292b0

Browse files
committed
ZJIT: Add comments about zjit_frame_active
1 parent 5041ea3 commit 47292b0

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

vm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,18 @@ zjit_materialize_frames(const rb_execution_context_t *ec, rb_control_frame_t *cf
28922892
VM_ASSERT(cfp <= end_cfp);
28932893

28942894
while (true) {
2895+
// If materialize_target is false, we skip materializing ec->tag->cfp.
2896+
//
2897+
// When JIT code calls a C function that does the same number of setjmps and
2898+
// longjmps, e.g. rb_hash_aref, it calls zjit_materialize_frames but goes
2899+
// back to the JIT code. In that case, we don't want to materialize the frame
2900+
// and clear cfp->jit_return, which will still be used by the JIT code.
2901+
//
2902+
// When JIT code calls a C function that does more longjmps than setjmps,
2903+
// it would not go back to the JIT code. So ec->tag->cfp should be materialized
2904+
// in that case.
28952905
if (cfp == end_cfp && !materialize_target) break;
2906+
28962907
if (CFP_ZJIT_FRAME_P(cfp)) {
28972908
const zjit_jit_frame_t *jit_frame = CFP_ZJIT_FRAME(cfp);
28982909
cfp->pc = jit_frame->pc;

vm_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,10 @@ struct rb_vm_tag {
10301030
// ec->cfp as of EC_PUSH_TAG, which is saved for materializing JITFrame.
10311031
rb_control_frame_t *cfp;
10321032
// Whether cfp had a ZJIT frame before this tag's setjmp was established.
1033+
// It's used for checking if zjit_materialize_frames should materialize
1034+
// the frame or not when the tag is popped. If zjit_frame_active is true,
1035+
// we don't want to materialize cfp->jit_return, which will still be used
1036+
// by JIT code.
10331037
bool zjit_frame_active;
10341038
#endif
10351039
};

0 commit comments

Comments
 (0)