Skip to content

Commit 1434983

Browse files
committed
Cheaper exception checks
1 parent 47cf18b commit 1434983

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,18 +1227,19 @@ static zend_always_inline zend_bool zend_jit_verify_type_common(zval *arg, zend_
12271227
return 0;
12281228
}
12291229

1230-
//static void ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, const zend_op_array *op_array, uint32_t arg_num, zend_arg_info *arg_info, void **cache_slot)
1231-
static int ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info)
1230+
static zend_bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info)
12321231
{
12331232
zend_execute_data *execute_data = EG(current_execute_data);
12341233
const zend_op *opline = EX(opline);
12351234
void **cache_slot = CACHE_ADDR(opline->extended_value);
1235+
zend_bool ret;
12361236

1237-
if (UNEXPECTED(!zend_jit_verify_type_common(arg, arg_info, cache_slot))) {
1237+
ret = zend_jit_verify_type_common(arg, arg_info, cache_slot);
1238+
if (UNEXPECTED(!ret)) {
12381239
zend_verify_arg_error(EX(func), arg_info, opline->op1.num, cache_slot, arg);
12391240
return 0;
12401241
}
1241-
return 1;
1242+
return ret;
12421243
}
12431244

12441245
static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_array *op_array, zend_arg_info *arg_info, void **cache_slot)

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_func_counter_helper(ZEND_OPCODE_H
128128
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_HANDLER_ARGS);
129129

130130
void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D);
131-
void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
131+
zend_bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
132132

133133
void ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags);
134134
int ZEND_FASTCALL zend_jit_check_constant(const zval *key);

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D)
153153
}
154154
}
155155

156-
void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D)
156+
zend_bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D)
157157
{
158158
zend_execute_data *call = (zend_execute_data *) opline;
159159
zend_function *fbc = call->func;
@@ -176,7 +176,9 @@ void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D)
176176
}
177177

178178
zend_vm_stack_free_call_frame(call);
179+
return 0;
179180
}
181+
return 1;
180182
}
181183

182184
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_profile_helper(ZEND_OPCODE_HANDLER_ARGS)

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5420,9 +5420,9 @@ static int zend_jit_assign_dim(dasm_State **Dst, const zend_op *opline, const ze
54205420
| SAVE_VALID_OPLINE opline, r0
54215421
| EXT_CALL zend_jit_prepare_assign_dim_ref, r0
54225422
| test r0, r0
5423-
| jz ->exception_handler_undef
54245423
| mov FCARG1a, r0
5425-
| jmp >1
5424+
| jne >1
5425+
| jmp ->exception_handler_undef
54265426
|.code
54275427
|1:
54285428
op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0);
@@ -5622,9 +5622,9 @@ static int zend_jit_assign_dim_op(dasm_State **Dst, const zend_op *opline, const
56225622
| SAVE_VALID_OPLINE opline, r0
56235623
| EXT_CALL zend_jit_prepare_assign_dim_ref, r0
56245624
| test r0, r0
5625-
| jz ->exception_handler_undef
56265625
| mov FCARG1a, r0
5627-
| jmp >1
5626+
| jne >1
5627+
| jmp ->exception_handler_undef
56285628
|.code
56295629
|1:
56305630
op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0);
@@ -8413,10 +8413,10 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
84138413
| mov FCARG1a, RX
84148414
}
84158415
| EXT_CALL zend_jit_deprecated_helper, r0
8416-
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
8417-
| jne ->exception_handler
8416+
| test al, al
84188417
| mov r0, EX:RX->func // reload
8419-
| jmp >1
8418+
| jne >1
8419+
| jmp ->exception_handler
84208420
|.code
84218421
|1:
84228422
}
@@ -8425,8 +8425,8 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
84258425
| mov FCARG1a, RX
84268426
}
84278427
| EXT_CALL zend_jit_deprecated_helper, r0
8428-
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
8429-
| jne ->exception_handler
8428+
| test al, al
8429+
| je ->exception_handler
84308430
}
84318431
}
84328432

@@ -8706,10 +8706,10 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
87068706
| mov FCARG1a, RX
87078707
}
87088708
| EXT_CALL zend_jit_deprecated_helper, r0
8709-
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
8710-
| jne ->exception_handler
8709+
| test al, al
87118710
| mov r0, EX:RX->func // reload
8712-
| jmp >1
8711+
| jne >1
8712+
| jmp ->exception_handler
87138713
|.code
87148714
|1:
87158715
}
@@ -8718,8 +8718,8 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
87188718
| mov FCARG1a, RX
87198719
}
87208720
| EXT_CALL zend_jit_deprecated_helper, r0
8721-
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
8722-
| jne ->exception_handler
8721+
| test al, al
8722+
| je ->exception_handler
87238723
| mov r0, EX:RX->func // reload
87248724
}
87258725
}
@@ -10551,11 +10551,16 @@ static int zend_jit_verify_arg_type(dasm_State **Dst, const zend_op *opline, zen
1055110551
| EXT_CALL zend_jit_verify_arg_slow, r0
1055210552

1055310553
if (check_exception) {
10554-
| test eax, eax
10555-
| jz ->exception_handler
10556-
}
10557-
10558-
if (in_cold) {
10554+
| test al, al
10555+
if (in_cold) {
10556+
| jnz >1
10557+
| jmp ->exception_handler
10558+
|.code
10559+
|1:
10560+
} else {
10561+
| jz ->exception_handler
10562+
}
10563+
} else if (in_cold) {
1055910564
| jmp >1
1056010565
|.code
1056110566
|1:
@@ -10686,18 +10691,12 @@ static int zend_jit_recv_init(dasm_State **Dst, const zend_op *opline, const zen
1068610691
if (!ZEND_TYPE_IS_SET(arg_info->type)) {
1068710692
break;
1068810693
}
10689-
if (!zend_jit_verify_arg_type(Dst, opline, arg_info, 0)) {
10694+
if (!zend_jit_verify_arg_type(Dst, opline, arg_info, may_throw)) {
1069010695
return 0;
1069110696
}
1069210697
} while (0);
1069310698
}
1069410699

10695-
if (may_throw) {
10696-
if (!zend_jit_check_exception(Dst)) {
10697-
return 0;
10698-
}
10699-
}
10700-
1070110700
if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) {
1070210701
if (is_last) {
1070310702
| LOAD_IP_ADDR (opline + 1)

0 commit comments

Comments
 (0)