Skip to content

Commit 9dc9534

Browse files
committed
If we don't know the return address, just escape to VM, instead of adding side exit.
Remove unnecessary exception checks.
1 parent a81061d commit 9dc9534

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
27402740
}
27412741
}
27422742
}
2743-
if (!zend_jit_leave_func(&dasm_state, op_array, NULL, NULL,
2743+
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info, NULL, NULL,
27442744
(ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0, 1)) {
27452745
goto jit_failure;
27462746
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4076,7 +4076,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40764076
}
40774077
}
40784078
}
4079-
if (!zend_jit_leave_func(&dasm_state, op_array, p + 1, &zend_jit_traces[ZEND_JIT_TRACE_NUM],
4079+
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info,
4080+
p + 1, &zend_jit_traces[ZEND_JIT_TRACE_NUM],
40804081
(op_array_ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0, may_throw)) {
40814082
goto jit_failure;
40824083
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10194,7 +10194,7 @@ static int zend_jit_free_op(dasm_State **Dst, const zend_op *opline, uint32_t in
1019410194
return 1;
1019510195
}
1019610196

10197-
static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array, zend_jit_trace_rec *trace, zend_jit_trace_info *trace_info, int indirect_var_access, int may_throw)
10197+
static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array, const zend_op *opline, uint32_t op1_info, zend_jit_trace_rec *trace, zend_jit_trace_info *trace_info, int indirect_var_access, int may_throw)
1019810198
{
1019910199
zend_bool may_be_top_frame =
1020010200
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
@@ -10293,50 +10293,49 @@ static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array,
1029310293

1029410294
|8:
1029510295

10296-
if ((trace->op != ZEND_JIT_TRACE_END ||
10297-
trace->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) &&
10298-
may_throw) {
10299-
| // if (EG(exception))
10300-
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
10301-
| jne ->leave_throw_handler
10302-
}
10303-
1030410296
if (trace->op == ZEND_JIT_TRACE_BACK
1030510297
&& (!JIT_G(current_frame) || TRACE_FRAME_IS_UNKNOWN_RETURN(JIT_G(current_frame)))) {
1030610298
const zend_op *next_opline = trace->opline;
10307-
uint32_t exit_point;
10308-
const void *exit_addr;
10309-
zend_jit_trace_stack_frame *current_frame;
1031010299

10300+
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))
10301+
&& (op1_info & MAY_BE_RC1)
10302+
&& (op1_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) {
10303+
/* exception might be thrown during destruction of unused return value */
10304+
| // if (EG(exception))
10305+
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
10306+
| jne ->leave_throw_handler
10307+
}
1031110308
do {
1031210309
trace++;
1031310310
} while (trace->op == ZEND_JIT_TRACE_INIT_CALL);
1031410311
ZEND_ASSERT(trace->op == ZEND_JIT_TRACE_VM || trace->op == ZEND_JIT_TRACE_END);
1031510312
next_opline = trace->opline;
1031610313
ZEND_ASSERT(next_opline != NULL);
10317-
current_frame = JIT_G(current_frame);
10318-
JIT_G(current_frame) = NULL;
10319-
exit_point = zend_jit_trace_get_exit_point(NULL, 0);
10320-
JIT_G(current_frame) = current_frame;
10321-
exit_addr = zend_jit_trace_get_exit_addr(exit_point);
10322-
if (!exit_addr) {
10323-
return 0;
10324-
}
10314+
1032510315
if (trace->op == ZEND_JIT_TRACE_END
1032610316
&& trace->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
1032710317
trace_info->flags |= ZEND_JIT_TRACE_LOOP;
1032810318
| CMP_IP next_opline
1032910319
| je =>0 // LOOP
10330-
| jmp &exit_addr
10320+
| jmp ->trace_escape
1033110321
} else {
1033210322
| CMP_IP next_opline
10333-
| jne &exit_addr
10323+
| jne ->trace_escape
1033410324
}
1033510325

1033610326
last_valid_opline = trace->opline;
1033710327

1033810328
return 1;
10329+
} else if (may_throw ||
10330+
(((opline->op1_type & (IS_VAR|IS_TMP_VAR))
10331+
&& (op1_info & MAY_BE_RC1)
10332+
&& (op1_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY)))
10333+
&& (!JIT_G(current_frame) || TRACE_FRAME_IS_RETURN_VALUE_UNUSED(JIT_G(current_frame))))) {
10334+
| // if (EG(exception))
10335+
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
10336+
| jne ->leave_throw_handler
1033910337
}
10338+
1034010339
return 1;
1034110340
} else {
1034210341
| // if (EG(exception))

0 commit comments

Comments
 (0)